Bug 1963616 - Don't try adding action context menus without permission r=willdurand
When an extension does not have the contextMenus or menus permission, it is not possible to have extension-defined context menus on an extension's action button. The actionContextMenu() call would never add menu items in this case. As the bug report shows, trying to call actionContextMenu() can throw an error when the ext-menus.js module has not been loaded. To avoid this error, verify that the extension has the permission to add menus. Because ext-menus.js is declared with `"events": ["startup"]`, the module is guaranteed to be loaded if an extension has the permissions. Differential Revision: https://phabricator.services.mozilla.com/D248154
This commit is contained in:
@@ -726,11 +726,16 @@ this.browserAction = class extends ExtensionAPIPersistent {
|
||||
const action =
|
||||
this.extension.manifestVersion < 3 ? "onBrowserAction" : "onAction";
|
||||
|
||||
global.actionContextMenu({
|
||||
extension: this.extension,
|
||||
[action]: true,
|
||||
menu,
|
||||
});
|
||||
if (
|
||||
this.extension.hasPermission("contextMenus") ||
|
||||
this.extension.hasPermission("menus")
|
||||
) {
|
||||
global.actionContextMenu({
|
||||
extension: this.extension,
|
||||
[action]: true,
|
||||
menu,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user