【问题标题】:Chrome extension initiate browser_action popup from background scriptsChrome 扩展从后台脚本启动 browser_action 弹出窗口
【发布时间】:2014-08-02 05:54:36
【问题描述】:

我正在尝试显示从触发器到快捷键(如(ctrl+shift+U))的 chrome 扩展弹出窗口。

清单 Json:

 "commands": {

    "generate_link": {
      "suggested_key": {
        "default": "Ctrl+K",
        "mac": "Command+K"
      },
      "description": "Builds link copy to extension."
    },


    "show-interface": {
      "suggested_key": {
        "default": "Ctrl+Shift+K",
        "mac": "Command+Shift+K"
      },
      "description": "Show builder interface2."
    }

后台脚本:

chrome.commands.onCommand.addListener(function(command) {

    chrome.tabs.update({}, function(tab) {
    if (command == 'generate_link')
    {
       //need to show extension window with some info about the current tab
        getLink(tablink)
    }
    else if (command == 'show-interface')
          alert('show-interface');
  });
});

是否有任何函数可以触发我们单击 browser_action 图标时发生的相同任务。

这可能很简单,但对于 chrome 扩展和术语来说是新的,没有找到解决此类问题的任何好的参考。

【问题讨论】:

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


    【解决方案1】:

    尝试添加"global": true。这是 chrome 命令的参考:https://developer.chrome.com/extensions/commands

    【讨论】:

    • 命令正在运行,我可以运行我的脚本。我的问题是,我们是否可以选择从后台脚本打开扩展弹出窗口。
    【解决方案2】:

    其实找到了,这个in command section是用来触发chrome扩展从快捷方式打开的。

    "_execute_browser_action": {
          "suggested_key": {
            "default": "Ctrl+Shift+K",
            "mac": "Command+Shift+K"
          }
    

    这是对术语的误解。 谢谢。

    【讨论】:

      猜你喜欢
      • 2013-05-10
      • 2017-02-15
      • 1970-01-01
      • 2023-01-06
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      • 2017-12-24
      相关资源
      最近更新 更多