mdn / mdn/content

Clarify image.decode() failure on lazy-loaded images

Open
#38,034 2 comments 0 reactions 0 assignees View on GitHub
area: DOM/CSSOM Content:WebAPI help wanted
Dominant language
Markdown
Stars
11k
Forks
23.2k
Avg merge
2d 9h
Merged PRs (30d)
331

Description

### MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode

### What specific section or headline is this issue about?

Missing information

### What information was incorrect, unhelpful, or incomplete?

As noted in https://stackoverflow.com/questions/65146920/domexception-invalid-image-request, the decode() function will throw `EncodingError: Invalid image request.` on images with `loading="lazy"` _that have not yet loaded_ in Firefox; it will not do so in Chrome. This is either a browser bug, an indication that the page information ("This can be used to initiate loading of the image") is somewhat incomplete/misleading, or just of a case of undefined behavior which might deserve a note.

### What did you expect to see?

Either just a note that this `loading="lazy"` case fails in Firefox _on images that have not yet loaded_, or an explanation of the difference between loading and decoding/when decoding might fail if this is actually a symptom of a larger degree of complexity.

**edit:** Per further testing, calling decode() in an `onload` handler works and functions correctly on a `loading="lazy"` image; it's only calling it too early that fails.

### Do you have any supporting links, references, or citations?

The only semi-relevant Firefox bug I found is https://bugzilla.mozilla.org/show_bug.cgi?id=1758035, which links to [the spec](https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode). It's still not entirely clear from the spec text to me whether the function is explicitly supposed to interact with/wait for loading, and if so exactly how.

### Do you have anything more you want to share?

_No response_

### MDN metadata

Page report details

* Folder: `en-us/web/api/htmlimageelement/decode`
* MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode
* GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/api/htmlimageelement/decode/index.md
* Last commit: https://github.com/mdn/content/commit/e9e2ec643ac69c132f31427a0b586ab2cf83ed58
* Document last modified: 2024-07-26T02:56:30.000Z

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.