Chrome扩展程序后台页面未添加新标签页?

时间:2014-02-18 14:22:52

标签: google-chrome-extension

我已经编写了一个示例扩展,只需在背景页面中为chrome添加新标签。它不起作用。我是chrome扩展的新手,你能帮我吗?

manifest.json

{
  "manifest_version": 2,

  "name": "My extension",
  "description": "Test Extension.",
  "version": "1.0",
  "background": {
   "page": "bg.html"
   },

  "permissions": [
    "history",
    "tabs"
  ],
  "browser_action": {
    "default_icon": "icon.png"
  }
}

bg.html

chrome.browserAction.onClicked.addListener(function(activeTab)
{
    var newURL = "www.google.com";
    chrome.tabs.create({ url: newURL });
});

1 个答案:

答案 0 :(得分:1)

尝试将bg.html重命名为bg.js并更改清单背景声明,如下所示

的manifest.json:

  ...
  "background": {
    "scripts": ["bg.js"]
  },
  ...

bg.js:

chrome.browserAction.onClicked.addListener(function(activeTab)
{
    var newURL = "www.google.com";
    chrome.tabs.create({ url: newURL });
});