Welcome What's new in Chrome extensions Getting started API Reference Samples
Welcome What's new in Chrome extensions Getting started API Reference Samples

chrome.tabs

  • Description

    Use the chrome.tabs API to interact with the browser's tab system. You can use this API to create, modify, and rearrange tabs in the browser.

Manifest

You can use most chrome.tabs methods and events without declaring any permissions in the extension's manifest file. However, if you require access to the url, pendingUrl, title, or favIconUrl properties of tabs.Tab, you must declare the "tabs" permission in the manifest, as shown below:

{
"name": "My extension",
...
"permissions": [
"tabs"
],
...
}

Examples

The following sections demonstrate several common use cases for the chrome.tabs API.

Opening an extension page in a new tab

A common pattern for extensions is to open an onboarding page in a new tab when the extension is installed. The following example shows how to do this.

Content scripts cannot use chrome.tabs.create().

//// background.js

chrome.runtime.onInstalled.addListener((reason) => {
if (reason === chrome.runtime.OnInstalledReason.INSTALL) {
chrome.tabs.create({
url: 'onboarding.html'
});
}
});

Get the current tab

This example demonstrates how the background script can retrieve the currently focused tab.

This example requires Manifest V3 due to the use of Promises. Additionally, content scripts cannot use tabs.query.

//// background.js

async function getCurrentTab() {
let queryOptions = { active: true, currentWindow: true };
let [tab] = await chrome.tabs.query(queryOptions);
return tab;
}

Mute the specified tab

This example shows how an extension can toggle the muted state for a given tab.

Requires Manifest V3 due to the use of Promises. Content scripts cannot use tabs.get or tabs.update.

//// background.js

function toggleMuteState(tabId) {
chrome.tabs.get(tabId, async (tab) => {
let muted = !tab.mutedInfo.muted;
await chrome.tabs.update(tabId, { muted });
console.log(`Tab ${tab.id} is ${ muted ? 'muted' : 'unmuted' }`);
});
}

Move the current tab to the first position when clicked

This example shows how to move a tab while a drag may or may not be in progress.

Manifest V3 required due to the use of Promises and chrome.tabs.onActivated(), replacing chrome.tabs.onSelectionChanged(). The use of catch(error) in a Promise context is a way to ensure that an error that otherwise populates chrome.runtime.lastError is not unchecked. chrome.tabs.move is used in this example, but the same waiting pattern can be used for other calls that modify tabs while a drag may be in progress.

//// background.js

chrome.tabs.onActivated.addListener(activeInfo => move(activeInfo));

async function move(activeInfo) {
try {
await chrome.tabs.move(activeInfo.tabId, {index: 0});
console.log('Success.');
} catch (error) {
if (error == 'Error: Tabs cannot be edited right now (user may be dragging a tab).') {
setTimeout(() => move(activeInfo), 50);
}
}
}

More samples

For more examples that demonstrate the Tabs API, see the mv2-archive/api/tabs directory of the chrome-extensions-samples repository.

Summary

Types

MutedInfo

The tab's muted state and the reason for the last state change.

Properties

  • extensionId
    string optional

    The ID of the extension that changed the muted state. Not set if an extension was not the reason the muted state last changed.

  • muted
    boolean

    Whether the tab is muted (prevented from playing sound). The tab may be muted even if it has not played or is not currently playing sound. Equivalent to whether the 'muted' audio indicator is showing.

  • reason
    MutedInfoReason optional

    The reason the tab was muted or unmuted. Not set if the tab's mute state has never been changed.

MutedInfoReason

An event that caused a muted state change.

Enum

"user", "capture", or "extension"

Tab

