打开浏览器操作的弹出式键盘快捷键 [英] Open Browser Action's Popup with keyboard shortcut
问题描述
我正在开发带有浏览器操作弹出窗口的Google Chrome扩展程序。当用户点击图标时,弹出窗口出现。
有没有办法用键盘快捷方式打开这个弹出窗口,如 CTRL + ?
您需要添加一个commands
manifest.json
,如 https:// developer.chrome.com/extensions/commands 的。如果您的扩展程序的弹出窗口是browser_action
弹出式窗口(由browser_action
c> manifest.json ),您需要_ execute_browser_action
命令;对于page_action
弹出窗口,您需要_ execute_page_action
命令。使用前者的示例 manifest.json
如下所示:
{
manifest_version:2,
name:示例扩展名,
description:La la la,
version:1.0,
browser_action:{
default_icon:icon.png,
default_popup:popup.html
},
commands:{
_execute_browser_action:{
suggested_key:{
default:Ctrl + Shift + E,
linux:Ctrl + Shift + K,
windows:Alt + Shift + P,
mac:Alt + Shift + P
}
}
}
}
请注意,根据文档:
< blockquote>
某些Chrome快捷方式(例如窗口管理)总是优先于Extension Command快捷方式,并且不能被覆盖。
据我所知,这些命令没有任何规范的列表;你只需要尝试不同的可能的建议快捷方式,直到你找到一个真正有用的捷径。
I'm developing a Google Chrome extension with a Browser Action Popup. When the user clicks on the icon, the popup appears.
Is there a way to open this popup with a keyboard shortcut like CTRL+something?
You need to add a "commands"
object to your manifest.json
, as shown at https://developer.chrome.com/extensions/commands. If your extension's popup is a "browser_action"
popup (indicated by a "browser_action"
key in your manifest.json
), you'll need the "_execute_browser_action"
command; for a "page_action"
popup, you'll need the "_execute_page_action"
command. An example manifest.json
using the former looks like this:
{
"manifest_version": 2,
"name": "Example Extension",
"description": "La la la",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+E",
"linux": "Ctrl+Shift+K",
"windows": "Alt+Shift+P",
"mac": "Alt+Shift+P"
}
}
}
}
Note that, per the docs:
Certain Chrome shortcuts (e.g. window management) always take priority over Extension Command shortcuts and can not be overwritten.
As far as I know, there's no canonical list of what these commands are; you just have to experiment with different possible suggested shortcuts until you find one that actually works.
这篇关于打开浏览器操作的弹出式键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!