我从弹出窗口向后台进程发送消息。反馈信号对我来说不是必需的。我可以不打电话给sendResponse吗?
popup.js
window.onload = function(){
chrome.extension.sendMessage('Hi, i opened');
}
背景.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
console.log(request);
console.log(sendResponse);
// sendResponse not called
})
在 sendmessage responseCallback 可选函数developer.chrome.com/extensions/runtime.html#method-sendMessage的文档中
如果我不传输responseCallback,就在那里sendResponse。上面的代码打印出来。
function (response) {
if (port) {
port.postMessage(response);
port.destroy_();
port = null;
} else {
// We nulled out port when sending the response, and now the page
// is trying to send another response for the same request.
handleSendRequestError(isSendMessage, responseCallbackPreserved,
sourceExtensionId, targetExtensionId);
}
}
在端口的功能被删除。不调用 sendResponse 肯定是内存泄漏