fix mounting failure caused by DuckDuckGo's initial rendering delay. #610

This commit is contained in:
josc146
2024-01-26 11:27:31 +08:00
parent 4510cf421e
commit 5929a184a4
3 changed files with 22 additions and 1 deletions
@@ -1,4 +1,4 @@
export function waitForElementToExistAndSelect(selector) {
export function waitForElementToExistAndSelect(selector, timeout = 0) {
return new Promise((resolve) => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector))
@@ -15,5 +15,11 @@ export function waitForElementToExistAndSelect(selector) {
subtree: true,
childList: true,
})
if (timeout)
setTimeout(() => {
observer.disconnect()
resolve(null)
}, timeout)
})
}