action.isEnabled()
Returns true if the browser action is enabled. Returns the global status if the details parameter is omitted or empty, or all its properties are empty.
Returns true if the browser action is enabled. Returns the global status if the details parameter is omitted or empty, or all its properties are empty.
[!NOTE] This API is available in Manifest V3 or higher.
Syntax
let gettingIsEnabled = browser.action.isEnabled(
details // optional object or integer
)
Parameters
details-
:
integerorobject. As anintegerit defines the ID of a tab to check. As anobjectit contains:tabId- :
integer. ID of a tab to check. windowId- :
integer. ID of a window to check.
If
windowIdandtabIdare supplied, the function fails.
[!NOTE] Chrome only support the
detailsas aninteger, the ID of a tab to check.
Return value
A Promise fulfilled with true if the extension's browser action is enabled, and false otherwise.
Examples
Check the global state:
browser.action.isEnabled({}).then((result) => {
console.log(result);
});
Check the state of the active tab:
async function enabledInActiveTab() {
let tabs = await browser.tabs.query({
currentWindow: true,
active: true,
});
let enabled = await browser.action.isEnabled({
tabId: tabs[0].id,
});
console.log(enabled);
}