sendRequest/onRequest の代わりに新しい API sendMessage/onMessage を使用してメッセージを送信すると、JS コンソールで次のエラーが発生します。Port error: Could not establish connection. Receiving end does not exist.
古いAPIで動作していたので、それが来るのか理解できません。
ここにいくつかのサンプルがあります:
//content.js
chrome.extension.sendMessage({index: number}, function(response) {
console.log("test", response.data);
});
//background.js
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
// From content script.
if (sender.tab) {
//stuff
}
sendResponse({who: "me",data: "tata"});
});
何か案は ?どうも