Search code examples
javascriptgoogle-chromeiframegoogle-chrome-extensioncontent-script

Can't inject content script into all IFRAMEs from my Chrome Extension


In my Google Chrome Extension I need to be able to inject my content script into all IFRAMEs on the page. To do this my original manifest.json was declared as such:

"content_scripts": [
    {
        "run_at": "document_end",
        "all_frames" : true,
        "matches": ["http://*/*", "https://*/*"],
        "js": ["content.js"]
    }
],

This seemed to have worked for most sites, until I came across an IFRAME that was declared as such:

(From Chrome debugger) enter image description here

and here's the HTML for it:

<iframe id="wysiwygtext_ifr" src='javascript:""' frameborder="0" allowtransparency="true" title="Rich Text Area." style="width: 100%; height: 341px; display: block;"></iframe>

In this case my content script is not injected into that IFRAME.

I tried changing the matches filter to "matches": ["<all_urls>"] but that still didn't do it.

Is there any way for me to inject my content script in an IFRAME like that?


Solution

  • This is exactly the problem that the match_about_blank flag was created for. It was finally released to stable in Chrome 37.

    Just add "match_about_blank": true to the content script definition.

    You can also use it in tabs.executeScript. See: