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
This commit is contained in:
Rob Wu 2021-05-27 17:30:03 +00:00
Родитель 179d3960ce
Коммит 4aa25c2995
1 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -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 <image>.
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({