Properties

  • active
    boolean

    Whether the tab is active in its window. Does not necessarily mean the window is focused.

  • audible
    boolean optional

    Whether the tab has produced sound over the past couple of seconds (but it might not be heard if also muted). Equivalent to whether the 'speaker audio' indicator is showing.

  • autoDiscardable
    boolean
    Chrome 54+

    Whether the tab can be discarded automatically by the browser when resources are low.

  • discarded
    boolean
    Chrome 54+

    Whether the tab is 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.

  • favIconUrl
    string optional

    The URL of the tab's favicon. This property is only present if the extension's manifest includes the "tabs" permission. It may also be an empty string if the tab is loading.

  • groupId
    number
    Chrome 88+

    The ID of the group that the tab belongs to.

  • height
    number optional

    The height of the tab in pixels.

  • highlighted
    boolean

    Whether the tab is highlighted.

  • id
    number optional

    The ID of the tab. Tab IDs are unique within a browser session. Under some circumstances a tab may not be assigned an ID; for example, when querying foreign tabs using the sessions API, in which case a session ID may be present. Tab ID can also be set to chrome.tabs.TAB_ID_NONE for apps and devtools windows.

  • incognito
    boolean

    Whether the tab is in an incognito window.

  • index
    number

    The zero-based index of the tab within its window.

  • mutedInfo
    MutedInfo optional

    The tab's muted state and the reason for the last state change.

  • openerTabId
    number optional

    The ID of the tab that opened this tab, if any. This property is only present if the opener tab still exists.

  • pendingUrl
    string optional
    Chrome 79+

    The URL the tab is navigating to, before it has committed. This property is only present if the extension's manifest includes the "tabs" permission and there is a pending navigation.

  • pinned
    boolean

    Whether the tab is pinned.

  • selected
    boolean
    Deprecated

    Please use tabs.Tab.highlighted.

    Whether the tab is selected.

  • sessionId
    string optional

    The session ID used to uniquely identify a tab obtained from the sessions API.

  • status
    TabStatus optional

    The tab's loading status.

  • title
    string optional

    The title of the tab. This property is only present if the extension's manifest includes the "tabs" permission.

  • url
    string optional

    The last committed URL of the main frame of the tab. This property is only present if the extension's manifest includes the "tabs" permission and may be an empty string if the tab has not yet committed. See also Tab.pendingUrl.

  • width
    number optional

    The width of the tab in pixels.

  • windowId
    number

    The ID of the window that contains the tab.

TabStatus

The tab's loading status.

Enum

"unloaded", "loading", or "complete"

WindowType

The type of window.

Enum

"normal", "popup", "panel", "app", or "devtools"

ZoomSettings

Defines how zoom changes in a tab are handled and at what scope.

Properties

  • defaultZoomFactor
    number optional

    Used to return the default zoom level for the current tab in calls to tabs.getZoomSettings.

  • mode

    Defines how zoom changes are handled, i.e., which entity is responsible for the actual scaling of the page; defaults to automatic.

  • scope

    Defines whether zoom changes persist for the page's origin, or only take effect in this tab; defaults to per-origin when in automatic mode, and per-tab otherwise.

ZoomSettingsMode

Defines how zoom changes are handled, i.e., which entity is responsible for the actual scaling of the page; defaults to automatic.

Enum

"automatic", "manual", or "disabled"

ZoomSettingsScope

Defines whether zoom changes persist for the page's origin, or only take effect in this tab; defaults to per-origin when in automatic mode, and per-tab otherwise.

Enum

"per-origin", or "per-tab"

Properties

MAX_CAPTURE_VISIBLE_TAB_CALLS_PER_SECOND

Chrome 92+

The maximum number of times that captureVisibleTab can be called per second. captureVisibleTab is expensive and should not be called too often.

Value

2

TAB_ID_NONE

An ID that represents the absence of a browser tab.

Value

-1

Methods

captureVisibleTab

captureVisibleTab(windowId?: number, options?: extensionTypes.ImageDetails): Promise<object>
captureVisibleTab(windowId?: number, options?: extensionTypes.ImageDetails, callback: function): void
Promise

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.

Parameters

Result

  • return/callback
    async

    The captureVisibleTab method provides its result via callback or returned as a Promise (MV3 only).

    • dataUrl
      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.

connect

connect(tabId: number, connectInfo?: object): runtime.Port

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.

Parameters

  • tabId
    number
  • connectInfo
    object optional
    • frameId
      number optional

      Open a port to a specific frame identified by frameId instead of all frames in the tab.

    • name
      string optional

      Is passed into onConnect for content scripts that are listening for the connection event.

Returns

  • 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.

create

create(createProperties: object): Promise<object>
create(createProperties: object, callback?: function): void
Promise

