fix: waitForDocumentLoaded
This commit is contained in:
parent
dd959c995b
commit
c63b30bc5d
1 changed files with 4 additions and 2 deletions
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue