我有一个与下面类似的设置,我希望能够通过运行时消息传递来发送一个函数,但是它将变成空值。
为什么会发生这种情况,我该怎么办才能解决这个问题?
console.log("background");
chrome.runtime.onMessage.addListener(function(data){
console.log(data);
});
console.log("content");
function test(){
console.log("test")
}
test2 = function(){
console.log("test2")
}
chrome.extension.sendMessage({funcs:[test, test2], func:test, func2:test2}, function(background_response){
})
{
"name": "Functions won't send!",
"version": "1.0",
"description": "Functions won't send!",
"permissions": [
"tabs"
],
"background": {
"scripts": [
"background.js"
],
"persistent": true
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": [
"content.js"
],
"run_at": "document_start"
}
],
"manifest_version": 2
}