Creates a new tab.

Parameters

  • createProperties
    object
    • active
      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.

    • index
      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.

    • openerTabId
      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.

    • pinned
      boolean optional

      Whether the tab should be pinned. Defaults to false

    • selected
      boolean optional
      Deprecated

      Please use active.

      Whether the tab should become the selected tab in the window. Defaults to true

    • url
      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.

    • windowId
      number optional

      The window in which to create the new tab. Defaults to the current window.

Result

  • return/callback
    async

    The create method provides its result via callback or returned as a Promise (MV3 only).

    • tab

      The created tab.

detectLanguage

detectLanguage(tabId?: number): Promise<object>
detectLanguage(tabId?: number, callback: function): void
Promise

Detects the primary language of the content in a tab.

Parameters

  • tabId
    number optional

    Defaults to the active tab of the current window.

Result

  • return/callback
    async

    The detectLanguage method provides its result via callback or returned as a Promise (MV3 only).

    • language
      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.

discard

discard(tabId?: number): Promise<object>
discard(tabId?: number, callback?: function): void
Promise Chrome 54+

Discards a tab from memory. Discarded tabs are still visible on the tab strip and are reloaded when activated.

Parameters

  • tabId
    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.

Result

  • return/callback
    async

    Called after the operation is completed.

    The discard method provides its result via callback or returned as a Promise (MV3 only).

    • tab
      Tab optional

      The discarded tab, if it was successfully discarded; undefined otherwise.

duplicate

duplicate(tabId: number): Promise<object>
duplicate(tabId: number, callback?: function): void
Promise

Duplicates a tab.

Parameters

  • tabId
    number

    The ID of the tab to duplicate.

Result

  • return/callback
    async

    The duplicate method provides its result via callback or returned as a Promise (MV3 only).

    • tab
      Tab optional

      Details about the duplicated tab. The tabs.Tab object does not contain url, pendingUrl, title, and favIconUrl if the "tabs" permission has not been requested.

executeScript

executeScript(tabId?: number, details: extensionTypes.InjectDetails): Promise<object>
executeScript(tabId?: number, details: extensionTypes.InjectDetails, callback?: function): void
Promise Manifest V2 Deprecated 91+

Replaced by scripting.executeScript in Manifest V3.

Injects JavaScript code into a page. For details, see the programmatic injection section of the content scripts doc.

Parameters

  • tabId
    number optional
    Deprecated

    The ID of the tab in which to run the script; defaults to the active tab of the current window.

  • Deprecated

    Details of the script to run. Either the code or the file property must be set, but both may not be set at the same time.

Result

  • return/callback
    async
    Deprecated

    Called after all the JavaScript has been executed.

    The executeScript method provides its result via callback or returned as a Promise (MV3 only).

    • result
      any[] optional
      Deprecated

      The result of the script in every injected frame.

get

get(tabId: number): Promise<object>
get(tabId: number, callback: function): void
Promise

Retrieves details about the specified tab.

Parameters

  • tabId
    number

Result

  • return/callback
    async

    The get method provides its result via callback or returned as a Promise (MV3 only).

getAllInWindow

getAllInWindow(windowId?: number): Promise<object>
getAllInWindow(windowId?: number, callback: function): void
Promise Manifest V2 Deprecated

Please use tabs.query {windowId: windowId}.

Gets details about all tabs in the specified window.

Parameters

Result

  • return/callback
    async
    Deprecated

    The getAllInWindow method provides its result via callback or returned as a Promise (MV3 only).

    • tabs
      Tab[]
      Deprecated

getCurrent

getCurrent(): Promise<object>
getCurrent(callback: function): void
Promise

Gets the tab that this script call is being made from. May be undefined if called from a non-tab context (for example, a background page or popup view).

Result

  • return/callback
    async

    The getCurrent method provides its result via callback or returned as a Promise (MV3 only).

    • tab
      Tab optional

getSelected

getSelected(windowId?: number): Promise<object>
getSelected(windowId?: number, callback: function): void
Promise Manifest V2 Deprecated

Please use tabs.query {active: true}.

Gets the tab that is selected in the specified window.

Parameters

