tabs

Interact with the browser's tab system. You can use this API to get a list of opened tabs and to create, modify, and rearrange tabs in the browser.

You can use most of this API without any special permission. However, to access Tab.url, Tab.title, and Tab.faviconUrl, you need to have the "tabs" permission. In Firefox this also means you need "tabs" to query by URL.

Types

tabs.MutedInfoReason
An event that caused a muted state change.
tabs.MutedInfo
Tab muted state and the reason for the last state change.
tabs.Tab
Contains various properties of a single tab.
tabs.ZoomSettingsMode
Defines how zoom changes are handled, i.e. which entity is responsible for the actual scaling of the page; defaults to automatic.
tabs.ZoomSettingsScope
Defines whether zoom changes will 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.
tabs.ZoomSettings
Defines how zoom changes in a tab are handled and at what scope.
tabs.TabStatus
Whether the tabs have completed loading.
tabs.WindowType
The type of window.

Properties

tabs.TAB_ID_NONE
An ID which represents the absence of a browser tab.

Functions

tabs.get()
Retrieves details about the specified tab.
tabs.getCurrent()
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).
tabs.connect()
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.
tabs.sendRequest()
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.
tabs.sendMessage()
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.
tabs.getSelected()
Gets the tab that is selected in the specified window.
tabs.getAllInWindow()
Gets details about all tabs in the specified window.
tabs.create()
Creates a new tab.
tabs.duplicate()
Duplicates a tab.
tabs.query()
Gets all tabs that have the specified properties, or all tabs if no properties are specified.
tabs.highlight()
Highlights the given tabs.
tabs.update()
Modifies the properties of a tab. Properties that are not specified in updateProperties are not modified.
tabs.move()
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.
tabs.reload()
Reload a tab.
tabs.remove()
Closes one or more tabs.
tabs.detectLanguage()
Detects the primary language of the content in a tab.
tabs.captureVisibleTab()
Captures the visible area of the currently active tab in the specified window. You must have <all_urls> permission to use this method.
tabs.executeScript()
Injects JavaScript code into a page. For details, see the programmatic injection section of the content scripts doc.
tabs.insertCSS()
Injects CSS into a page. For details, see the programmatic injection section of the content scripts doc.
tabs.setZoom()
Zooms a specified tab.
tabs.getZoom()
Gets the current zoom factor of a specified tab.
tabs.setZoomSettings()
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.
tabs.getZoomSettings()
Gets the current zoom settings of a specified tab.

Events

tabs.onCreated
Fired when a tab is created. Note that the tab's URL may not be set at the time this event fired, but you can listen to onUpdated events to be notified when a URL is set.
tabs.onUpdated
Fired when a tab is updated.
tabs.onMoved
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. This event is not fired when a tab is moved between windows. For that, see tabs.onDetached.
tabs.onSelectionChanged
Fires when the selected tab in a window changes.
tabs.onActiveChanged
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 to be notified when a URL is set.
tabs.onActivated
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 to be notified when a URL is set.
tabs.onHighlightChanged
Fired when the highlighted or selected tabs in a window changes.
tabs.onHighlighted
Fired when the highlighted or selected tabs in a window changes.
tabs.onDetached
Fired when a tab is detached from a window, for example because it is being moved between windows.
tabs.onAttached
Fired when a tab is attached to a window, for example because it was moved between windows.
tabs.onRemoved
Fired when a tab is closed.
tabs.onReplaced
Fired when a tab is replaced with another tab due to prerendering or instant.
tabs.onZoomChange
Fired when a tab is zoomed.

Browser compatibility

EdgeFirefoxChromeOpera
MutedInfo?47.0Yes33
MutedInfoReason?47.0Yes33
TAB_ID_NONE?45.0Yes33
Tab?45.0Yes33
TabStatus?45.0Yes33
WindowType?45.0Yes33
ZoomSettings?45.0Yes33
ZoomSettingsMode?45.0Yes33
ZoomSettingsScope?45.0Yes33
captureVisibleTab?47.0Yes33
connect?45.0Yes33
create?45.01Yes33
detectLanguage?45.0Yes33
duplicate?47.0Yes33
executeScript?43.0Yes33
get?45.0Yes33
getAllInWindow?45.0YesNo
getCurrent?45.0Yes33
getSelected?NoYesNo
getZoom?45.0Yes33
getZoomSettings?45.0Yes33
highlight?45.0YesNo
insertCSS?47.0Yes33
move?46.0Yes33
onActivated?45.0Yes33
onActiveChanged?NoYesNo
onAttached?45.0Yes33
onCreated?45.0Yes33
onDetached?45.0Yes33
onHighlightChanged?NoYesNo
onHighlighted?45.0YesNo
onMoved?45.0Yes33
onRemoved?45.0Yes33
onReplaced?45.0Yes33
onSelectionChanged?NoYesNo
onUpdated?45.0Yes33
onZoomChange?45.0Yes33
query?45.0Yes33
reload?45.0Yes33
remove?45.0Yes33
sendMessage?45.0Yes33
sendRequest?NoYesNo
setZoom?45.0Yes33
setZoomSettings?45.0Yes33
update?45.02Yes33
Firefox
MutedInfoNo
MutedInfoReasonNo
TAB_ID_NONENo
TabNo
TabStatusNo
WindowTypeNo
ZoomSettingsNo
ZoomSettingsModeNo
ZoomSettingsScopeNo
captureVisibleTabNo
connectNo
createNo
detectLanguageNo
duplicateNo
executeScriptNo
getNo
getAllInWindowNo
getCurrentNo
getSelectedNo
getZoomNo
getZoomSettingsNo
highlightNo
insertCSSNo
moveNo
onActivatedNo
onActiveChangedNo
onAttachedNo
onCreatedNo
onDetachedNo
onHighlightChangedNo
onHighlightedNo
onMovedNo
onRemovedNo
onReplacedNo
onSelectionChangedNo
onUpdatedNo
onZoomChangeNo
queryNo
reloadNo
removeNo
sendMessageNo
sendRequestNo
setZoomNo
setZoomSettingsNo
updateNo

1. The 'selected' option is deprecated and not supported in Firefox. Use 'active' instead.
2. It's not possible to update the "highlighted" and "selected" properties.

Chrome incompatibilities

  • Firefox does not support:
    • sendRequest()
    • getSelected()
    • onActiveChanged
    • onHighlightChanged
    • onSelectionChanged
  • Additionally:
    • Firefox treats highlighted and active as the same, since Firefox has no concept of selecting multiple tabs.
    • In Firefox, you need the tabs permission if you want to include url in the queryInfo parameter to tabs.query().
    • In Firefox, relative URLs passed into tabs.executeScript() or tabs.insertCSS() are resolved relative to the current page URL. In Chrome, these URLs are resolved relative to the add-on's base URL. To work cross-browser, you can specify the path as an absolute URL, starting at the add-on's root, like this:

      /path/to/script.js
    • In Firefox, you can't open (using tabs.create), or navigate to (using tabs.update) privileged URLs:
      • chrome: URLs
      • javascript: URLs
      • data: URLs
      • privileged about: URLs (for example, about:config, about:addons, about:debugging)

Example add-ons

Acknowledgements

This API is based on Chromium's chrome.tabs API. This documentation is derived from tabs.json in the Chromium code.

Document Tags and Contributors

 Contributors to this page: wbamberg, kmaglione
 Last updated by: wbamberg,