Google chrome extension Chrome扩展-结果始终为空

Google chrome extension Chrome扩展-结果始终为空,google-chrome-extension,Google Chrome Extension,我刚刚开始玩Chrome扩展 在my content.js中,我有以下内容 chrome.runtime.sendMessage("", function(response){ //some logic }); 在background.js中 chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { sendResponse(someFunction); return tru

我刚刚开始玩Chrome扩展

在my content.js中,我有以下内容

chrome.runtime.sendMessage("", function(response){
    //some logic
});
在background.js中

chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
   sendResponse(someFunction);
   return true;
});

function someFunction(para) {
    //logic
}
问题是,content.js中的
响应始终未定义。。。这个站点上类似的帖子通常是由于异步调用,比如ajax,但是我没有异步做任何事情,我返回的是true,根据文档返回的方法。。。我只能假设我的逻辑有些倒退


我做错了什么?

您不能发送函数(“someFunction”)作为响应。响应对象必须可序列化。

不能将函数(“someFunction”)作为响应发送。响应对象必须是可序列化的。

删除括号-它只是:
AddToBody parent
。或者像这样使用
Call
calladdtobody(parent)
删除括号-它只是:
AddToBody parent
。或者像这样使用
Call
calladdtobody(parent)
这是answr。我现在明白了。我无法返回函数。。。我本想用回复作为回电,但这似乎不可能。我不确定我是否遵循了你的想法。您的函数已在回调。你为什么需要回电话?这就是您使用消息传递的原因。这是ANWR。我现在明白了。我无法返回函数。。。我本想用回复作为回电,但这似乎不可能。我不确定我是否遵循了你的想法。您的函数已在回调。你为什么需要回电话?这就是您使用消息传递的原因。