这篇翻译不完整。请帮忙从英语翻译这篇文章

与浏览器标签系统进行交互。

你可以使用该API获取一个已打开标签的列表并且使用各种标准过滤标签,并进行 打开, 刷新,移动,重载,移除操作。该API不能直接访问标签中的主机内容,但是你可以使用 tabs.executeScript() 或者 tabs.insertCSS() APIs,来插入javascript和CSS。

你可以在不需要任何特殊权限的情况下使用该APIS的大部分, 除了:

或者你可以仅仅只为当前的活动标签临时的获取这些权限并且仅仅只响应一个显示的用户行为,请查看 "activeTab" permission.

枚举值

tabs.MutedInfoReason
确定一个标签静音与否的原因(用户修改,扩展修改)。
tabs.MutedInfo
该对象包含一个布尔值只是该标签是否静音,以及最近一次静音的原因。
tabs.Tab
该值包含了一个标签的信息。
tabs.TabStatus
指示某个标签是否已经加载完成
tabs.WindowType
包含该标签的窗口类型。
tabs.ZoomSettingsMode
定义缩放由浏览器控制或是扩展,或者禁用。
tabs.ZoomSettingsScope
定义缩放将对某个网址持续生效,或者仅仅只针对该标签。
tabs.ZoomSettings
定义缩放设置。 modescope, 和默认缩放比例。

属性

tabs.TAB_ID_NONE
给予非浏览器标签的一个特殊ID值 (比如,在开发工具中的标签)。

方法

tabs.connect()
在运行于该标签的任何 content scripts  和该扩展的后台脚本(或者其他的比如弹出菜单脚本或者设置页面脚本)间创建一个消息连接。
tabs.create()
创建一个新标签。
tabs.captureVisibleTab()
创意一个数据统一资源标识符解码在规定窗口中当前活动标签的可视区域重的一个图片。
tabs.detectLanguage()
检查在一个标签中的主要语言。
tabs.duplicate()
复制一个标签
tabs.executeScript()
向一个页面注入脚本。
tabs.get()
取回制定标签的详细信息。
tabs.getAllInWindow()
获取指定窗口所有标签的详细信息。
tabs.getCurrent()
返回一个 tabs.Tab 对象包含了该脚本当前的宿主标签的信息。
tabs.getSelected()
获取在指定窗口被选定的标签。
tabs.getZoom()
获取制定标签的缩放系数。
tabs.getZoomSettings()
获取指定标签的缩放设置。
tabs.highlight()
高亮显示一个或多个标签。
tabs.insertCSS()
向一个页面注入CSS。
tabs.removeCSS()
移除之前调用tabs.insertCSS() 注入的一个css。
tabs.move()
移动一个或多个标签页到同一窗口的一个新的位置或是到不同窗口。
tabs.query()
获取所有包含指定属性的标签,如果没有属性则获取所有标签。
tabs.reload()
重在一个标签,可选的可以绕过本地缓存。
tabs.remove()
关闭一个或多个标签。
tabs.sendMessage()
向一个指定标签的content script 发送单个消息。
tabs.sendRequest()
向一个指定标签的content script 发送一个单一请求。 过时: 请使用 tabs.sendMessage() 替代。
tabs.setZoom()
缩放指定标签。
tabs.setZoomSettings()
为一个制定标签设置缩放选项。
tabs.update()
导航一个标签到新的地址,或是修改其它的属性。

Events

tabs.onActivated
当窗口活动标签改变时触发,注意当该消息触发时,标签地址可能没有被设置。
tabs.onActiveChanged
 已过时: 请使用 tabs.onActivated 代替。
tabs.onAttached
当一个标签被附加到一个窗口时触发,因为他可能在窗口间移动。
tabs.onCreated
当一个标签被创建时触发,注意当该事件触发时可能没有设置地址。
tabs.onDetached
当一个标签脱离一个窗口时被触发。
tabs.onHighlightChanged
过时: 请使用 tabs.onHighlighted 代替。
tabs.onHighlighted
当一个标签被高亮显示或是被选中时触发。
tabs.onMoved
当一个标签在一个窗口内移动时被触发。
tabs.onRemoved
当一个标签关闭时被处罚。
tabs.onReplaced
当一个标签因为预载取代另一个标签时被触发。
tabs.onSelectionChanged
 以过时: 请使用 tabs.onActivated 代替。