Result

  • return/callback
    async
    Deprecated

    The getSelected method provides its result via callback or returned as a Promise (MV3 only).

    • tab
      Deprecated

getZoom

getZoom(tabId?: number): Promise<object>
getZoom(tabId?: number, callback: function): void
Promise

Gets the current zoom factor of a specified tab.

Parameters

  • tabId
    number optional

    The ID of the tab to get the current zoom factor from; defaults to the active tab of the current window.

Result

  • return/callback
    async

    Called with the tab's current zoom factor after it has been fetched.

    The getZoom method provides its result via callback or returned as a Promise (MV3 only).

    • zoomFactor
      number

      The tab's current zoom factor.

getZoomSettings

getZoomSettings(tabId?: number): Promise<object>
getZoomSettings(tabId?: number, callback: function): void
Promise

Gets the current zoom settings of a specified tab.

Parameters

  • tabId
    number optional

    The ID of the tab to get the current zoom settings from; defaults to the active tab of the current window.

Result

  • return/callback
    async

    Called with the tab's current zoom settings.

    The getZoomSettings method provides its result via callback or returned as a Promise (MV3 only).

goBack

goBack(tabId?: number): Promise<object>
goBack(tabId?: number, callback?: function): void
Promise Chrome 72+

Go back to the previous page, if one is available.

Parameters

  • tabId
    number optional

    The ID of the tab to navigate back; defaults to the selected tab of the current window.

Result

  • return/callback
    async

    The goBack method provides its result via callback or returned as a Promise (MV3 only). It has no parameters.

goForward

goForward(tabId?: number): Promise<object>
goForward(tabId?: number, callback?: function): void
Promise Chrome 72+

Go foward to the next page, if one is available.

Parameters

  • tabId
    number optional

    The ID of the tab to navigate forward; defaults to the selected tab of the current window.

Result

  • return/callback
    async

    The goForward method provides its result via callback or returned as a Promise (MV3 only). It has no parameters.

group

group(options: object): Promise<object>
group(options: object, callback?: function): void
Promise Chrome 88+

Adds one or more tabs to a specified group, or if no group is specified, adds the given tabs to a newly created group.

Parameters

  • options
    object
    • createProperties
      object optional

      Configurations for creating a group. Cannot be used if groupId is already specified.

      • windowId
        number optional

        The window of the new group. Defaults to the current window.

    • groupId
      number optional

      The ID of the group to add the tabs to. If not specified, a new group will be created.

    • tabIds
      number | number[]

      The tab ID or list of tab IDs to add to the specified group.

Result

  • return/callback
    async

    The group method provides its result via callback or returned as a Promise (MV3 only).

    • groupId
      number

      The ID of the group that the tabs were added to.

highlight

highlight(highlightInfo: object): Promise<object>
highlight(highlightInfo: object, callback?: function): void
Promise

Highlights the given tabs and focuses on the first of group. Will appear to do nothing if the specified tab is currently active.

Parameters

  • highlightInfo
    object
    • tabs
      number[] | number

      One or more tab indices to highlight.

    • windowId
      number optional

      The window that contains the tabs.

Result

  • return/callback
    async

    The highlight method provides its result via callback or returned as a Promise (MV3 only).

    • Contains details about the window whose tabs were highlighted.

insertCSS

insertCSS(tabId?: number, details: extensionTypes.InjectDetails): Promise<object>
insertCSS(tabId?: number, details: extensionTypes.InjectDetails, callback?: function): void
Promise Manifest V2 Deprecated 91+

Replaced by scripting.insertCSS in Manifest V3.

Injects CSS into a page. Styles inserted with this method can be removed with scripting.removeCSS. For details, see the programmatic injection section of the content scripts doc.

Parameters

  • tabId
    number optional
    Deprecated

    The ID of the tab in which to insert the CSS; defaults to the active tab of the current window.

  • Deprecated

    Details of the CSS text to insert. Either the code or the file property must be set, but both may not be set at the same time.

Result

  • return/callback
    async
    Deprecated

    Called when all the CSS has been inserted.

    The insertCSS method provides its result via callback or returned as a Promise (MV3 only). It has no parameters.

move

