From 4aa25c2995538a4c68f140be239e5f95167f0513 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Thu, 27 May 2021 17:30:03 +0000 Subject: [PATCH] Bug 1713120 - Fix TypeError: n.getAttribute is not a function in ext-pageAction.js r=rpl The reported error happens because `.parentNode` can be a document, which doesn't implement the Element interface. Using `.parentElement` solves this issue. And while I'm fixing this: move the logic behind the menu ID check, so that the logic is not unnecessarily run for non-pageAction contextmenus. Differential Revision: https://phabricator.services.mozilla.com/D116138 --- .../components/extensions/parent/ext-pageAction.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/browser/components/extensions/parent/ext-pageAction.js b/browser/components/extensions/parent/ext-pageAction.js index 235c012b9e6c..7f3d99815dbb 100644 --- a/browser/components/extensions/parent/ext-pageAction.js +++ b/browser/components/extensions/parent/ext-pageAction.js @@ -252,14 +252,17 @@ this.pageAction = class extends ExtensionAPI { case "popupshowing": const menu = event.target; const trigger = menu.triggerNode; - let actionId = trigger?.getAttribute("actionid"); - if (trigger && !actionId) { + const getActionId = () => { + let actionId = trigger.getAttribute("actionid"); + if (actionId) { + return actionId; + } // When a page action is clicked, triggerNode will be an ancestor of // a node corresponding to an action. triggerNode will be the page // action node itself when a page action is selected with the // keyboard. That's because the semantic meaning of page action is on // an hbox that contains an . - for (let n = trigger.parentNode; n && !actionId; n = n.parentNode) { + for (let n = trigger; n && !actionId; n = n.parentElement) { if (n.id == "page-action-buttons" || n.localName == "panelview") { // We reached the page-action-buttons or panelview container. // Stop looking; no action was found. @@ -267,11 +270,12 @@ this.pageAction = class extends ExtensionAPI { } actionId = n.getAttribute("actionid"); } - } + return actionId; + }; if ( menu.id === "pageActionContextMenu" && trigger && - actionId === this.browserPageAction.id && + getActionId() === this.browserPageAction.id && !this.browserPageAction.getDisabled(trigger.ownerGlobal) ) { global.actionContextMenu({