I'm developing a userscript and one of its functions should be available thru an additional menu item in the native browser context menu.
So, firstly, I'm inserting into body of the page:
<menu type="context" id="mymenu">
<menuitem label="My Fancy Something"></menuitem>
</menu>
Then comes the attempt to use it, at the body element:
document.body.contextMenu = document.querySelector('#mymenu');
or
document.body.contextMenu = 'mymenu';
Either way, it fails.
console.log(document.body.contextMenu); // returns null
But, when I get to Firefox DOM inspector, and put that attribute into the body tag by hand, it actually works, and makes new context menu element appear in the document.
What am I doing wrong?