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 inautomatic
mode, andper-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
Edge | Firefox | Chrome | Opera | |
---|---|---|---|---|
MutedInfo | ? | 47.0 | Yes | 33 |
MutedInfoReason | ? | 47.0 | Yes | 33 |
TAB_ID_NONE | ? | 45.0 | Yes | 33 |
Tab | ? | 45.0 | Yes | 33 |
TabStatus | ? | 45.0 | Yes | 33 |
WindowType | ? | 45.0 | Yes | 33 |
ZoomSettings | ? | 45.0 | Yes | 33 |
ZoomSettingsMode | ? | 45.0 | Yes | 33 |
ZoomSettingsScope | ? | 45.0 | Yes | 33 |
captureVisibleTab | ? | 47.0 | Yes | 33 |
connect | ? | 45.0 | Yes | 33 |
create | ? | 45.01 | Yes | 33 |
detectLanguage | ? | 45.0 | Yes | 33 |
duplicate | ? | 47.0 | Yes | 33 |
executeScript | ? | 43.0 | Yes | 33 |
get | ? | 45.0 | Yes | 33 |
getAllInWindow | ? | 45.0 | Yes | No |
getCurrent | ? | 45.0 | Yes | 33 |
getSelected | ? | No | Yes | No |
getZoom | ? | 45.0 | Yes | 33 |
getZoomSettings | ? | 45.0 | Yes | 33 |
highlight | ? | 45.0 | Yes | No |
insertCSS | ? | 47.0 | Yes | 33 |
move | ? | 46.0 | Yes | 33 |
onActivated | ? | 45.0 | Yes | 33 |
onActiveChanged | ? | No | Yes | No |
onAttached | ? | 45.0 | Yes | 33 |
onCreated | ? | 45.0 | Yes | 33 |
onDetached | ? | 45.0 | Yes | 33 |
onHighlightChanged | ? | No | Yes | No |
onHighlighted | ? | 45.0 | Yes | No |
onMoved | ? | 45.0 | Yes | 33 |
onRemoved | ? | 45.0 | Yes | 33 |
onReplaced | ? | 45.0 | Yes | 33 |
onSelectionChanged | ? | No | Yes | No |
onUpdated | ? | 45.0 | Yes | 33 |
onZoomChange | ? | 45.0 | Yes | 33 |
query | ? | 45.0 | Yes | 33 |
reload | ? | 45.0 | Yes | 33 |
remove | ? | 45.0 | Yes | 33 |
sendMessage | ? | 45.0 | Yes | 33 |
sendRequest | ? | No | Yes | No |
setZoom | ? | 45.0 | Yes | 33 |
setZoomSettings | ? | 45.0 | Yes | 33 |
update | ? | 45.02 | Yes | 33 |
Firefox | |
---|---|
MutedInfo | No |
MutedInfoReason | No |
TAB_ID_NONE | No |
Tab | No |
TabStatus | No |
WindowType | No |
ZoomSettings | No |
ZoomSettingsMode | No |
ZoomSettingsScope | No |
captureVisibleTab | No |
connect | No |
create | No |
detectLanguage | No |
duplicate | No |
executeScript | No |
get | No |
getAllInWindow | No |
getCurrent | No |
getSelected | No |
getZoom | No |
getZoomSettings | No |
highlight | No |
insertCSS | No |
move | No |
onActivated | No |
onActiveChanged | No |
onAttached | No |
onCreated | No |
onDetached | No |
onHighlightChanged | No |
onHighlighted | No |
onMoved | No |
onRemoved | No |
onReplaced | No |
onSelectionChanged | No |
onUpdated | No |
onZoomChange | No |
query | No |
reload | No |
remove | No |
sendMessage | No |
sendRequest | No |
setZoom | No |
setZoomSettings | No |
update | No |
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.
The "Chrome incompatibilities" section is included from https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities using the WebExtChromeCompat macro.
If you need to update this content, edit https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities, then shift-refresh this page to see your changes.
Chrome incompatibilities
- Firefox does not support:
sendRequest()
getSelected()
onActiveChanged
onHighlightChanged
onSelectionChanged
- Additionally:
- Firefox treats
highlighted
andactive
as the same, since Firefox has no concept of selecting multiple tabs. - In Firefox, you need the
tabs
permission if you want to includeurl
in thequeryInfo
parameter totabs.query()
. -
In Firefox, relative URLs passed into
tabs.executeScript()
ortabs.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 (usingtabs.update
) privileged URLs:- chrome: URLs
- javascript: URLs
- data: URLs
- privileged about: URLs (for example, about:config, about:addons, about:debugging)
- Firefox treats
Example add-ons
This API is based on Chromium's chrome.tabs
API. This documentation is derived from tabs.json
in the Chromium code.
// Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.