简体   繁体   English

Chrome扩展键盘命令在弹出窗口打开时触发两次

[英]Chrome extension keyboard command firing twice when popup is open

In the following Chrome extension, I receive a keyboard command twice when the shortcut is pressed, but only when the browser popup is open. 在以下Chrome扩展程序中,按下快捷键时两次(但仅当浏览器弹出窗口打开时)我收到两次键盘命令。 Here's how you replicate it: 复制方式如下:

  1. Install the following chrome extension. 安装以下chrome扩展程序。
  2. Navigate to the Chrome extensions page 导航至Chrome扩展程序页面
  3. Scroll to the bottom and click "Keyboard shortcuts" 滚动到底部,然后单击“键盘快捷方式”
  4. Set the shortcut for the extension to Alt+Shift+S 将扩展的快捷方式设置为Alt + Shift + S
  5. In the extensions page, click the "background page" link for the extension to open the background page console. 在扩展页面中,单击扩展的“后台页面”链接以打开后台页面控制台。
  6. Hit Alt+Shift+S. 按Alt + Shift + S。 You'll see "command" being logged once. 您将看到“命令”被记录一次。
  7. Now open the browser popup that should have appeared when the extension was installed. 现在,打开安装扩展程序时应该出现的浏览器弹出窗口。 Hit Alt+Shift+S. 按Alt + Shift + S。
  8. Go to the background page console and you'll see "command" logged twice. 转到后台页面控制台,您将看到两次记录了“命令”。

Here is the code: 这是代码:

manifest.json 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 background.js

chrome.commands.onCommand.addListener(function (command) {
    console.log(command);
});

popup.html does not need to exist. popup.html不需要存在。 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. 我有一个hack,如果自上一个命令以来不到50 ms,我将不接受命令,但我不想使用hack。

It looks like this is a bug with the GTK build of Chrome. 看来这是Chrome的GTK版本的错误。 You can see the bug report I filed here: https://code.google.com/p/chromium/issues/detail?id=355559 您可以在此处查看我提交的错误报告: 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. 由于Chrome仍会切换到Aura,因此在GTK版本中不会解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM