I have a chrome extension, with content script 1 which programmatically creates an iframe (not same domain iframe) on the current page. I want to run a content script 2 of my chrome extension inside this new iframe (e.g. when a user clicks on something inside the iframe, a message is sent to the background script).
In my manifest.json, I added in the content scripts section:
{
"matches": ["http://url_of_my_new_iframe/*"],
"css": [],
"js": ["ContentScript2.js"],
"run_at": "document_idle",
"all_frames": true
}
I thought putting the all_frames=true property would be sufficient, but when I use the extension, the ContentScript2.js is loaded in every other iframes loaded at page load, but NOT in my dynamically created iframe.
Does anybody have a solution for this?
More info: This is the code I use in ContentScript1 to create the iframe:
var iFrame = document.createElement('iframe');
iFrame.setAttribute('id', 'some_id');
document.body.insertBefore(iFrame, some_other_dom_element);
iFrame.setAttribute('src', 'my_iframe_url_not_same_domain');
Chrome Version is 35.0.1916.114