docs.rodeo

MDN Web Docs mirror

browserAction.onClicked

{{AddonSidebar}} 

Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.

To define a right-click action, use the contextMenus API with the “browser_action” context type.

Syntax

browser.browserAction.onClicked.addListener(listener)
browser.browserAction.onClicked.removeListener(listener)
browser.browserAction.onClicked.hasListener(listener)

Events have three functions:

addListener syntax

Parameters

Browser compatibility

{{Compat}} 

Examples

When the user clicks the browser action icon this code turns it off for the active tab and logs the tab’s URL:

browser.browserAction.onClicked.addListener((tab) => {
  // disable the browser action for the tab
  browser.browserAction.disable(tab.id);
  // requires the "tabs" or "activeTab" permission, or host permissions for the URL
  console.log(tab.url);
});

{{WebExtExamples}} 

[!NOTE] This API is based on Chromium’s chrome.browserAction API. This documentation is derived from browser_action.json in the Chromium code.

In this article

View on MDN