move(tabIds: number | number[], moveProperties: object): Promise<object>
move(tabIds: number | number[], moveProperties: object, callback?: function): void
Promise

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.

Parameters

  • tabIds
    number | number[]

    The tab ID or list of tab IDs to move.

  • moveProperties
    object
    • index
      number

      The position to move the window to. Use -1 to place the tab at the end of the window.

    • windowId
      number optional

      Defaults to the window the tab is currently in.

Result

  • return/callback
    async

    The move method provides its result via callback or returned as a Promise (MV3 only).

    • tabs
      Tab | Tab[]

      Details about the moved tabs.

query

query(queryInfo: object): Promise<object>
query(queryInfo: object, callback: function): void
Promise

Gets all tabs that have the specified properties, or all tabs if no properties are specified.

Parameters

  • queryInfo
    object
    • active
      boolean optional

      Whether the tabs are active in their windows.

    • audible
      boolean optional

      Whether the tabs are audible.

    • autoDiscardable
      boolean optional
      Chrome 54+

      Whether the tabs can be discarded automatically by the browser when resources are low.

    • currentWindow
      boolean optional

      Whether the tabs are in the current window.

    • discarded
      boolean optional
      Chrome 54+

      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.

    • groupId
      number optional
      Chrome 88+

      The ID of the group that the tabs are in, or tabGroups.TAB_GROUP_ID_NONE for ungrouped tabs.

    • highlighted
      boolean optional

      Whether the tabs are highlighted.

    • index
      number optional

      The position of the tabs within their windows.

    • lastFocusedWindow
      boolean optional

      Whether the tabs are in the last focused window.

    • muted
      boolean optional

      Whether the tabs are muted.

    • pinned
      boolean optional

      Whether the tabs are pinned.

    • status
      TabStatus optional

      The tab loading status.

    • title
      string optional

      Match page titles against a pattern. This property is ignored if the extension does not have the "tabs" permission.

    • url
      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.

    • windowId
      number optional

      The ID of the parent window, or windows.WINDOW_ID_CURRENT for the current window.

    • windowType
      WindowType optional

      The type of window the tabs are in.

Result

  • return/callback
    async

    The query method provides its result via callback or returned as a Promise (MV3 only).

reload

reload(tabId?: number, reloadProperties?: object): Promise<object>
reload(tabId?: number, reloadProperties?: object, callback?: function): void
Promise

Reload a tab.

Parameters

  • tabId
    number optional

    The ID of the tab to reload; defaults to the selected tab of the current window.

  • reloadProperties
    object optional
    • bypassCache
      boolean optional

      Whether to bypass local caching. Defaults to false.

Result

  • return/callback
    async

    The reload method provides its result via callback or returned as a Promise (MV3 only). It has no parameters.

remove

remove(tabIds: number | number[]): Promise<object>
remove(tabIds: number | number[], callback?: function): void
Promise

Closes one or more tabs.

Parameters

  • tabIds
    number | number[]

    The tab ID or list of tab IDs to close.

Result

  • return/callback
    async

    The remove method provides its result via callback or returned as a Promise (MV3 only). It has no parameters.

removeCSS

removeCSS(tabId?: number, details: extensionTypes.DeleteInjectionDetails): Promise<object>
removeCSS(tabId?: number, details: extensionTypes.DeleteInjectionDetails, callback?: function): void
Promise Chrome 87+ Manifest V2 Deprecated 91+

Replaced by scripting.removeCSS in Manifest V3.

Removes from a page CSS that was previously injected by a call to scripting.insertCSS.

Parameters

  • tabId
    number optional
    Deprecated

    The ID of the tab from which to remove the CSS; defaults to the active tab of the current window.

  • Deprecated

    Details of the CSS text to remove. Either the code or the file property must be set, but both may not be set at the same time.

Result

  • return/callback
    async
    Deprecated

    Called when all the CSS has been removed.

    The removeCSS method provides its result via callback or returned as a Promise (MV3 only). It has no parameters.

sendMessage

sendMessage(tabId: number, message: any, options?: object, responseCallback?: function): void

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.

