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