windowId?: number,
options?: ImageDetails,
callback?: function,
)
Captures the visible area of the currently active tab in the specified window. In order to call this method, the extension must have either the <all_urls> permission or the activeTab permission. In addition to sites that extensions can normally access, this method allows extensions to capture sensitive sites that are otherwise restricted, including chrome:-scheme pages, other extensions' pages, and data: URLs. These sensitive sites can only be captured with the activeTab permission. File URLs may be captured only if the extension has been granted file access.
number optional
The target window. Defaults to the current window.
ImageDetails optional
function optional
The callback
parameter looks like: (dataUrl: string) => void
string
A data URL that encodes an image of the visible area of the captured tab. May be assigned to the 'src' property of an HTML img
element for display.
Promise<string>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.connect(
tabId: number,
connectInfo?: object,
)
Connects to the content script(s) in the specified tab. The runtime.onConnect
event is fired in each content script running in the specified tab for the current extension. For more details, see Content Script Messaging.
number
object optional
string optional
Open a port to a specific document identified by documentId
instead of all frames in the tab.
number optional
Open a port to a specific frame identified by frameId
instead of all frames in the tab.
string optional
Is passed into onConnect for content scripts that are listening for the connection event.
A port that can be used to communicate with the content scripts running in the specified tab. The port's runtime.Port
event is fired if the tab closes or does not exist.
chrome.tabs.create(
createProperties: object,
callback?: function,
)
Creates a new tab.
object
boolean optional
Whether the tab should become the active tab in the window. Does not affect whether the window is focused (see windows.update
). Defaults to true
.
number optional
The position the tab should take in the window. The provided value is clamped to between zero and the number of tabs in the window.
number optional
The ID of the tab that opened this tab. If specified, the opener tab must be in the same window as the newly created tab.
boolean optional
Whether the tab should be pinned. Defaults to false
boolean optional
Please use active.
Whether the tab should become the selected tab in the window. Defaults to true
string optional
The URL to initially navigate the tab to. Fully-qualified URLs must include a scheme (i.e., 'http://www.google.com', not 'www.google.com'). Relative URLs are relative to the current page within the extension. Defaults to the New Tab Page.
number optional
The window in which to create the new tab. Defaults to the current window.
function optional
The callback
parameter looks like: (tab: Tab) => void
The created tab.
Promise<Tab>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.detectLanguage(
tabId?: number,
callback?: function,
)
Detects the primary language of the content in a tab.
number optional
Defaults to the active tab of the current window.
function optional
The callback
parameter looks like: (language: string) => void
string
An ISO language code such as en
or fr
. For a complete list of languages supported by this method, see kLanguageInfoTable. The second to fourth columns are checked and the first non-NULL value is returned, except for Simplified Chinese for which zh-CN
is returned. For an unknown/undefined language, und
is returned.
Promise<string>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.discard(
tabId?: number,
callback?: function,
)
Discards a tab from memory. Discarded tabs are still visible on the tab strip and are reloaded when activated.
number optional
The ID of the tab to be discarded. If specified, the tab is discarded unless it is active or already discarded. If omitted, the browser discards the least important tab. This can fail if no discardable tabs exist.
function optional
The callback
parameter looks like: (tab?: Tab) => void
Tab optional
The discarded tab, if it was successfully discarded; undefined otherwise.
Promise<Tab | undefined>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.duplicate(
tabId: number,
callback?: function,
)
Duplicates a tab.
number
The ID of the tab to duplicate.
function optional
The callback
parameter looks like: (tab?: Tab) => void
Promise<Tab | undefined>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.get(
tabId: number,
callback?: function,
)
Retrieves details about the specified tab.
number
function optional
The callback
parameter looks like: (tab: Tab) => void
Promise<Tab>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.getCurrent(
callback?: function,
)
Gets the tab that this script call is being made from. Returns undefined
if called from a non-tab context (for example, a background page or popup view).
Promise<Tab | undefined>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.getZoom(
tabId?: number,
callback?: function,
)
Gets the current zoom factor of a specified tab.
number optional
The ID of the tab to get the current zoom factor from; defaults to the active tab of the current window.
function optional
The callback
parameter looks like: (zoomFactor: number) => void
number
The tab's current zoom factor.
Promise<number>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.getZoomSettings(
tabId?: number,
callback?: function,
)
Gets the current zoom settings of a specified tab.
number optional
The ID of the tab to get the current zoom settings from; defaults to the active tab of the current window.
function optional
The callback
parameter looks like: (zoomSettings: ZoomSettings) => void
The tab's current zoom settings.
Promise<ZoomSettings>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.goBack(
tabId?: number,
callback?: function,
)
Go back to the previous page, if one is available.
number optional
The ID of the tab to navigate back; defaults to the selected tab of the current window.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.goForward(
tabId?: number,
callback?: function,
)
Go foward to the next page, if one is available.
number optional
The ID of the tab to navigate forward; defaults to the selected tab of the current window.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.group(
options: object,
callback?: function,
)
Adds one or more tabs to a specified group, or if no group is specified, adds the given tabs to a newly created group.
object
object optional
Configurations for creating a group. Cannot be used if groupId is already specified.
number optional
The window of the new group. Defaults to the current window.
number optional
The ID of the group to add the tabs to. If not specified, a new group will be created.
number | [number, ...number[]]
The tab ID or list of tab IDs to add to the specified group.
function optional
The callback
parameter looks like: (groupId: number) => void
number
The ID of the group that the tabs were added to.
Promise<number>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.highlight(
highlightInfo: object,
callback?: function,
)
Highlights the given tabs and focuses on the first of group. Will appear to do nothing if the specified tab is currently active.
object
number | number[]
One or more tab indices to highlight.
number optional
The window that contains the tabs.
function optional
The callback
parameter looks like: (window: Window) => void
Contains details about the window whose tabs were highlighted.
Promise<windows.Window>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.move(
tabIds: number | number[],
moveProperties: object,
callback?: function,
)
Moves one or more tabs to a new position within its window, or to a new window. Note that tabs can only be moved to and from normal (window.type === "normal") windows.
number | number[]
The tab ID or list of tab IDs to move.
object
number
The position to move the window to. Use -1
to place the tab at the end of the window.
number optional
Defaults to the window the tab is currently in.
function optional
The callback
parameter looks like: (tabs: Tab | Tab[]) => void
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.query(
queryInfo: object,
callback?: function,
)
Gets all tabs that have the specified properties, or all tabs if no properties are specified.
object
boolean optional
Whether the tabs are active in their windows.
boolean optional
Whether the tabs are audible.
boolean optional
Whether the tabs can be discarded automatically by the browser when resources are low.
boolean optional
Whether the tabs are in the current window.
boolean optional
Whether the tabs are discarded. A discarded tab is one whose content has been unloaded from memory, but is still visible in the tab strip. Its content is reloaded the next time it is activated.
boolean optional
Whether the tabs are frozen. A frozen tab cannot execute tasks, including event handlers or timers. It is visible in the tab strip and its content is loaded in memory. It is unfrozen on activation.
number optional
The ID of the group that the tabs are in, or tabGroups.TAB_GROUP_ID_NONE
for ungrouped tabs.
boolean optional
Whether the tabs are highlighted.
number optional
The position of the tabs within their windows.
boolean optional
Whether the tabs are in the last focused window.
boolean optional
Whether the tabs are muted.
boolean optional
Whether the tabs are pinned.
TabStatus optional
The tab loading status.
string optional
Match page titles against a pattern. This property is ignored if the extension does not have the "tabs"
permission or host permissions for the page.
string | string[] optional
Match tabs against one or more URL patterns. Fragment identifiers are not matched. This property is ignored if the extension does not have the "tabs"
permission or host permissions for the page.
number optional
The ID of the parent window, or windows.WINDOW_ID_CURRENT
for the current window.
WindowType optional
The type of window the tabs are in.
function optional
The callback
parameter looks like: (result: Tab[]) => void
Tab[]
Promise<Tab[]>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.reload(
tabId?: number,
reloadProperties?: object,
callback?: function,
)
Reload a tab.
number optional
The ID of the tab to reload; defaults to the selected tab of the current window.
object optional
boolean optional
Whether to bypass local caching. Defaults to false
.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.remove(
tabIds: number | number[],
callback?: function,
)
Closes one or more tabs.
number | number[]
The tab ID or list of tab IDs to close.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.sendMessage(
tabId: number,
message: any,
options?: object,
callback?: function,
)
Sends a single message to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The runtime.onMessage
event is fired in each content script running in the specified tab for the current extension.
number
any
The message to send. This message should be a JSON-ifiable object.
object optional
function optional
The callback
parameter looks like: (response: any) => void
any
The JSON response object sent by the handler of the message. If an error occurs while connecting to the specified tab, the callback is called with no arguments and runtime.lastError
is set to the error message.
Promise<any>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.setZoom(
tabId?: number,
zoomFactor: number,
callback?: function,
)
Zooms a specified tab.
number optional
The ID of the tab to zoom; defaults to the active tab of the current window.
number
The new zoom factor. A value of 0
sets the tab to its current default zoom factor. Values greater than 0
specify a (possibly non-default) zoom factor for the tab.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.setZoomSettings(
tabId?: number,
zoomSettings: ZoomSettings,
callback?: function,
)
Sets the zoom settings for a specified tab, which define how zoom changes are handled. These settings are reset to defaults upon navigating the tab.
number optional
The ID of the tab to change the zoom settings for; defaults to the active tab of the current window.
Defines how zoom changes are handled and at what scope.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.ungroup(
tabIds: number | [number, ...number[]],
callback?: function,
)
Removes one or more tabs from their respective groups. If any groups become empty, they are deleted.
number | [number, ...number[]]
The tab ID or list of tab IDs to remove from their respective groups.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.update(
tabId?: number,
updateProperties: object,
callback?: function,
)
Modifies the properties of a tab. Properties that are not specified in updateProperties
are not modified.
number optional
Defaults to the selected tab of the current window.
object
boolean optional
Whether the tab should be active. Does not affect whether the window is focused (see windows.update
).
boolean optional
Whether the tab should be discarded automatically by the browser when resources are low.
boolean optional
Adds or removes the tab from the current selection.
boolean optional
Whether the tab should be muted.
number optional
The ID of the tab that opened this tab. If specified, the opener tab must be in the same window as this tab.
boolean optional
Whether the tab should be pinned.
boolean optional
Please use highlighted.
Whether the tab should be selected.
string optional
A URL to navigate the tab to. JavaScript URLs are not supported; use scripting.executeScript
instead.
function optional
The callback
parameter looks like: (tab?: Tab) => void
Promise<Tab | undefined>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.tabs.onActivated.addListener(
callback: function,
)
Fires when the active tab in a window changes. Note that the tab's URL may not be set at the time this event fired, but you can listen to onUpdated events so as to be notified when a URL is set.
function
The callback
parameter looks like: (activeInfo: object) => void
object
number
The ID of the tab that has become active.
number
The ID of the window the active tab changed inside of.
chrome.tabs.onAttached.addListener(
callback: function,
)
Fired when a tab is attached to a window; for example, because it was moved between windows.
function
The callback
parameter looks like: (tabId: number, attachInfo: object) => void
number
object
number
number
chrome.tabs.onCreated.addListener(
callback: function,
)
Fired when a tab is created. Note that the tab's URL and tab group membership may not be set at the time this event is fired, but you can listen to onUpdated events so as to be notified when a URL is set or the tab is added to a tab group.
chrome.tabs.onDetached.addListener(
callback: function,
)
Fired when a tab is detached from a window; for example, because it was moved between windows.
function
The callback
parameter looks like: (tabId: number, detachInfo: object) => void
number
object
number
number
chrome.tabs.onHighlighted.addListener(
callback: function,
)
Fired when the highlighted or selected tabs in a window changes.
function
The callback
parameter looks like: (highlightInfo: object) => void
object
number[]
All highlighted tabs in the window.
number
The window whose tabs changed.
chrome.tabs.onMoved.addListener(
callback: function,
)
Fired when a tab is moved within a window. Only one move event is fired, representing the tab the user directly moved. Move events are not fired for the other tabs that must move in response to the manually-moved tab. This event is not fired when a tab is moved between windows; for details, see tabs.onDetached
.
function
The callback
parameter looks like: (tabId: number, moveInfo: object) => void
number
object
number
number
number
chrome.tabs.onRemoved.addListener(
callback: function,
)
Fired when a tab is closed.
function
The callback
parameter looks like: (tabId: number, removeInfo: object) => void
number
object
boolean
True when the tab was closed because its parent window was closed.
number
The window whose tab is closed.
chrome.tabs.onReplaced.addListener(
callback: function,
)
Fired when a tab is replaced with another tab due to prerendering or instant.
function
The callback
parameter looks like: (addedTabId: number, removedTabId: number) => void
number
number
chrome.tabs.onUpdated.addListener(
callback: function,
)
Fired when a tab is updated.
function
The callback
parameter looks like: (tabId: number, changeInfo: object, tab: Tab) => void
number
object
boolean optional
The tab's new audible state.
boolean optional
The tab's new auto-discardable state.
boolean optional
The tab's new discarded state.
string optional
The tab's new favicon URL.
boolean optional
The tab's new frozen state.
number optional
The tab's new group.
MutedInfo optional
The tab's new muted state and the reason for the change.
boolean optional
The tab's new pinned state.
TabStatus optional
The tab's loading status.
string optional
The tab's new title.
string optional
The tab's URL if it has changed.
chrome.tabs.onZoomChange.addListener(
callback: function,
)
Fired when a tab is zoomed.
function
The callback
parameter looks like: (ZoomChangeInfo: object) => void
object
number
number
number
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-01-13 UTC.