menus.onHidden

Fired when the browser stops displaying a menu: for example because the user clicked outside it or selected an item.

It is only triggered for menus that can be manipulated using the menus API itself: this includes the context menu, the browser's tools menu, and the bookmarks menu.

This is most likely to be used in combination with the menus.onShown and menus.refresh() APIs: an extension can update the menu when it is shown, then undo the changes when it is hidden.

Firefox makes this event available via the contextMenus namespace as well as the menus namespace.

Syntax

js
browser.menus.onHidden.addListener(listener)
browser.menus.onHidden.removeListener(listener)
browser.menus.onHidden.hasListener(listener)

Events have three functions:

addListener(listener)

Adds a listener to this event.

removeListener(listener)

Stop listening to this event. The listener argument is the listener to remove.

hasListener(listener)

Check whether listener is registered for this event. Returns true if it is listening, false otherwise.

addListener syntax

Parameters

listener

The function called when this event occurs. The function is passed no parameters.

Examples

This example just logs a message whenever a menu is hidden:

js
function hidden() {
  console.log("Menu was hidden");
}

browser.menus.onHidden.addListener(hidden);

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
onHidden
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 60 (Release date: 2018-05-09)
altname
altname Alternate name: contextMenus.onHidden
Firefox – Full support
Firefox 60 (Release date: 2018-05-09)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

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

Full support
Full support
No support
No support
Uses a non-standard name
Has more compatibility info.