Skip to content

Instantly share code, notes, and snippets.

@enpitsuLin
Created June 12, 2024 06:28
Show Gist options
  • Save enpitsuLin/a3c94c77619df50f1c6edca1046f8733 to your computer and use it in GitHub Desktop.
Save enpitsuLin/a3c94c77619df50f1c6edca1046f8733 to your computer and use it in GitHub Desktop.
const waitForElement = (/** @type {string}*/selector) => {
return new Promise((resolve) => {
const observer = new MutationObserver(() => {
const target = document.querySelector(selector)
if (target) {
observer.disconnect()
resolve()
}
})
observer.observe(document, { childList: true, subtree: true, attributes: false })
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment