選択したタブに挿入されたスクリプトに Chrome 拡張機能 (popup.html) からメッセージを送信する際に問題が発生しています。popup.html のコードは次のとおりです。
alert("sending MSG");
chrome.tabs.sendMessage(null, {greeting: "hello"}, function(response) {
console.log(response.farewell);
});
alert("MSG send");
問題は、"sending MSG" アラートのみが表示され、2 番目のアラート "MSG sent" が表示されないことです。コードをブロックしているようです。
この関数を使用する場合でも:
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendMessage(tab.id, {greeting: "hello"}, function(response) {
console.log(response.farewell); alert("MSG sent _ in");
});
});
alert("MSG send _ out");
ここでも同じ問題が発生します。「MSG send _ out」は表示されますが、「MSG send _ in」は表示されません。誰かがこの問題について何か考えを持っているなら、私に知らせてください。