Перевод не завершен. Пожалуйста, помогите перевести эту статью с английского.

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

ChromeEdgeFirefoxFirefox for AndroidOpera
MutedInfo Да Нет47 Нет Да
MutedInfoReason Да Нет47 Нет Да
PageSettings Нет Нет56 Нет Нет
TAB_ID_NONE Да Да4554 Да
TabStatus Да Да4554 Да
WindowType Да Да4554 Да
ZoomSettings Да Нет45 Нет Да
ZoomSettingsMode Да Нет45 Нет Да
ZoomSettingsScope Да Нет45 Нет Да
captureVisibleTab Да *154754 Да *
connect Да Нет4554 Да
create Да Да4554 Да
detectLanguage Да Да45 Нет Да
duplicate Да Нет4754 Да
executeScript Да * Да *43 *54 * Да *
get Да Да4554 Да
getAllInWindow Да Нет4554 Нет
getCurrent Да Да4554 Да
getSelected Да Нет Нет Нет Нет
getZoom Да Нет45 Нет Да
getZoomSettings Да Нет45 Нет Да
highlight Да Нет Нет Нет Нет
insertCSS Да * Да *47 *54 * Да *
move Да Нет46 Нет Да
onActivated Да Да4554 Да
onActiveChanged Да Нет Нет Нет Нет
onAttached Да154554 Да
onCreated Да Да4554 Да
onDetached Да154554 Да
onHighlightChanged Да Нет Нет Нет Нет
onHighlighted Да Нет4554 Нет
onMoved Да Нет45 Нет Да
onRemoved Да Да4554 Да
onReplaced Да Нет Нет Нет Да
onSelectionChanged Да Нет Нет Нет Нет
onUpdated Да Да4554 Да
onZoomChange Да Нет45 Нет Да
print Нет Нет56 Нет Нет
printPreview Нет Нет56 Нет Нет
query Да Да *4554 Да
reload Да Нет4554 Да
remove Да Да4554 Да
removeCSS Нет Нет4954 Нет
saveAsPDF Нет Нет56 * Нет Нет
sendMessage Да Да *4554 Да
sendRequest Да Нет Нет Нет Нет
setZoom Да Нет45 Нет Да
setZoomSettings Да Нет45 Нет Да
toggleReaderMode Нет Нет58 Нет Нет
update Да Да4554 Да

Chrome incompatibilities

tabs

  • 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 extension's base URL. To work cross-browser, you can specify the path as an absolute URL, starting at the extension's root, like this:

    /path/to/script.js
  • In Firefox, querying tabs by URL with tabs.query() requires "tabs" permission. In Chrome, it's possible without the "tabs" permission but will limit results to tabs whose URLs match host permissions.
  • In Firefox, the tabs.remove() promise is fulfilled after the beforeunload event while in Chrome the callback does not wait for beforeunload.

Example extensions

Acknowledgements

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

Метки документа и участники

 Внесли вклад в эту страницу: wbamberg
 Обновлялась последний раз: wbamberg,