I launch a URL from another domain and then postMessage to it
const child = window.open("http://urlfromanotherdomain.com");
child.postMessage("you cant handle the message", "*");
The JavaScript code, in the child window I launch, registers its interest as follows:
window.onmessage = function(ev) {window.console.log(ev);}
The problem is that sometimes there's so much code to run in the child window before it's able to register interest that it doesn't receive the posted message.
How do I reliably know that the cross-domain child window is ready to receive messages? I tried to register child.onload, but that doesn't fire as it's cross-domain. Is there anything else like passing a parameter to window.open that can guarantee the delivery of the message?
Additional information that may be relevant:
- I'm using version 62 of Chrome.
- The real reason I'm ending up with a cross-domain window is because I want to ensure I get a new rendering thread in the child window as the rendering it is being done in is quite heavy. If I make it the same origin, Chrome seems to reuse the renderer process and hence the same thread.