【问题标题】:"commands" not calling commands.onCommand listener when shortcut keys pressed [duplicate]按下快捷键时,“命令”不调用commands.onCommand侦听器[重复]
【发布时间】:2018-02-21 12:58:34
【问题描述】:

我正在尝试使用 Google 的命令 API 将热键添加到我的扩展程序,但我无法将任何内容打印到控制台。所有 Stack Overflow 的回答都说要检查扩展页面右下角的热键页面。我已经检查过了,并且我的热键设置为应有的状态。

Manifest.json

{
    "manifest_version": 2,
    ...
    "background": {
        "scripts": ["background.js"]
    },

    "commands": {
        "move_tab_up": {
            "suggested_key": {
                "default": "Ctrl+Shift+K"
        },
        "description": "move tab up one window"
    }
}

Background.js

chrome.commands.onCommand.addListener(function(command) {
    console.log("I am a stupid script.", command);
});

【问题讨论】:

标签: javascript google-chrome google-chrome-extension


【解决方案1】:

原来我只是没有检查正确的控制台。我的扩展程序在后台页面中运行,因此我必须专门使用后台页面控制台。

【讨论】:

    猜你喜欢
    • 2012-10-18
    • 2020-01-08
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 2011-05-02
    • 2011-04-08
    • 1970-01-01
    相关资源
    最近更新 更多