Parameters

  • tabId
    number
  • message
    any

    The message to send. This message should be a JSON-ifiable object.

  • options
    object optional
    • frameId
      number optional

      Send a message to a specific frame identified by frameId instead of all frames in the tab.

  • responseCallback
    function optional

    The responseCallback function looks like this:

    responseCallback(response: any) => {...}
    • response
      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.

sendRequest

sendRequest(tabId: number, request: any, responseCallback?: function): void
Manifest V2 Deprecated

Please use runtime.sendMessage.

Sends a single request to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The extension.onRequest event is fired in each content script running in the specified tab for the current extension.

Parameters

  • tabId
    number
    Deprecated
  • request
    any
    Deprecated
  • responseCallback
    function optional
    Deprecated

    The responseCallback function looks like this:

    responseCallback(response: any) => {...}
    • response
      any
      Deprecated

      The JSON response object sent by the handler of the request. 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.

setZoom

setZoom(tabId?: number, zoomFactor: number): Promise<object>
setZoom(tabId?: number, zoomFactor: number, callback?: function): void
Promise

Zooms a specified tab.

Parameters

  • tabId
    number optional

    The ID of the tab to zoom; defaults to the active tab of the current window.

  • zoomFactor
    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.

Result

  • return/callback
    async

    Called after the zoom factor has been changed.

    The setZoom method provides its result via callback or returned as a Promise (MV3 only). It has no parameters.

setZoomSettings

setZoomSettings(tabId?: number, zoomSettings: ZoomSettings): Promise<object>
setZoomSettings(tabId?: number, zoomSettings: ZoomSettings, callback?: function): void
Promise

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.

Parameters

  • tabId
    number optional

    The ID of the tab to change the zoom settings for; defaults to the active tab of the current window.

  • zoomSettings

    Defines how zoom changes are handled and at what scope.

Result

  • return/callback
    async

    Called after the zoom settings are changed.

    The setZoomSettings method provides its result via callback or returned as a Promise (MV3 only). It has no parameters.

ungroup

ungroup(tabIds: number | number[]): Promise<object>
ungroup(tabIds: number | number[], callback?: function): void
Promise Chrome 88+

Removes one or more tabs from their respective groups. If any groups become empty, they are deleted.

Parameters

  • tabIds
    number | number[]

    The tab ID or list of tab IDs to remove from their respective groups.

Result

  • return/callback
    async

    The ungroup method provides its result via callback or returned as a Promise (MV3 only). It has no parameters.

update

update(tabId?: number, updateProperties: object): Promise<object>
update(tabId?: number, updateProperties: object, callback?: function): void
Promise

Modifies the properties of a tab. Properties that are not specified in updateProperties are not modified.

Parameters

  • tabId
    number optional

    Defaults to the selected tab of the current window.

  • updateProperties
    object
    • active
      boolean optional

      Whether the tab should be active. Does not affect whether the window is focused (see windows.update).

    • autoDiscardable
      boolean optional
      Chrome 54+

      Whether the tab should be discarded automatically by the browser when resources are low.

    • highlighted
      boolean optional

      Adds or removes the tab from the current selection.

    • muted
      boolean optional

      Whether the tab should be muted.

    • openerTabId
      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.

    • pinned
      boolean optional

      Whether the tab should be pinned.

    • selected
      boolean optional
      Deprecated

      Please use highlighted.

      Whether the tab should be selected.

    • url
      string optional

      A URL to navigate the tab to. JavaScript URLs are not supported; use scripting.executeScript instead.

Result

  • return/callback
    async

    The update method provides its result via callback or returned as a Promise (MV3 only).

    • tab
      Tab optional

      Details about the updated tab. The tabs.Tab object does not contain url, pendingUrl, title, and favIconUrl if the "tabs" permission has not been requested.

Events

onActivated

