<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>284341</bug_id>
          
          <creation_ts>2024-12-09 17:01:04 -0800</creation_ts>
          <short_desc>Improve &lt;img&gt;&apos;s naturalWidth &amp; naturalHeight with SVG images</short_desc>
          <delta_ts>2026-05-04 14:01:19 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>SVG</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=291655</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar, WPTImpact</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Daniel Holbert">dholbert</reporter>
          <assigned_to name="Anne van Kesteren">annevk</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>annevk</cc>
    
    <cc>emilio</cc>
    
    <cc>heycam</cc>
    
    <cc>karlcow</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zimmermann</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2080372</commentid>
    <comment_count>0</comment_count>
    <who name="Daniel Holbert">dholbert</who>
    <bug_when>2024-12-09 17:01:04 -0800</bug_when>
    <thetext>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&quot;

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&apos;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&apos;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).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2080399</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-12-09 20:04:02 -0800</bug_when>
    <thetext>&lt;rdar://problem/141196049&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2080400</commentid>
    <comment_count>2</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-12-09 20:15:56 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/37685</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2090900</commentid>
    <comment_count>3</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2025-01-30 21:04:23 -0800</bug_when>
    <thetext>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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2111476</commentid>
    <comment_count>4</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2025-04-17 01:27:24 -0700</bug_when>
    <thetext>Test Case on WPT (Already imported in repo) - https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight.html?label=master&amp;label=experimental&amp;aligned&amp;q=the-img-element%2F</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2121274</commentid>
    <comment_count>5</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2025-06-02 17:48:52 -0700</bug_when>
    <thetext>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&apos;t web-compatible, for cases where attributes are missing
https://github.com/whatwg/html/issues/11287#issuecomment-2923467541</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2121379</commentid>
    <comment_count>6</comment_count>
    <who name="Daniel Holbert">dholbert</who>
    <bug_when>2025-06-03 08:44:38 -0700</bug_when>
    <thetext>(In reply to Karl Dubost from comment #5)
&gt; see the new tests
&gt; https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/
&gt; 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-&quot;unavailable&quot;-cases) - it&apos;s now here:
https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/naturalWidth-naturalHeight-width-height.tentative.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2121380</commentid>
    <comment_count>7</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2025-06-03 08:56:26 -0700</bug_when>
    <thetext>(In reply to Daniel Holbert from comment #6)
&gt; (In reply to Karl Dubost from comment #5)
&gt; &gt; see the new tests
&gt; &gt; https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/
&gt; &gt; naturalWidth-naturalHeight-unavailable.tentative.html
&gt; 
&gt; Update: I actually renamed the test in the past few days (since I broadened
&gt; it to cover .width and .height APIs and not-just-&quot;unavailable&quot;-cases) - it&apos;s
&gt; now here:
&gt; https://wpt.fyi/results/html/semantics/embedded-content/the-img-element/
&gt; naturalWidth-naturalHeight-width-height.tentative.html

Thanks Daniel, I am syncing new tests here including this one - https://github.com/WebKit/WebKit/pull/46237</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2199646</commentid>
    <comment_count>8</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2026-04-13 03:34:55 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/62624</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2207348</commentid>
    <comment_count>9</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-05-04 14:01:16 -0700</bug_when>
    <thetext>Committed 312552@main (7a59ef69ef56): &lt;https://commits.webkit.org/312552@main&gt;

Reviewed commits have been landed. Closing PR #62624 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>