Post the following code:
manifest.json
{ "manifest_version": 2, "name": "Demo", "description": "all_frames test", "version": "1.0", "background": { "scripts": ["background.js"] }, "content_scripts": [{ "matches": ["*://*/*"], "js": ["content.js"], "all_frames": true }], "permissions": [ "tabs", "*://*/*" ] }
background.js
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { var tabStatus = changeInfo.status; if (tabStatus == 'complete') { function return_msg_callback() { console.log('Got a msg from cs...') } chrome.tabs.sendMessage(tabId, { text: 'hey_cs' }, return_msg_callback); } });
content.js
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) { if (msg.text && (msg.text == 'hey_cs')) { console.log('Received a msg from bp...') sendResponse('hey_bp'); } });
Then, if I go to a site that includes multi-line iFrames with cross-starting, for example http://www.sport.es/ , you will see that all iFrames within the page receive a message from the background page, but only one of them may respond back. Is this normal behavior?
Thanks in advance for your reply.
jack source share