您好我正在尝试从popup.js执行background.js中的函数,但chrome.extension.getBackgroundPage();
始终返回null:
popup.js
var bkg = chrome.extension.getBackgroundPage();
bkg.test(function(result) {
alert(result);
});
background.js
function test(func) {
alert('test');
func.apply(this, ['bar']);
}
和我的清单:
{
"name": "Get pages source",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"version": "1.0",
"manifest_version": 2,
"description": "Get pages source from a popup",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": ["tabs", "<all_urls>",
"downloads","http://*/*", "https://*/*","background"
]
}
有人知道为什么吗?