Firefox键盘快捷键是否只在浏览器启动时激活?

Are Firefox Keyboard Shortcuts only activated at browser start-up?

本文关键字:启动 激活 浏览器 键盘 快捷键 是否 Firefox      更新时间:2023-09-26

在Firefox插件中,在禁用和启用该插件后,键盘快捷键会消失。控制台不记录任何错误(try{}catch{})。

检查Browser Toolbox时,key被插入回<keyset id="mainKeyset">,但快捷方式不起作用,修饰符没有出现在上下文菜单上。

所以问题是,我错过了什么或键盘快捷键只在浏览器启动时激活?

我发现问题了…

而(创建/插入)keyset &context menuitem在浏览器启动时并不重要,它在重新启用无重启插件时确实重要。将keyset创建/插入移到menuitem创建/插入之前,解决了这个问题。

每个请求

:
首先我有/* ContextMenu Menuitem */部分,然后/* keyset */部分。通过把/* keyset */section first, the keyset was created & inserted before inserting the contextmenu 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