tabs.onUpdated
当一个标签被更新时触发。
tabs.onZoomChange
当一个标签被缩放时触发

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
MutedInfoChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android No support No
MutedInfoReasonChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android No support No
PageSettingsChrome No support NoEdge No support NoFirefox Full support 56Opera No support NoFirefox Android No support No
TAB_ID_NONEChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
TabStatusChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
WindowTypeChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
ZoomSettingsChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
ZoomSettingsModeChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
ZoomSettingsScopeChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
captureTabChrome No support NoEdge No support NoFirefox Full support 59Opera No support NoFirefox Android Full support 59
captureVisibleTabChrome Full support Yes
Notes
Full support Yes
Notes
Notes The default file format is 'jpeg'.
Edge Full support 15Firefox Full support 47Opera Full support Yes
Notes
Full support Yes
Notes
Notes The default file format is 'jpeg'.
Firefox Android Full support 54
connectChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 54
createChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
detectLanguageChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android No support No
discardChrome Full support 54
Notes
Full support 54
Notes
Notes Only accepts a single tab ID as a parameter, not an array.
Notes The tab ID argument is optional: if it is omitted, the browser discards the least important tab.
Notes The callback is passed a Tab object representing the tab that was discarded.
Notes Tabs whose document contains a beforeunload listener that displays a prompt will be discarded.
Edge Full support 14Firefox Full support 58Opera Full support Yes
Notes
Full support Yes
Notes
Notes Only accepts a single tab ID as a parameter, not an array.
Notes The tab ID argument is optional: if it is omitted, the browser discards the least important tab.
Notes The callback is passed a Tab object representing the tab that was discarded.
Notes Tabs whose document contains a beforeunload listener that displays a prompt will be discarded.
Firefox Android No support No
duplicateChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 54
executeScriptChrome Full support Yes
Notes
Full support Yes
Notes
Notes Extensions can't inject scripts into their own pages using this API.
Edge Full support 14Firefox Full support 43
Notes
Full support 43
Notes
Notes Before version 50, Firefox would pass a single result value into its callback rather than an array, unless 'allFrames' had been set.
Opera Full support Yes
Notes
Full support Yes
Notes
Notes Extensions can't inject scripts into their own pages using this API.
Firefox Android Full support 54
getChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
getAllInWindow
DeprecatedNon-standard
Chrome Full support YesEdge No support NoFirefox No support NoOpera No support NoFirefox Android No support No
getCurrentChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
getSelected
DeprecatedNon-standard
Chrome Full support YesEdge No support NoFirefox No support NoOpera No support NoFirefox Android No support No
getZoomChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
getZoomSettingsChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
hide
ExperimentalNon-standard
Chrome No support NoEdge No support NoFirefox Full support 61
Full support 61
No support 59 — 61
Disabled
Disabled From version 59 until version 61 (exclusive): this feature is behind the extensions.webextensions.tabhide.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera No support NoFirefox Android No support No
highlightChrome Full support YesEdge No support NoFirefox No support NoOpera No support NoFirefox Android No support No
insertCSSChrome Full support YesEdge Full support 14Firefox Full support 47Opera Full support YesFirefox Android Full support 54
moveChrome Full support YesEdge No support NoFirefox Full support 46Opera Full support YesFirefox Android No support No
onActivatedChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
onActiveChanged
DeprecatedNon-standard
Chrome Full support YesEdge No support NoFirefox No support NoOpera No support NoFirefox Android No support No
onAttachedChrome Full support YesEdge Full support 15Firefox Full support 45Opera Full support YesFirefox Android Full support 54
onCreatedChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
onDetachedChrome Full support YesEdge Full support 15Firefox Full support 45Opera Full support YesFirefox Android Full support 54
onHighlightChanged
DeprecatedNon-standard
Chrome Full support YesEdge No support NoFirefox No support NoOpera No support NoFirefox Android No support No
onHighlightedChrome Full support YesEdge No support NoFirefox Full support 63
Full support 63
No support 45 — 62
Notes
Notes Implemented as an alias for onActivated.
Opera No support NoFirefox Android Full support 54
Notes
Full support 54
Notes
Notes Implemented as an alias for onActivated.
onMovedChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
onRemovedChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
onReplacedChrome Full support YesEdge No support NoFirefox No support NoOpera Full support YesFirefox Android No support No
onSelectionChanged
DeprecatedNon-standard
Chrome Full support YesEdge No support NoFirefox No support NoOpera No support NoFirefox Android No support No
onUpdatedChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
onZoomChangeChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
printChrome No support NoEdge No support NoFirefox Full support 56Opera No support NoFirefox Android No support No
printPreviewChrome No support NoEdge No support NoFirefox Full support 56Opera No support NoFirefox Android No support No
queryChrome Full support YesEdge Full support 14
Notes
Full support 14
Notes
Notes The panel, app, devtools and popup values for WindowType are not supported.
Firefox Full support 45Opera Full support YesFirefox Android Full support 54
reloadChrome Full support YesEdge Full support 17Firefox Full support 45Opera Full support YesFirefox Android Full support 54
removeChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54
removeCSSChrome No support NoEdge No support NoFirefox Full support 49Opera No support NoFirefox Android Full support 54
saveAsPDFChrome No support NoEdge No support NoFirefox Full support 56
Notes
Full support 56
Notes
Notes This function does not work on macOS.
Opera No support NoFirefox Android No support No
sendMessageChrome Full support YesEdge Full support 14
Notes
Full support 14
Notes
Notes No response is sent after the receiving tab is refreshed if there is no `runtime.onMessage` listener.
Firefox Full support 45Opera Full support YesFirefox Android Full support 54
sendRequest
DeprecatedNon-standard
Chrome Full support YesEdge No support NoFirefox No support NoOpera No support NoFirefox Android No support No
setZoomChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android No support No
setZoomSettingsChrome Full support YesEdge No support NoFirefox No support NoOpera Full support YesFirefox Android No support No
show
ExperimentalNon-standard
Chrome No support NoEdge No support NoFirefox Full support 61
Full support 61
No support 59 — 61
Disabled
Disabled From version 59 until version 61 (exclusive): this feature is behind the extensions.webextensions.tabhide.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera No support NoFirefox Android No support No
toggleReaderModeChrome No support NoEdge No support NoFirefox Full support 58Opera No support NoFirefox Android No support No
updateChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 54

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

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.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

文档标签和贡献者

此页面的贡献者: ivysrono, Hypophrenia, wbamberg
最后编辑者: ivysrono,