- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在运行具有以下内容的 Chrome 扩展程序时,我收到错误“未捕获的类型错误:无法读取未定义的属性‘onCommand’”:
list .json:
{
"name": "Test",
"description": "Key command test.",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [ {
"js": ["background_test.js"],
"matches": [ "http://*/*", "https://*/*"]
}],
"commands": {
"Ctrl+M": {
"suggested_key": {
"default": "Ctrl+M",
"mac": "Command+M"
},
"description": "Ctrl+M."
},
"Ctrl-L": {
"suggested_key": {
"default": "Ctrl+L",
"mac": "Command+L"
},
"description": "Ctrl+L"
}
}
}
background_test.js:
chrome.commands.onCommand.addListener(function(command) {
if (command === "Ctrl+L") {
console.log("Ctrl-L successful.");
}
else if (command === "Ctrl+M") {
console.log("Ctrl+M successful.");
}
});
它应该做的就是在按下 Ctrl-M 时打印“Ctrl-M 成功”,在按下 Ctrl-L 时打印“Ctrl-L 成功”。
This question似乎包含这个问题的答案,但我不明白答案,也无法添加评论来要求进一步解释,因为我没有足够的声誉:“是你的 onCommand
听众在内容脚本中定义?它可能在那里不起作用;您需要将它包含在背景页面或操作弹出窗口中。”我应该如何在后台页面中定义onCommand
?我在任何地方都找不到任何关于它的信息,无论是在 API 中还是通过一般的谷歌搜索。
我还尝试重新加载扩展并按照建议手动输入键盘快捷键 here ,无济于事。
我在这里错过了什么?
最佳答案
content_scripts(如 https://developer.chrome.com/extensions/content_scripts 中所定义)无法使用 chrome.commands。
要使其正常工作,您可以将 list 更改为:
{
"name": "Test",
"description": "Key command test.",
"version": "1.0",
"manifest_version": 2,
"permissions": [
"<all_urls>"
],
"background":
{
"scripts": ["background_test.js"],
"persistent": true
},
"commands": {
"Ctrl+M": {
"suggested_key": {
"default": "Ctrl+M",
"mac": "Command+M"
},
"description": "Ctrl+M."
},
"Ctrl+L": {
"suggested_key": {
"default": "Ctrl+L",
"mac": "Command+L"
},
"description": "Ctrl+L"
}
}
}
此外,Ctlr+L 不起作用(至少在 Mac 上),因为 chrome 已经使用它来将焦点放在地址栏上。
该元素将在扩展的控制台中可见。要查看它,请打开 chrome://extensions/并单击 Inspect views: background page of your extension。
关于javascript - 'onCommand' 的 Chrome 扩展错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24226994/
我的问题是我有一个简单的 Minecraft 插件,我只想让它执行一个命令。我以前做过命令,所以步骤对我来说很清楚。我的plugin.yml 设置正确(服务器检测我添加的命令并显示它的帮助页面等),并
我有一个页面,其中列出了数据网格中的一堆项目。 每个项目都有一个对应的删除链接按钮,用于从列表中删除该项目。在我的事件处理程序中——项目被删除的地方——我检查该项目是否是列表中的最后一项。如果它是最后
我正在为 Minecraft 创建一个简单的插件,它可以切换命令并为目标玩家提供唯一的 UUID。然而,public boolean onCommand 方法声明它从未被使用过。 主类(Freeze.
我在对我的项目 (ASP.NET Web Forms) 进行一些研究时遇到了 2 种看起来相似的事件类型,OnCommand 和 OnClick。我已通读 MSDN 页面,但仍不清楚它们之间的区别。
在运行具有以下内容的 Chrome 扩展程序时,我收到错误“未捕获的类型错误:无法读取未定义的属性‘onCommand’”: list .json: { "name": "Test", "de
我正在尝试做一些看起来相当简单的事情。我有一个带有多个 LinkButtons 的用户控件。每个 LinkButton 都有 OnCommand、CommandName 和 CommandAr
为什么下面的代码会导致以下错误: System.Web.UI.WebControls.Button.OnCommand(System.Web.UI.WebControls.CommandEventAr
本文整理了Java中com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster.onCommand()方法的一些代码示例,展示了ZclOnOffClus
我正在尝试找到在 macOS 上将 NSMenuItem 与 SwiftUI onCommand 连接的最佳解决方案。 目前我正在做以下事情: 在 AppDelegate 中,我创建了一个虚拟函数,以
我已经阅读了数十篇有关此问题的帖子并尝试了所有这些,但没有运气,我不确定我错过了什么,这是 gridview 代码:
所以我现在正在尝试制作一个 Minecraft 插件,并且我已经制作了我的代码,其中大部分都是完美的,但是由于某种原因,一旦编写完成,我就会从 Eclipse 收到错误消息(标题) . 代码在这里找到
我试图从 bootstrap.js 文件调用 changePassword() 方法,但我不知道如何.. Bootstrap.js 位于项目文件夹的根目录,options.xul 位于 ./chrom
我有以下代码,在我正在开发的新扩展中: (.addListener js/chrome.alarms.onAlarm (fn [alarm] (.log js/console alarm))) (.a
我是一名优秀的程序员,十分优秀!