This gist shows two techniques for (simultaneously) accessing the DOM and the window
from a Chrome extension
You can run arbitrary code in the page using chrome.devtools.inspectedWindow.eval( ... )
This solution is shown in the files below prefixed with 1-
.
This will work at any time - even when you're stopped at a breakpoint in the debugger.
The only limitations are
- it has to be synchronous
- it is bound to cross-origin policies. For example, you can't read something like
return window.frames[0].my_global
ifframes[0]
is cross-origin. - return value is serialized
The more complicated option is to inject a script into the pages/frames you want to read data from and use message passing to pass that data back to your extension.
This is shown in the files below prefixed with 2-
.
Limitations of this solution
- it's complicated
- the content-script and injected-script cannot run while at a breakpoint