Approach No. 2
Concern No. 1
There seems to be no way to access the contents of the iframe, because the policies are cross-origin. And this access - I need to assign handlers to the input field, where the user enters the answer, I need to remember who steals the focus from the input field of the answer, to give it returns after the answer to the question, etc. etc. etc.
Yes, you get access to the contents of the iframe (s) for the substance of the entire code of the web page, no CSP, etc.
The content of the script that inserts the iframe.
I suggest this is the best approach, you can inject the script into dynamically generated frames, as shown here, and get the contents
Implementation example
manifest.json
{ "name": "Iframe", "description": "", "version": "1", "manifest_version": 2, "content_scripts": [ { "matches": [ "<all_urls>" ], "js": [ "myscript.js" ], "run_at": "document_end" }, { "matches": [ "<all_urls>" ], "js": [ "anotherscript.js" ], "all_frames": true } ], "permissions": [ "<all_urls>" ] }
myscript.js
var iframe = document.createElement("iframe"); iframe.setAttribute("src", "https://www.facebook.com/plugins/like.php?href=http://allofrgb.blogspot.in/"); iframe.setAttribute("style", "border:none; width:150px; height:30px"); iframe.setAttribute("scrolling", "no"); iframe.setAttribute("frameborder", "0"); document.body.appendChild(iframe);
anotherscript.js
iframes = document.getElementsByTagName("iframe"); for (iframe in iframes){ console.log(iframes[iframe].src); } console.log("In another Script");
If you look at messages recorded in the console, you see that messages are logged twice ( document log + iframe log + [any number of optional iframes in pages]* )
anotherscript.js , which runs during document idle states, runs in a dynamically generated iframe as soon as you can re-run the script content through chrome.tabs.executeScript () at any time.
Concern No. 2
Using Message Passing didn't work for me, and I'm not even sure if I have to get it to work, because messaging does it all excessively and forbids me to use the application as a simple web page (i.e. not as an extension) . Why even bother?
What do you want to achieve?