I'm writing a chrome extension to manipulate DOM elements in a website.
I have a content script that seems to be blocked somehow from executing in the webpage's iFrames even though it is injected.
content.js:
console.log("this script is executed");
chrome.runtime.sendMessage("Hello background.js, I am a frame");
Both in the webpage's console and the background.js' console only the first frame is logged.
At first I thought the iFrames were dynamically loaded and therefore the content scripts could not be injected.
Then I looked at the JS contexts in the console and it seems like the opposite is true:
They are injected but not executed.
I also tried accessing the frames via the top frame by:
let iFrames = document.getElementsByClassName('js-iframe');
for (iFrame of iFrames) {
console.log(iFrame.contentDocument);
console.log(iFrame.contentWindow);
}
//null
//Uncaught (in promise) DOMException: Blocked a frame with origin "https://www.webpage.com" from accessing a cross-origin frame.
What am I missing out?
PS: Of course a solution by executing in the frames themselves would be more preferable but a workaround like the one I tried would be extremely helpful as well.