tabs.getCurrent()
获取一个包含当前脚本所在标签页信息的 tabs.Tab
对象。
备注: 此函数只在浏览器标签页的上下文中有用,例如选项页面。
如果在后台脚本或弹出窗口中调用该函数,它将返回 undefined
。
这是一个返回 Promise
的异步函数。
语法
js
const gettingCurrent = browser.tabs.getCurrent()
参数
无。
返回值
示例
获取当前标签页的信息:
js
function onGot(tabInfo) {
console.log(tabInfo);
}
function onError(error) {
console.log(`发生错误:${error}`);
}
const gettingCurrent = browser.tabs.getCurrent();
gettingCurrent.then(onGot, onError);
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
getCurrent |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
备注:
此 API 基于 Chromium 的 chrome.tabs
API。本文档来自 Chromium 代码中的 tabs.json
。