The HTMLImageElement.decode() method never resolves when the src references a SVG image. To reproduce the issue: ``` const img = new Image(); img.src = 'https://unpkg.com/@mapbox/maki@4.0.0/icons/fuel-15.svg'; img.decode() .then(() => { console.log('loaded'); }) .catch(() => { console.log('error'); }); ``` Expected behavior: `loaded` is displayed in the console. (this is the case on Chromium and Firefox)
<rdar://problem/51488679>
Created attachment 371520 [details] decode-svg
What is the meaning of decoding an SVG image? And why do you expect the decode() promise to be resolved rather than being rejected? The specs https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode says: image . decode() This method causes the user agent to decode the image in parallel, returning a promise that fulfills when decoding is complete. The promise will be rejected with an "EncodingError" DOMException if the image cannot be decoded. Since the SVG image cannot be decoded, the promise is rejected. Open the attached test case.
I understand that an SVG image doesn't needs to be decoded but the promise could nevertheless be resolved. Context: the decode function is used in the OpenLayers library [1] to load and decode images in any format See also: https://chromium-review.googlesource.com/c/chromium/src/+/585220/ [1] https://github.com/openlayers/openlayers/blob/v6.0.0-beta.9/src/ol/Image.js#L160-L175
The spec is explicit about vector images: "If decoding does not need to be performed for this image (for example because it is a vector graphic), resolve promise with undefined."
This was fixed in r249367 and r249594. *** This bug has been marked as a duplicate of bug 201243 ***