我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译
您也可以阅读此文章的English (US)版。

Returns true if the browser action is enabled.

This is an asynchronous function that returns a Promise.

Syntax

let gettingIsEnabled = browser.browserAction.isEnabled(
  details // object
)

Parameters

details
object. An object optionally containing the tabId or windowId to check.
tabId Optional
integer. ID of a tab to check.
windowId Optional
integer. ID of a window to check.
  • If windowId and tabId are both supplied, the function fails.
  • If windowId and tabId are both omitted, the global enabled/disabled status is returned.

Return value

A Promise that will be fulfilled with true if the extension's browser action is enabled, and false otherwise.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
isEnabledChrome No support NoEdge No support NoFirefox Full support 59Opera No support NoFirefox Android No support No
details.windowIdChrome No support NoEdge No support NoFirefox Full support 62Opera No support NoFirefox Android No support No

Legend

Full support  
Full support
No support  
No support

Examples

Check the global state:

browser.browserAction.isEnabled({}).then(result => {
  console.log(result);
});

  Check the state of the currently active tab:

async function enabledInActiveTab() {
  let tabs = await browser.tabs.query({
    currentWindow:true,
    active: true
  });
  let enabled = await browser.browserAction.isEnabled({
    tabId: tabs[0].id
  });
  console.log(enabled);
}

文档标签和贡献者

此页面的贡献者: mdnwebdocs-bot, Loirooriol, irenesmith, wbamberg
最后编辑者: mdnwebdocs-bot,