Bypass same origin frame

Let’s say you want to execute JavaScript code after a redirect

If you use document href you won’t be able to that.

If you try with a frame the same origin will block you

Here below a practical solution!

document.getElementById("idButton").onclick=async ()=>{ 
  var myUrl = document.getElementById("myUrl").value;
  var frame = document.getElementById("frame"); 
  var x = await fetch(myUrl);
  var html = await x.text(); 
  console.log("document written ");
  console.log('DOM is ready.');

Of course this is a practical solution for a specific goal and it is valid in the context of those requirements. There is no “one fits all” way to do things.

The fetch request could be blocked by cors on server in same cases, so one can resort to proxy like that

 myUrl = "" + myUrl; 

Another free option with cloudflare for the fetch is a serverless worker.