Skip to content

Instantly share code, notes, and snippets.

@buildingwatsize
Created November 5, 2025 07:01
Show Gist options
  • Select an option

  • Save buildingwatsize/e37f097db38a3f24cee77695d8ae2e20 to your computer and use it in GitHub Desktop.

Select an option

Save buildingwatsize/e37f097db38a3f24cee77695d8ae2e20 to your computer and use it in GitHub Desktop.
Web utils functions collection
const waitForElm = (selector) => {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
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