我已经编写了一个示例扩展,只需在背景页面中为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 });
});
答案 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 });
});