Skip to content

Instantly share code, notes, and snippets.

@gemanor
Created September 17, 2019 09:07
Show Gist options
  • Select an option

  • Save gemanor/30d64059294078091861df379babaa12 to your computer and use it in GitHub Desktop.

Select an option

Save gemanor/30d64059294078091861df379babaa12 to your computer and use it in GitHub Desktop.
const checkAvailability = new Promise((resolve) => {
const image = new Image();
const loadCB = function() {
resolve(image.height > 1);
}
image.onload = loadCB;
image.onerror = loadCB;
image.src = "https://youtube.com/favicon.ico";
});
// Usage:
// checkAvailability().then(isAvailable)
// Or in async/await fashion
// const isAvailable = async checkAvailability();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment