Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add means to detect if a script is loading, has loaded, or has errored #4594

Open
dead-claudia opened this issue May 4, 2019 · 3 comments
Open
Labels
addition/proposal New features or enhancements needs concrete proposal Moving the issue forward requires someone to figure out a detailed plan needs implementer interest Moving the issue forward requires implementers to express interest topic: script

Comments

@dead-claudia
Copy link

dead-claudia commented May 4, 2019

Something like a [SameValue] attribute Promise<void> loaded; on HTMLScriptElement would be nice, where it's resolved immediately with the load event itself when the script completes execution and rejected immediately with the error event itself if/when an error occurs.

Currently, there is no way to tell if a script is loaded or not, and that would be very useful in a lot of contexts, particularly when the script is in the HTML itself and might not yet be loaded.

This is possible to polyfill, but only for scripts you can control the loading of. Conceptually, it's as simple as this:

script.loaded = new Promise((resolve, reject) => {
	script.addEventListener("load", resolve, false)
	script.addEventListener("error", reject, false)
})
@rniwa
Copy link

rniwa commented May 4, 2019

Maybe we want script.readyState. A bunch of objects like XHR and FileReader have it already.

@domenic
Copy link
Member

domenic commented May 4, 2019

I'd love to do "loaded" or "ready" promises for elements as a more ergonomic, modern API than the onload/onerror/readyState trio. See also #127 / #1936.

@domenic domenic added addition/proposal New features or enhancements needs concrete proposal Moving the issue forward requires someone to figure out a detailed plan needs implementer interest Moving the issue forward requires implementers to express interest topic: script labels May 4, 2019
@dead-claudia
Copy link
Author

Amended my proposal to be script.loaded rather than script.ready. It's a little more self-descriptive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs concrete proposal Moving the issue forward requires someone to figure out a detailed plan needs implementer interest Moving the issue forward requires implementers to express interest topic: script
Development

No branches or pull requests

3 participants