在以下Chrome扩展程序中,按下快捷方式时,我会收到两次键盘命令,但仅在浏览器弹出窗口打开时才会收到。 这是你如何复制它:
安装以下chrome扩展。 导航至Chrome扩展程序页面 滚动到底部,然后点击“键盘快捷键” 将扩展名的快捷方式设置为Alt + Shift + S. 在扩展页面中,单击扩展的“后台页面”链接以打开后台页面控制台。 按Alt + Shift + S. 您将看到“命令”被记录一次。 现在打开安装扩展时应该出现的浏览器弹出窗口。 按Alt + Shift + S. 转到后台页面控制台,您将看到“命令”记录两次。这是代码:
的manifest.json
{ "manifest_version": 2, "name": "Test", "version": "1.0", "background": { "scripts": ["background.js"] }, "browser_action": { "default_popup": "popup.html" }, "commands": { "command": { "suggested_key": { "default": "Alt+Shift+S" }, "description": "My command" } } }background.js
chrome.commands.onCommand.addListener(function (command) { console.log(command); });popup.html不需要存在。 为什么会这样? 我有一个黑客,我不接受命令,如果它自上一个命令以来不到50毫秒,但我不想使用黑客。
In the following Chrome extension, I receive a keyboard command twice when the shortcut is pressed, but only when the browser popup is open. Here's how you replicate it:
Install the following chrome extension. Navigate to the Chrome extensions page Scroll to the bottom and click "Keyboard shortcuts" Set the shortcut for the extension to Alt+Shift+S In the extensions page, click the "background page" link for the extension to open the background page console. Hit Alt+Shift+S. You'll see "command" being logged once. Now open the browser popup that should have appeared when the extension was installed. Hit Alt+Shift+S. Go to the background page console and you'll see "command" logged twice.Here is the code:
manifest.json
{ "manifest_version": 2, "name": "Test", "version": "1.0", "background": { "scripts": ["background.js"] }, "browser_action": { "default_popup": "popup.html" }, "commands": { "command": { "suggested_key": { "default": "Alt+Shift+S" }, "description": "My command" } } }background.js
chrome.commands.onCommand.addListener(function (command) { console.log(command); });popup.html does not need to exist. Why is this happening? I have a hack where I don't accept commands if it's been less than 50 ms since the last command, but I don't want to use a hack.
最满意答案
看起来这是Chrome的GTK版本的一个错误。 您可以在此处查看我提交的错误报告: https : //code.google.com/p/chromium/issues/detail?id = 355559
这不会在GTK构建中修复,因为Chrome无论如何都要切换到Aura。
It looks like this is a bug with the GTK build of Chrome. You can see the bug report I filed here: https://code.google.com/p/chromium/issues/detail?id=355559
This will not be fixed in the GTK build since Chrome is switching to Aura anyway.
更多推荐
发布评论