onActivated.addListener(listener: 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.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (activeInfo: object) => {...}
    • activeInfo
      object
      • tabId
        number

        The ID of the tab that has become active.

      • windowId
        number

        The ID of the window the active tab changed inside of.

onActiveChanged

onActiveChanged.addListener(listener: function)
Manifest V2 Deprecated

Please use tabs.onActivated.

Fires when the selected 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 tabs.onUpdated events so as to be notified when a URL is set.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (tabId: number, selectInfo: object) => {...}
    • tabId
      number
      Deprecated

      The ID of the tab that has become active.

    • selectInfo
      object
      Deprecated
      • windowId
        number
        Deprecated

        The ID of the window the selected tab changed inside of.

onAttached

onAttached.addListener(listener: function)

Fired when a tab is attached to a window; for example, because it was moved between windows.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (tabId: number, attachInfo: object) => {...}
    • tabId
      number
    • attachInfo
      object
      • newPosition
        number
      • newWindowId
        number

onCreated

onCreated.addListener(listener: 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.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (tab: Tab) => {...}
    • tab

      Details of the tab that was created.

onDetached

onDetached.addListener(listener: function)

Fired when a tab is detached from a window; for example, because it was moved between windows.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (tabId: number, detachInfo: object) => {...}
    • tabId
      number
    • detachInfo
      object
      • oldPosition
        number
      • oldWindowId
        number

onHighlightChanged

onHighlightChanged.addListener(listener: function)
Manifest V2 Deprecated

Please use tabs.onHighlighted.

Fired when the highlighted or selected tabs in a window changes.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (selectInfo: object) => {...}
    • selectInfo
      object
      Deprecated
      • tabIds
        number[]
        Deprecated

        All highlighted tabs in the window.

      • windowId
        number
        Deprecated

        The window whose tabs changed.

onHighlighted

onHighlighted.addListener(listener: function)

Fired when the highlighted or selected tabs in a window changes.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (highlightInfo: object) => {...}
    • highlightInfo
      object
      • tabIds
        number[]

        All highlighted tabs in the window.

      • windowId
        number

        The window whose tabs changed.

onMoved

onMoved.addListener(listener: 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.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (tabId: number, moveInfo: object) => {...}
    • tabId
      number
    • moveInfo
      object
      • fromIndex
        number
      • toIndex
        number
      • windowId
        number

onRemoved

onRemoved.addListener(listener: function)

Fired when a tab is closed.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (tabId: number, removeInfo: object) => {...}
    • tabId
      number
    • removeInfo
      object
      • isWindowClosing
        boolean

        True when the tab was closed because its parent window was closed.

      • windowId
        number

        The window whose tab is closed.

onReplaced

onReplaced.addListener(listener: function)

Fired when a tab is replaced with another tab due to prerendering or instant.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (addedTabId: number, removedTabId: number) => {...}
    • addedTabId
      number
    • removedTabId
      number

onSelectionChanged

onSelectionChanged.addListener(listener: function)
Manifest V2 Deprecated

Please use tabs.onActivated.

Fires when the selected tab in a window changes.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (tabId: number, selectInfo: object) => {...}
    • tabId
      number
      Deprecated

      The ID of the tab that has become active.

    • selectInfo
      object
      Deprecated
      • windowId
        number
        Deprecated

        The ID of the window the selected tab changed inside of.

onUpdated

onUpdated.addListener(listener: function)

Fired when a tab is updated.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (tabId: number, changeInfo: object, tab: Tab) => {...}
    • tabId
      number
    • changeInfo
      object

      Lists the changes to the state of the tab that was updated.

      • audible
        boolean optional

        The tab's new audible state.

      • autoDiscardable
        boolean optional
        Chrome 54+

        The tab's new auto-discardable state.

      • discarded
        boolean optional
        Chrome 54+

        The tab's new discarded state.

      • favIconUrl
        string optional

        The tab's new favicon URL.

      • groupId
        number optional
        Chrome 88+

        The tab's new group.

      • mutedInfo
        MutedInfo optional

        The tab's new muted state and the reason for the change.

      • pinned
        boolean optional

        The tab's new pinned state.

      • status
        TabStatus optional

        The tab's loading status.

      • title
        string optional

        The tab's new title.

      • url
        string optional

        The tab's URL if it has changed.

    • tab

      Gives the state of the tab that was updated.

onZoomChange

onZoomChange.addListener(listener: function)

Fired when a tab is zoomed.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (ZoomChangeInfo: object) => {...}
    • ZoomChangeInfo
      object
      • newZoomFactor
        number
      • oldZoomFactor
        number
      • tabId
        number
      • zoomSettings
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.