I'm curious if the following scenario is a bug in Chrome, working as expected, or developer error.
So, I have an extension. In its manifest.json I request cross-origin permissions for two sites:
"permissions": [
"http://www.foo.com/*",
"http://www.bar.com/*"
]
I also declare a content script:
"content_scripts": [
{
"matches": ["http://www.foo.com/*"],
"js": ["injectedScript.js"]
}
]
So, I've indicated that I would like to inject "injectedScript.js" into all foo.com domains. "injectedScript.js" looks something like:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = handleStateChange; // Implemented elsewhere.
xhr.open("GET", 'http://www.bar.com/123'), true);
xhr.send();
Now, an iframe is added to my Chrome Extension's page. It looks like this:
<iframe src="http://www.foo.com/123"></iframe>
This frame's src matches my content script pattern. As such, when the frame loads, injectedScript.js is injected inside of it. But the XMLHttpRequest inside of injectedScript fails.
Now, this leaves me wondering what expected behavior is. It is frustrating to encounter CORS issues when I have requested the appropriate permissions... but I can also understand that I am attempting to access "http://www.bar.com/123" from an origin outside of my chrome-extension... albeit an iframe loaded into the extension which I have permission to access.
Any thoughts from anyone on the matter?
EDIT: If you're wondering what I could be getting at from a practical standpoint -- I would like to inject some javascript which can call getImageData on a video in the injected page. However, I can't, because getImageData thinks the video's src is tainted data. I've requested the appropriate permissions, but it doesn't trickle down into the iframe.
UPDATE: Here's a picture: https://i.stack.imgur.com/P5qup.png