fix: waitForDocumentLoaded

This commit is contained in:
Xmader 2020-10-23 10:46:45 -04:00
parent dd959c995b
commit c63b30bc5d

View file

@ -22,11 +22,13 @@ export const fetchData = async (url: string, init?: RequestInit): Promise<Uint8A
export const waitForDocumentLoaded = (): Promise<void> => { export const waitForDocumentLoaded = (): Promise<void> => {
if (document.readyState !== 'complete') { if (document.readyState !== 'complete') {
return new Promise(resolve => { return new Promise(resolve => {
document.addEventListener('readystatechange', () => { const cb = () => {
if (document.readyState === 'complete') { if (document.readyState === 'complete') {
resolve() resolve()
document.removeEventListener('readystatechange', cb)
} }
}, { once: true }) }
document.addEventListener('readystatechange', cb)
}) })
} else { } else {
return Promise.resolve() return Promise.resolve()