Image Elements Should Expose an HTML Attribute or JS Field on Load Fail/Success #11339
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
topic: img
Uh oh!
There was an error while loading. Please reload this page.
What problem are you trying to solve?
Hi! I've done a brief scan of existing Issues and didn't see any topic on this matter. (And my apologies if I've overlooked anything or if this has been submitted to the wrong place!)
Request: HTML
img
Elements lack visibility into the status of an Image Request/Fetch. Although,img
Elements displayalt
Text or some specifiedbackground
/background-image
say, these effects are mostly phenomenological (only apparent to the viewing User) and don't have corresponding handles in Code, the DOM, or available Interfaces.Specifically exposed through any one or more of the following:
my_element.failed
my_element.getAttribute('failed)
<img class="my_class" loading="lazy" alt="my text" src="my_url" failed="false" />
Comments
In all browsers I've researched (albeit only briefly), there's no inbuilt readily-available programmatic means to detect the present state of the Image
src
.Some Errors (
net::ERR_HTTP2_PROTOCOL_ERROR
) appear to sidestep typicalerror
and/orabort
handling (e.g - the following won't or won't always correctly catch some kinds ofnet::
namespaced Events - I'm not sure why but have been testing this repeatedly. Possibly another Issue in its own right.)One can presently use a mix of something like:
and:
handle or represent the state of Images that fail to load under heavy Network use (e.g. - the
net::ERR_HTTP2_PROTOCOL_ERROR
above). The default approach (using the above) is either somewhat unreliable ("finnicky") or is overridden by invisible and idiomatic browser operations.I think there's still merit to this suggestion even if those concerns don't warrant a solution "in-of-themselves".
alt
, alternatives set through CSS dynamically or not, etc.).The JavaScript Field or HTML Attribute could be set somewhere in 4.8.4.3 or thereabouts.
What solutions exist today?
One can presently use a mix of something like:
and:
But this approach will occasionally fail to catch certain kinds of failures. In testing:
net::ERR_HTTP2_PROTOCOL_ERROR
wasn't caught by any of the above in several browser about 50% of the time.How would you solve it?
The HTML Standard sets any one or more of the following:
my_element.failed
my_element.getAttribute('failed)
<img class="my_class" loading="lazy" alt="my text" src="my_url" failed="false" />
After
src
is read and used to retrieve an Image (roughly: 4.8.4.3-ish).Anything else?
No response
The text was updated successfully, but these errors were encountered: