# tabs
Documentation: [Chrome Tabs API](https://developer.chrome.com/docs/extensions/reference/tabs)
A promise-based wrapper for the Chrome `tabs` API, providing core tab operations, messaging, zoom controls, grouping, and helper utilities.
## Methods
- [captureVisibleTab(windowId, options)](#captureVisibleTab)
- [connectTab(tabId, connectInfo?)](#connectTab)
- [createTab(properties)](#createTab)
- [detectTabLanguage(tabId)](#detectTabLanguage)
- [discardTab(tabId)](#discardTab)
- [duplicateTab(tabId)](#duplicateTab)
- [getTab(tabId)](#getTab)
- [getCurrentTab()](#getCurrentTab)
- [getTabZoom(tabId)](#getTabZoom)
- [getTabZoomSettings(tabId)](#getTabZoomSettings)
- [goTabBack(tabId)](#goTabBack)
- [goTabForward(tabId)](#goTabForward)
- [groupTabs(options)](#groupTabs)
- [highlightTab(highlightInfo)](#highlightTab)
- [moveTab(tabId, moveProperties)](#moveTab)
- [moveTabs(tabIds, moveProperties)](#moveTabs)
- [queryTabs(queryInfo?)](#queryTabs)
- [reloadTab(tabId, bypassCache?)](#reloadTab)
- [removeTab(tabId)](#removeTab)
- [sendTabMessage(tabId, message, options?)](#sendTabMessage)
- [setTabZoom(tabId, zoomFactor)](#setTabZoom)
- [setTabZoomSettings(tabId, zoomSettings)](#setTabZoomSettings)
- [ungroupTab(tabIds)](#ungroupTab)
- [updateTab(tabId, updateProperties)](#updateTab)
- [executeScriptTab(tabId, details)](#executeScriptTab) [MV2]
- [insertCssTab(tabId, details)](#insertCssTab) [MV2]
- [removeCssTab(tabId, details)](#removeCssTab) [MV2]
- [getTabUrl(tabId)](#getTabUrl)
- [getActiveTab()](#getActiveTab)
- [queryTabIds(queryInfo?)](#queryTabIds)
- [findTab(queryInfo?)](#findTab)
- [findTabById(tabId)](#findTabById)
- [findTabByUrl(url)](#findTabByUrl)
- [updateTabAsSelected(tabId)](#updateTabAsSelected)
- [updateTabAsActive(tabId)](#updateTabAsActive)
- [openOrCreateTab(tab)](#openOrCreateTab)
- [openOrCreateTabByUrl(url)](#openOrCreateTabByUrl)
## Events
- [onTabActivated(callback)](#onTabActivated)
- [onTabAttached(callback)](#onTabAttached)
- [onTabCreated(callback)](#onTabCreated)
- [onTabDetached(callback)](#onTabDetached)
- [onTabHighlighted(callback)](#onTabHighlighted)
- [onTabMoved(callback)](#onTabMoved)
- [onTabRemoved(callback)](#onTabRemoved)
- [onTabReplaced(callback)](#onTabReplaced)
- [onTabUpdated(callback)](#onTabUpdated)
- [onTabZoomChange(callback)](#onTabZoomChange)
---
### captureVisibleTab
```
captureVisibleTab(
windowId: number,
options: chrome.extensionTypes.ImageDetails
): Promise
```
Captures the visible area of the specified window as an image (data URL string).
### connectTab
```
connectTab(
tabId: number,
connectInfo?: chrome.tabs.ConnectInfo
): chrome.runtime.Port
```
Creates a long-lived connection to the specified tab for messaging.
### createTab
```
createTab(properties: chrome.tabs.CreateProperties): Promise
```
Creates a new tab with the given properties.
### detectTabLanguage
```
detectTabLanguage(tabId: number): Promise
```
Detects the primary language of the specified tab's content. Returns a language code (e.g., `"en"` or `"und"`).
### discardTab
```
discardTab(tabId: number): Promise
```
Discards the specified tab to free memory. Resolves with the updated tab or `undefined`.
### duplicateTab
```
duplicateTab(tabId: number): Promise
```
Duplicates the specified tab. Resolves with the new tab, or `undefined` if duplication fails.
### getTab
```
getTab(tabId: number): Promise
```
Retrieves information about the specified tab.
### getCurrentTab
```
getCurrentTab(): Promise
```
Retrieves the tab in which the calling script is running (e.g., popup). May resolve to `undefined` outside a tab context.
### getTabZoom
```
getTabZoom(tabId: number): Promise
```
Gets the zoom factor of the specified tab.
### getTabZoomSettings
```
getTabZoomSettings(tabId: number): Promise
```
Retrieves the zoom settings for the specified tab.
### goTabBack
```
goTabBack(tabId: number): Promise
```
Navigates the tab one step backward in its history.
### goTabForward
```
goTabForward(tabId: number): Promise
```
Navigates the tab one step forward in its history.
### groupTabs
```
groupTabs(options: chrome.tabs.GroupOptions): Promise
```
Groups one or more tabs. Resolves with the group ID.
### highlightTab
```
highlightTab(highlightInfo: chrome.tabs.HighlightInfo): Promise
```
Highlights (selects) the specified tabs and resolves with the updated window.
### moveTab
```
moveTab(
tabId: number,
moveProperties: chrome.tabs.MoveProperties
): Promise
```
Moves a tab to a new index or window.
### moveTabs
```
moveTabs(
tabIds: number[],
moveProperties: chrome.tabs.MoveProperties
): Promise
```
Moves multiple tabs and resolves with the updated tabs.
### queryTabs
```
queryTabs(queryInfo?: chrome.tabs.QueryInfo): Promise
```
Retrieves tabs matching the query filter.
### reloadTab
```
reloadTab(tabId: number, bypassCache?: boolean): Promise
```
Reloads the specified tab. Set `bypassCache` to `true` to force revalidation.
### removeTab
```
removeTab(tabId: number): Promise
```
Closes the specified tab.
### sendTabMessage
```
sendTabMessage(
tabId: number,
message: M,
options?: chrome.tabs.MessageSendOptions
): Promise
```
Sends a one-time message to the content script in the specified tab and resolves with the response.
### setTabZoom
```
setTabZoom(tabId: number, zoomFactor: number): Promise
```
Sets the zoom factor for the specified tab.
### setTabZoomSettings
```
setTabZoomSettings(
tabId: number,
zoomSettings: chrome.tabs.ZoomSettings
): Promise
```
Updates the zoom settings for the specified tab.
### ungroupTab
```
ungroupTab(tabIds: number | [number, ...number[]]): Promise
```
Removes one or more tabs from their respective groups.
### updateTab
```
updateTab(
tabId: number,
updateProperties: chrome.tabs.UpdateProperties
): Promise
```
Updates properties of the specified tab. Resolves with the updated tab or `undefined`.
### executeScriptTab [MV2]
```
executeScriptTab(
tabId: number,
details: chrome.extensionTypes.InjectDetails
): Promise
```
Executes code in the tab using the MV2 `chrome.tabs.executeScript`. Not available in MV3.
### insertCssTab [MV2]
```
insertCssTab(
tabId: number,
details: chrome.extensionTypes.InjectDetails
): Promise
```
Inserts CSS into the tab using the MV2 `chrome.tabs.insertCSS`. Not available in MV3.
### removeCssTab [MV2]
```
removeCssTab(
tabId: number,
details: chrome.extensionTypes.InjectDetails
): Promise
```
Removes previously inserted CSS using the MV2 `chrome.tabs.removeCSS`. Not available in MV3.
### getTabUrl
```
getTabUrl(tabId: number): Promise
```
Returns the current URL of the specified tab or throws if it cannot be determined.
### getActiveTab
```
getActiveTab(): Promise
```
Returns the active tab in the current window or throws if not found.
### queryTabIds
```
queryTabIds(queryInfo?: chrome.tabs.QueryInfo): Promise
```
Returns only the IDs for tabs matching the query.
### findTab
```
findTab(queryInfo?: chrome.tabs.QueryInfo): Promise
```
Returns the first tab matching the query, if any.
### findTabById
```
findTabById(tabId: number): Promise
```
Resolves with the tab for the given ID, or `undefined` if not available.
### findTabByUrl
```
findTabByUrl(url: string): Promise
```
Finds the first tab with the specified URL, if any.
### updateTabAsSelected
```
updateTabAsSelected(tabId: number): Promise
```
Marks the specified tab as highlighted (selected).
### updateTabAsActive
```
updateTabAsActive(tabId: number): Promise
```
Marks the specified tab as active.
### openOrCreateTab
```
openOrCreateTab(tab: chrome.tabs.Tab): Promise
```
Selects an existing tab with the same URL and ID, or creates a new one with that URL.
### openOrCreateTabByUrl
```
openOrCreateTabByUrl(url: string): Promise
```
Selects an existing tab with the given URL, or creates a new tab with that URL.
---
### onTabActivated
```
onTabActivated(
callback: (activeInfo: chrome.tabs.OnActivatedInfo) => void
): () => void
```
Fires when the active tab in a window changes. Returns an unsubscribe function.
### onTabAttached
```
onTabAttached(
callback: (tabId: number, attachInfo: chrome.tabs.OnAttachedInfo) => void
): () => void
```
Fires when a tab is attached to a window (moved between windows). Returns an unsubscribe function.
### onTabCreated
```
onTabCreated(
callback: (tab: chrome.tabs.Tab) => void
): () => void
```
Fires when a tab is created. Returns an unsubscribe function.
### onTabDetached
```
onTabDetached(
callback: (tabId: number, detachInfo: chrome.tabs.OnDetachedInfo) => void
): () => void
```
Fires when a tab is detached from a window. Returns an unsubscribe function.
### onTabHighlighted
```
onTabHighlighted(
callback: (highlightInfo: chrome.tabs.OnHighlightedInfo) => void
): () => void
```
Fires when the highlighted/selected tabs in a window change. Returns an unsubscribe function.
### onTabMoved
```
onTabMoved(
callback: (tabId: number, moveInfo: chrome.tabs.OnMovedInfo) => void
): () => void
```
Fires when a tab is moved within a window. Returns an unsubscribe function.
### onTabRemoved
```
onTabRemoved(
callback: (tabId: number, removeInfo: chrome.tabs.OnRemovedInfo) => void
): () => void
```
Fires when a tab is closed. Returns an unsubscribe function.
### onTabReplaced
```
onTabReplaced(
callback: (addedTabId: number, removedTabId: number) => void
): () => void
```
Fires when a tab is replaced with another tab due to prerendering or instant. Returns an unsubscribe function.
### onTabUpdated
```
onTabUpdated(
callback: (
tabId: number,
changeInfo: chrome.tabs.OnUpdatedInfo,
tab: chrome.tabs.Tab
) => void
): () => void
```
Fires when a tab is updated. Returns an unsubscribe function.
### onTabZoomChange
```
onTabZoomChange(
callback: (ZoomChangeInfo: chrome.tabs.OnZoomChangeInfo) => void
): () => void
```
Fires when a tab's zoom changes. Returns an unsubscribe function.