Would there be any sort of issue or specification incompatibility caused by calling
// assume iframe.contentWindow was checked beforehand and is defined
iframe.contentWindow.document.open();
iframe.contentWindow.document.close();
within the iframe onload function?
e.g.
iframe.onload = () => {
// ...
// assume iframe.contentWindow was checked beforehand and is defined
iframe.contentWindow.document.open();
iframe.contentWindow.document.close();
}
The background to this is that when creating a friendly iframe, I want to get a reference to the iframe window and do certain operations with no / minimal writing to the iframe beforehand using document.write() and without having to use setTimeout (see https://bugs.chromium.org/p/chromium/issues/detail?id=978325 and https://bugs.chromium.org/p/chromium/issues/detail?id=961428 for why setTimeout would be needed)
The issue is that without calling open or when calling it prior to the onload function, the iframe location is set to about:blank (see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#opening-the-input-stream step 13). This can also be solved by adding a setTimeout after opening the document (outside of onload) at the cost of performance, which I would like to avoid.
The solution involving calling open and close within the onload function works on Chrome, Firefox and Safari, but JSDom considers the contentDocument to be null and the iframe itself to have no children when using this method (after manually simulating a call to onload, which is a separate issue, but might be related to the behavior)