docs.rodeo

MDN Web Docs mirror

pageAction.onClicked

{{AddonSidebar}} 

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

To define a right-click action, use the {{WebExtAPIRef('contextMenus')}}  API with the “page_action” {{WebExtAPIRef('contextMenus/ContextType', 'context type', '', 'nocode')}} .

Syntax

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

Events have three functions:

addListener syntax

Parameters

Browser compatibility

{{Compat}} 

Examples

When the user clicks the page action, hide it, and navigate the active tab to “https://giphy.com/explore/cat”:

let catGifs = "https://giphy.com/explore/cat";

browser.pageAction.onClicked.addListener((tab) => {
  browser.pageAction.hide(tab.id);
  browser.tabs.update({ url: catGifs });
});

browser.pageAction.onClicked.addListener(() => {});

{{WebExtExamples}} 

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

In this article

View on MDN