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.
You can just inject an iframe of that web app in any page instead of re-implementing the whole UI from ground up. Just remember to first wrap that iframe in another iframe with src attribute pointing to a chrome-extension://* URL.
To use Read Aloud, navigate to the web page you want to read, then click the Read Aloud icon on the Chrome menu. In addition, the shortcut keys ALT-P, ALT-O, ALT-Comma, and ALT-Period can be used to Play/Pause, Stop, Rewind, and Forward. You may also select the text you want to read before activating the extension.
After the extension is added to your browser, open an extension's page on the Chrome Web Store, such as the Markdown Preview extension page. When the page loads, click on the CRX icon in the extensions bar in Chrome and select “View source.”
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With