javascript - Message passing between content scripts and background page -


i have injected content scripts frames. sent request background , receive response content scripts (frames have been injected).

currently can receive 1 response, how receive responses content scripts?

content script:

chrome.runtime.onmessage.addlistener(      function(request, sender, sendresponse) {      if (request.bgreq == "windowinfo")     alert("bgreq received : "+ window.location.host);  }); 

background script:

chrome.runtime.onmessage.addlistener(function(sentwords) {     if (sentwords.words == "injection") {         //send request content scritps         chrome.tabs.query({active: true, currentwindow: true}, function(tabs) {             chrome.tabs.sendmessage(tabs[0].id, {bgreq:"windowinfo"});         });     } }); 

you need explicitly send tabs in windows :

chrome.windows.getall({},function(windows){   for( var win in windows ){     chrome.tabs.getallinwindow(win.id, function(tabs) {       (var in tabs) {         chrome.tabs.sendmessage(tabs[0].id, {bgreq:"windowinfo"});       }     });   } }); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo