Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Chrome extensions access iframes?

Tags:

if I write a Chrome extension that runs a snippet of JS on a page, will it also run in any iframes I create? If so, does this apply for iframes created by Javascript after the DOM has loaded?

Thanks!

like image 499
Garen Checkley Avatar asked Jan 18 '12 21:01

Garen Checkley


1 Answers

Yes, a Chrome Extension "content script" can run in all iframes (that are initially in the HTML when the page is loaded). In order to have the content script run in all frames you need to configure it to do so in the Chrome Extension manifest.json using the all_frames property:

http://code.google.com/chrome/extensions/content_scripts.html

{   "name": "My extension",   ...   "content_scripts": [     {       "matches": ["http://www.google.com/*"],       "css": ["mystyles.css"],       "js": ["jquery.js", "myscript.js"],       "all_frames": true     }   ],   ... } 

No, the content scripts will NOT execute in the iframes loaded dynamically via JavaScript in the page.

like image 93
Adam Ayres Avatar answered Oct 22 '22 04:10

Adam Ayres