Skip to content

Instantly share code, notes, and snippets.

@kharandziuk
Created October 17, 2022 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kharandziuk/4005ab850bd9adb93eca4437e9713f9f to your computer and use it in GitHub Desktop.
Save kharandziuk/4005ab850bd9adb93eca4437e9713f9f to your computer and use it in GitHub Desktop.
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment