Skip to content

Instantly share code, notes, and snippets.

@pwall2222
Last active March 19, 2021 23:26
Show Gist options
  • Save pwall2222/a52a46bd2c94cbd0e760aaea1ce36821 to your computer and use it in GitHub Desktop.
Save pwall2222/a52a46bd2c94cbd0e760aaea1ce36821 to your computer and use it in GitHub Desktop.
How to replace a whole page with content script

Why

I was creating a page to substitude another in a project and I couldn't quite find anything to do this. So when i came out with the solution I decided I had to post it online.

How

Very easy stopping the window load, and then appending an iframe wich covers the whole page.

Code example

window.stop();
document.documentElement.innerHTML = "<head></head><body></body>";
const doc = await fetch("").then(response => response.text());
const item = document.createElement("iframe");
item.srcdoc = doc;
item.style = "position:fixed; top:0; left:0; bottom:0; right:0; width:100%; height:100%; border:none;"
document.body.appendChild(item);
item.focus();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment