我发现了问题……
虽然keyset 和context menuitem 的(创建/插入)顺序在浏览器启动时并不重要,但在重新启用无重启插件时却很重要。将keyset创建/插入移到menuitem创建/插入之前,解决了问题。
根据要求:
起初我先有/* ContextMenu Menuitem */ 部分,然后是/* keyset */ 部分。
通过放置 /* 键集 */section first, thekeysetwas created & inserted before inserting thecontextmenu menutiem` 并解决了问题。
let contextMenu = window.document.getElementById('contentAreaContextMenu');
/* keyset */
let mainKeyset = window.document.getElementById('mainKeyset'); // parent -> #main-window
let keyset = window.document.createElement('keyset');
//keyset.setAttribute('id', this.id + '-keyset'); // if you need to have an id
let key = window.document.createElement('key');
key.setAttribute('id', this.id + '-key');
key.setAttribute('modifiers', 'accel shift');
key.setAttribute('keycode', 'VK_F2');
key.setAttribute('oncommand', 'void(0);');
key.addEventListener('command', this, false);
keyset.appendChild(key); // add the key to keyset
mainKeyset.parentNode.appendChild(keyset); // add the keyset to the window.document
/* ContextMenu Menuitem */
let docfrag = window.document.createDocumentFragment(); // temporary container
let menuseparator = window.document.createElement('menuseparator');
let menuitem = window.document.createElement('menuitem');
//menuitem.setAttribute('id', this.id + '-menuitem'); // if you need to have an id
menuitem.setAttribute('class', 'menuitem-iconic');
menuitem.setAttribute('label', this.menuitemLabel);
//menuitem.setAttribute('hidden', 'true'); // starts from hidden
menuitem.setAttribute('accesskey', 'R');
menuitem.setAttribute('key', this.id + '-key');
//menuitem.style.listStyleImage = 'url(chrome://' + this.id + '/skin/icon16.png)'; // this also works
menuitem.setAttribute('style', 'list-style-image: url(chrome://' + this.id + '/skin/icon16.png);');
menuitem.addEventListener('command', this, false);
docfrag.appendChild(menuseparator); // adding the menuseparator to temporary container
docfrag.appendChild(menuitem); // add the menuitem to temporary container
contextMenu.appendChild(docfrag); // add the temporary container to the contextMenu