【发布时间】:2022-11-29 06:48:48
【问题描述】:
我想在我的后台服务工作者和我的内容脚本之间进行通信,但即使我添加了回调,它也不会触发
内容.js
setInterval(function () {
chrome.runtime.sendMessage({
message: "is-playing", callback: function (counter) {
console.log("Callback")
console.log(counter);
}
})
}, 2000);`
背景.js
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
sendResponse({ counter: request.counter + 1 });
console.log("send response")
console.log(chrome.runtime.lastError)
});
我试图通过检查错误chrome.runtime.lastError但即使这样也行不通
【问题讨论】:
标签: javascript google-chrome-extension