私はメッセージを送信しても4回アラートが発生しています! 何が間違っているかわからない! マニフェストも追加しています。複数のメッセージが1つだけ送信されたときにコンテンツページに受信されますか?
background.js:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if(request.method == "123")
{
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {method: "xyz"});
})
}
});
content.js:
chrome.runtime.onMessage.addListener(
function(request) {
alert(request.method);
if (request.method == "xyz"){
alert("hello);
}
});
これはマニフェストファイル マニフェストです:あなたはあなたのmanifest.json
で"all_frames": true
を宣言している
{
"manifest_version" : 2,
"version" : "0.1.0.0",
"name" : "xyz",
"short_name": "xyz",
"permissions" : [" <all_urls>","tabs","storage","notifications","unlimitedStorage","downloads"],
"background": {
"scripts": ["background.js"]
},
"content_scripts": [{
"matches": ["<all_urls>","http://*/*","https://*/*"],
"js": [
"content.js",
],
"all_frames" : true
}],
"browser_action" : {
"default_title" : "test",
"default_popup" : "popup.html"
},
"devtools_page" : "xyz.html"
}
をチェックしてコンテンツスクリプトirst? –
私はdevtoolパネルからバックグラウンドに、そしてバックグラウンドからメッセージにメッセージを送ります! –
あなたの 'manifest.json'のようなコードを提供してください。私はiframe用のスクリプトも挿入すると思います。 –