Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Last active February 22, 2018 03:59
Show Gist options
  • Save jonathantneal/fba8689eaa288aeee11b to your computer and use it in GitHub Desktop.
Save jonathantneal/fba8689eaa288aeee11b to your computer and use it in GitHub Desktop.
Document `interactive` and `complete` promises
function onstate(readyStates, resolve) {
function handler() {
if (readyStates.includes(document.readyState)) {
document.removeEventListener('readystatechange', handler);
resolve();
}
}
document.addEventListener('readystatechange', handler);
handler();
}
document.interactive = new Promise(function (resolve) {
onstate(['interactive', 'complete'], resolve);
});
document.complete = new Promise(function (resolve) {
onstate(['complete'], resolve);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment