16

I'm writing a Chrome extension that needs to alter a popular web app when loaded. Unfortunately, most of the UI of that web app is rendered inside an iframe, and although the address of that iframe matches my content_scripts match declaration, the user script only gets invoked for the top frame.

Q: Is there a method of accessing HTML rendered inside an iframe from a Chrome content script extension? If yes, what permissions and other manifest options should I specify? Thanks.

dpq
  • 9,028
  • 10
  • 49
  • 69
  • 1
    Is this relevant for you? http://code.google.com/p/chromium/issues/detail?id=37920 – bzlm Oct 14 '10 at 20:46
  • 1
    No, it isn't. The iframe is not injected by the extension, but by the original web app. – dpq Oct 14 '10 at 20:48

2 Answers2

39

I've resolved the problem. The following option has to be specified in the content_scripts section of the manifest.json: "all_frames": true. Without it, the script is only applied to the top frame.

// Sometimes one just has to RTFM carefully.

dpq
  • 9,028
  • 10
  • 49
  • 69
10

Even "all_frames": true doesn't seem to help in the case of iframes without @src. This is discussed in the bug http://code.google.com/p/chromium/issues/detail?id=20773, which also covers some workarounds, including getting the contentDocument of the iframe element in the source page, e.g. $('a', $($("#canvas_frame")[0].contentDocument)).

This bug is not exactly the problem you were having (you wanted to load your content script inside the iframe, not interact between the iframe and the outer frame) but I think that most people who have one of the problems will have the other one as well.