Skip to content

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

@dead-claudia

Description

@dead-claudia

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)
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds concrete proposalMoving the issue forward requires someone to figure out a detailed planneeds implementer interestMoving the issue forward requires implementers to express interesttopic: script

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions