tabs.getCurrent()

获取一个包含当前脚本所在标签页信息的 tabs.Tab 对象。

备注: 此函数只在浏览器标签页的上下文中有用,例如选项页面

如果在后台脚本或弹出窗口中调用该函数,它将返回 undefined

这是一个返回 Promise 的异步函数。

语法

js
const gettingCurrent = browser.tabs.getCurrent()

参数

无。

返回值

一个 Promise,其会兑现一个包含当前标签页信息的 tabs.Tab 对象。如果发生任何错误,promise 将会以错误信息拒绝。

示例

获取当前标签页的信息:

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 GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
getCurrent

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

备注: 此 API 基于 Chromium 的 chrome.tabs API。本文档来自 Chromium 代码中的 tabs.json