RESOLVED FIXED284341
Improve <img>'s naturalWidth & naturalHeight with SVG images
https://bugs.webkit.org/show_bug.cgi?id=284341
Summary Improve <img>'s naturalWidth & naturalHeight with SVG images
Daniel Holbert
Reported 2024-12-09 17:01:04 PST
Steps to repro: 1. Visit https://bug1935269.bmoattachments.org/attachment.cgi?id=9442538 EXPECTED RESULTS: The second line of text at the top should say img naturalWidth x naturalHeight: 0 x 0" ACTUAL RESULTS: The second line of text at the top says: naturalWidth x naturalHeight: 300 x 150 Firefox gives expected-results. Chrome gives partly-expected results; they report 0 x 150. Their narrower version of this bug is https://issues.chromium.org/issues/41357911 . There's a more comprehensive test here: https://bug1935269.bmoattachments.org/attachment.cgi?id=9442584 WebKit fails 60 of the subtests there. Chrome fails 24. Firefox passes all of them. See more analysis over on https://bugzilla.mozilla.org/show_bug.cgi?id=1935269 (which I filed in Mozilla's bug tracker but is really tracking a case where Firefox is correct and other browsers are incorrect). The 3rd and 4th comments there have spec quotes that make it pretty-clear that Firefox is correct. heycam also looked at this 5 years ago over in https://bugzilla.mozilla.org/show_bug.cgi?id=1607081#c4 and concluded that it was correct to return 0x0 for this case. I posted some analysis of the relevant WebKit code in https://bugzilla.mozilla.org/show_bug.cgi?id=1935269#c6 -- https://searchfox.org/wubkat/rev/48c752dce43162935898b93cefa254a21a5e84c5/Source/WebCore/svg/graphics/SVGImage.cpp#148-149,172-180 is the main issue where it explicitly sets 300x150 if the size is empty (i.e. if either dimension happens to be 0).
Attachments
Radar WebKit Bug Importer
Comment 1 2024-12-09 20:04:02 PST
Karl Dubost
Comment 2 2024-12-09 20:15:56 PST
Karl Dubost
Comment 3 2025-01-30 21:04:23 PST
When this behavior is fixed, it will create a breakage for iCloud. See https://bugzilla.mozilla.org/show_bug.cgi?id=1923304 So it might need a Quirk at the same time that this is fixed.
Karl Dubost
Comment 5 2025-06-02 17:48:52 PDT
see the new tests https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-unavailable.tentative.html and the spec change: Spec text for naturalWidth and naturalHeight behavior isn't web-compatible, for cases where attributes are missing https://github.com/whatwg/html/issues/11287#issuecomment-2923467541
Daniel Holbert
Comment 6 2025-06-03 08:44:38 PDT
(In reply to Karl Dubost from comment #5) > see the new tests > https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/ > naturalWidth-naturalHeight-unavailable.tentative.html Update: I actually renamed the test in the past few days (since I broadened it to cover .width and .height APIs and not-just-"unavailable"-cases) - it's now here: https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.tentative.html
Ahmad Saleem
Comment 7 2025-06-03 08:56:26 PDT
(In reply to Daniel Holbert from comment #6) > (In reply to Karl Dubost from comment #5) > > see the new tests > > https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/ > > naturalWidth-naturalHeight-unavailable.tentative.html > > Update: I actually renamed the test in the past few days (since I broadened > it to cover .width and .height APIs and not-just-"unavailable"-cases) - it's > now here: > https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/ > naturalWidth-naturalHeight-width-height.tentative.html Thanks Daniel, I am syncing new tests here including this one - https://github.com/WebKit/WebKit/pull/46237
Anne van Kesteren
Comment 8 2026-04-13 03:34:55 PDT
EWS
Comment 9 2026-05-04 14:01:16 PDT
Committed 312552@main (7a59ef69ef56): <https://commits.webkit.org/312552@main> Reviewed commits have been landed. Closing PR #62624 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.