support the img.decode() API

RESOLVED FIXED in Firefox 68

Status

()

enhancement
P3
normal
RESOLVED FIXED
6 months ago
7 days ago

People

(Reporter: dholbert, Assigned: aosmond)

Tracking

({dev-doc-complete, feature})

Trunk
mozilla68
Points:
---

Firefox Tracking Flags

(firefox65 wontfix, firefox66 wontfix, firefox67 wontfix, firefox68 fixed)

Details

(URL)

Attachments

(1 attachment)

(Reporter)

Description

6 months ago
Filing this bug to track the img.decode() API.

Apparently Google Images uses it (or wants to) to swap seamlessly from the low-res to high-res image -- right now, that can trigger a flash (in Firefox at least) due to the high res image not being fully decoded when they swap it in. More info in https://twitter.com/jaffathecake/status/925702096300707842 .

(See also bug 1416328 for the decoding attribute, which addresses similar use-cases more declaratively.)

Spec link:
https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode

Chrome's intent-to-implement a while back (they've shipped it now, perhaps WebKit has as well, not sure):
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/LMV9dBG_1-I

GitHub issue where it was specced:
https://github.com/whatwg/html/issues/2037
(Reporter)

Comment 1

6 months ago
Also: there's a good overview of the difference between the use-cases for <img decoding="..."> attribute vs. the img.decode() API in this github comment: https://github.com/whatwg/html/issues/1920#issuecomment-256114499
(Assignee)

Comment 2

6 months ago
I looked into what needed to be done on another bug around the time I implemented the attribute, but as I recall I just never got around to implementing it.
Assignee: nobody → aosmond
Flags: needinfo?(aosmond)
(Assignee)

Updated

6 months ago
Severity: normal → enhancement
Flags: needinfo?(aosmond)
Keywords: feature
Priority: -- → P3
(Assignee)

Comment 4

6 months ago
Still one test failing (locally) but most of the way there now:

try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=1ceedbd18674054ceee009fc296db9a3043aa64a
(Assignee)

Comment 5

6 months ago
(In reply to Andrew Osmond [:aosmond] from comment #4)
> Still one test failing (locally) but most of the way there now:
> 
> try:
> https://treeherder.mozilla.org/#/
> jobs?repo=try&revision=1ceedbd18674054ceee009fc296db9a3043aa64a

The last failure is weird. The promise is indeed rejected, but it doesn't bubble up to the test framework.
(Assignee)

Comment 6

6 months ago
(In reply to Andrew Osmond [:aosmond] from comment #5)
> (In reply to Andrew Osmond [:aosmond] from comment #4)
> > Still one test failing (locally) but most of the way there now:
> > 
> > try:
> > https://treeherder.mozilla.org/#/
> > jobs?repo=try&revision=1ceedbd18674054ceee009fc296db9a3043aa64a
> 
> The last failure is weird. The promise is indeed rejected, but it doesn't
> bubble up to the test framework.

Spoke with arai on IRC about this, it looks like we kill the global object when the iframe is removed, so the promises are dropped on the floor, despite me issuing the rejection. I'll leave the test case failing for now.
(Assignee)

Comment 8

6 months ago
The img decode API allows a web author to request that an image be
decoded at its intrinsic size and be notified when it has been
completed. This is useful to ensure an image is ready to display before
adding it to the DOM tree -- this will help reduce flickering.
(Assignee)

Comment 11

3 months ago

(In reply to Eric Shepherd [:sheppy] from comment #10)

Documentation updated:

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

Submitted BCD PR https://github.com/mdn/browser-compat-data/pull/3331 to update compatibility tables

Added to Firefox 65 for developers

Eric, this didn't land, and won't in time for 66 either since I have not been able to prioritize this work since. 67 is my new target.

@:aosmond -- Thanks for the reply; that's helpful. I'll update our schedule for documenting this, and will revise my PR to indicate we don't support this yet (instead of "no data").

Bug 1522288 is about potentially changing how we do image loads, in which case we probably also want to change how the decode api is implemented. See https://bugzilla.mozilla.org/show_bug.cgi?id=1522288#c8

(Assignee)

Comment 14

a month ago

I restarted rebasing/cleaning this up. Let's get this in 68 finally...

Comment 16

21 days ago
Pushed by aosmond@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/5a7f8303d682
Implement img decode API. r=bzbarsky,tnikkel

Comment 17

20 days ago
bugherder
Status: NEW → RESOLVED
Last Resolved: 20 days ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
Regressions: 1544668
You need to log in before you can comment on or make changes to this bug.