I'm doing a plugin to do some transformations to the interface. I keep getting unsafe javascript attempt to access frame with url.... Domains, protocols and ports must match
(typical cross site issue)
But being an extension it should have access to the iframe's content http://code.google.com/chrome/extensions/content_scripts.html ...
Doesn anyone know how to access it's contents so they can be capturable?
There's generally no direct way of accessing a different-origin
window
object. If you want to securely communicate between content scripts in different frames, you have to send a message to the background page which in turn sends the message back to the tab.Here is an example:
Part of
manifest.json
:main.js
:sub.js
:Background script 'bg.js':
An alternative method is to use
chrome.tabs.executeScript
inbg.js
to trigger a function in the main content script.Relevant documentation
c.runtime.sendMessage
/c.tabs.sendMessage
/c.runtime.onMessage
MessageSender
andTab
types.chrome.tabs.executeScript
I understand that this is an old question but I recently spent half a day in order to solve it. Usually creating of a iframe looks something like that:
This frame will have different origin with a page and you will not be able to obtain its DOM. But if you create iframe just for css isolation you can do this in another way:
After that you can use iframe.contentDocument to access to iframe's DOM