Bug 198527 - HTMLImage​Element​.decode() method doesn't work for SVG files
Summary: HTMLImage​Element​.decode() method doesn't work for SVG files
Status: RESOLVED DUPLICATE of bug 201243
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: Safari 12
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Said Abou-Hallawa
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-06-04 06:30 PDT by Frederic Junod
Modified: 2019-11-13 13:49 PST (History)
8 users (show)

See Also:


Attachments
decode-svg (297 bytes, text/html)
2019-06-06 12:25 PDT, Said Abou-Hallawa
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Frederic Junod 2019-06-04 06:30:41 PDT
The HTMLImage​Element​.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)
Comment 1 Radar WebKit Bug Importer 2019-06-06 10:22:37 PDT
<rdar://problem/51488679>
Comment 2 Said Abou-Hallawa 2019-06-06 12:25:24 PDT
Created attachment 371520 [details]
decode-svg
Comment 3 Said Abou-Hallawa 2019-06-06 12:26:08 PDT
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.
Comment 4 Frederic Junod 2019-06-06 13:03:03 PDT
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
Comment 5 Simon Fraser (smfr) 2019-06-06 15:39:08 PDT
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."
Comment 6 Said Abou-Hallawa 2019-11-13 13:49:05 PST
This was fixed in r249367 and r249594.

*** This bug has been marked as a duplicate of bug 201243 ***