提交 3511db58 编写于 作者: M Matt Bierner

Add polling based loading check for iframe

On safari in iframes with scripts disabled, the `DOMContentLoaded` never seems to be fired. Use polling to check if the load has happened instead
上级 bb9c167e
......@@ -496,21 +496,45 @@
newFrame.contentDocument.open();
}
newFrame.contentWindow.addEventListener('DOMContentLoaded', e => {
/**
* @param {Document} contentDocument
*/
function onFrameLoaded(contentDocument) {
// Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=978325
setTimeout(() => {
if (host.fakeLoad) {
newFrame.contentDocument.open();
newFrame.contentDocument.write(newDocument);
newFrame.contentDocument.close();
contentDocument.open();
contentDocument.write(newDocument);
contentDocument.close();
hookupOnLoadHandlers(newFrame);
}
const contentDocument = e.target ? (/** @type {HTMLDocument} */ (e.target)) : undefined;
if (contentDocument) {
applyStyles(contentDocument, contentDocument.body);
}
}, 0);
});
}
if (host.fakeLoad) {
// On Safari for iframes with scripts disabled, the `DOMContentLoaded` never seems to be fired.
// Use polling instead.
const interval = setInterval(() => {
// If the frame is no longer mounted, loading has stopped
if (!newFrame.parentElement) {
clearInterval(interval);
return;
}
if (newFrame.contentDocument.readyState === 'complete') {
clearInterval(interval);
onFrameLoaded(newFrame.contentDocument);
}
}, 10);
} else {
newFrame.contentWindow.addEventListener('DOMContentLoaded', e => {
const contentDocument = e.target ? (/** @type {HTMLDocument} */ (e.target)) : undefined;
onFrameLoaded(contentDocument);
});
}
/**
* @param {Document} contentDocument
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册