Skip to content

Instantly share code, notes, and snippets.

@Calamari
Last active February 17, 2018 11:04
Show Gist options
  • Save Calamari/dbf647bb752ef630c91e810c4fa0f61d to your computer and use it in GitHub Desktop.
Save Calamari/dbf647bb752ef630c91e810c4fa0f61d to your computer and use it in GitHub Desktop.
page helpers for async waiting
const sleep = time => new Promise(resolve => {
setTimeout(() => resolve(), time)
})
const waitUntilHidden = async (selector, timeout = 5000) => {
const endTime = Date.now() + timeout
while (document.querySelectorAll(selector).length && Date.now() < endTime) {
await sleep(100)
}
}
const waitUntil = async (selector, timeout = 5000) => {
const endTime = Date.now() + timeout
while (!document.querySelectorAll(selector).length && Date.now() < endTime) {
await sleep(100)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment