How to detect in javascript whether a new webpage launched from the current webpage has finished loading or not

javascript:(() => {
   window.open ("http://www.google.com"); 
   if (document.readyState === "complete"){
       alert (document.readyState);} 
})()


javascript:(() => {
   window.open ("http://www.google.com"); 
   window.onload = {
         alert (document.readyState);} 
})()

I am trying to create a B****ookmarklet which upon clicking will launch a webpage (either in the same tab or new tab both are fine) and once the webpage has finished loading then certain functions need to be done (changing dates & filling up textbox). The latter i have figured out but i am struggling to figure out a way to detect whether the newly launched webpage has finished loading or not

I am using javascript for it. i have tried all the common methods but the problem i am facing is that they are all detecting whether the current webpage on which i am currently at while clicking the bookmarklet has finished loading or not (which it already has obviously) but not the newly launched webpage

As a result i am always getting the popup as “complete” in the current tab even before the new webpage has loaded.

I am using chrome & i open to other programming languages or any workaround which can solve this problem