admin管理员组

文章数量:1430756

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)

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?

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)

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?

Share Improve this question asked Sep 10, 2014 at 2:28 c00000fdc00000fd 22.5k37 gold badges203 silver badges442 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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:

  • https://developer.chrome./extensions/content_scripts
  • https://developer.chrome./extensions/tabs#type-InjectDetails

本文标签: javascriptCan39t inject content script into all IFRAMEs from my Chrome ExtensionStack Overflow