gpt4 book ai didi

google-chrome-extension - «Invalid value» 错误,而 chrome.commands 中的括号

转载 作者:行者123 更新时间:2023-12-04 22:05:36 29 4
gpt4 key购买 nike

我需要热键 Alt + ]Alt + [。我有 manifest.json 像:

{
...
"commands": {
"nextTrack": {
"suggested_key": {
"default": "Alt+]"
},
"description": "Next track"
},
"previousTrack": {
"suggested_key": {
"default": "Alt+["
},
"description": "Previous track"
},
"toggle": {
"suggested_key": {
"default": "Alt+P"
},
"description": "Toggle pause"
}
},
...
}

当我启用我的扩展时,我得到:

Could not load extension from '~/project'. 
Invalid value for 'commands[1].default': Alt+].

热键的使用方法是什么?

最佳答案

只有大写字母 (A-Z) 和数字 (0-9) 是有效值,您可以查看 source code chrome.commands API。

如果你想使用其他字符,在每个页面中注入(inject)一个内容脚本,绑定(bind)一个keydown事件:

document.addEventListener('keydown', function(event) {
if (!event.ctrlKey && event.altKey && event.which === 80/*P*/) {
// Dispatch a custom message, handled by your extension
chrome.runtime.sendMessage('Alt+P');
}
}, true); // <-- True is important

这种方法的缺点

  • 键盘焦点必须位于激活内容脚本的页面内。如果您在开发人员工具、多功能栏等中,快捷方式将失败。
  • 即使您使用 <all_urls>作为match pattern , 它不适用于非 http(s)/文件/ftp(s) 方案,如 chrome: , data: , chrome-extension: , about:或 Chrome 网上应用店。
  • 您可能会在检测 [ 时遇到问题字符,如果键盘布局不支持它,或者使用不同的键码。
  • 没有对自定义此快捷方式的内置支持(作为用户,请访问 chrome://extensions/ ,滚动到底部并单击“配置命令”以更改扩展程序的快捷方式)。

我建议选择不同的快捷方式,或更改扩展程序的控制方式(例如,通过 page/browser action 弹出窗口)。

关于google-chrome-extension - «Invalid value» 错误,而 chrome.commands 中的括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16034279/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com