弹出窗口打开时,Chrome扩展程序键盘命令会触发两次(Chrome extension keyboard command firing twice when popup is open)

编程入门 行业动态 更新时间:2024-10-26 06:39:31
弹出窗口打开时,Chrome扩展程序键盘命令会触发两次(Chrome extension keyboard command firing twice when popup is open)

在以下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.

更多推荐

本文发布于:2023-08-04 15:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1418935.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两次   弹出窗口   键盘   命令   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!