I've got an extension that needs to load up a page with lots of redirects in its background page. Once that page gets to a known URL (https://website.com/index.php), the iframe should have its src
set to about:blank
.
The final page is quite large and has big images and everything that don't need to be loaded, so rather than attach to the iframe's onload
event, I set the following function on a 100ms interval:
function update(){
if(document.getElementsByTagName('iframe')[0].contentDocument.location.href == "https://website.com/index.php"){
console.log("Done!");
clearInterval(updateInterval);
document.getElementsByTagName('iframe')[0].src = "about:blank";
}
}
However, as soon as the iframe starts to load, update() throws this error:
Unsafe JavaScript attempt to access frame with URL https://website.com/index.php from frame with URL chrome-extension://hdmnoclbamhajcoblymcnloeoedkhfon/background.html. The frame requesting access has a protocol of 'chrome-extension', the frame being accessed has a protocol of 'https'. Protocols must match.
I tried catch()ing that error, but the message passed back to Javascript unsurprisingly doesn't include the URL. The page redirects multiple times, so it's important to know the exact URL. The src
property of the iframe also doesn't update to reflect redirects.