<?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>291310</bug_id>
          
          <creation_ts>2025-04-08 21:10:18 -0700</creation_ts>
          <short_desc>ResizeObserver listener on canvas element sends 0 on resize instead of its new size</short_desc>
          <delta_ts>2025-04-26 02:06:26 -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>Layout and Rendering</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=269911</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=254078</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=219005</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>471421641</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>karlcow</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2109892</commentid>
    <comment_count>0</comment_count>
    <who name="">471421641</who>
    <bug_when>2025-04-08 21:10:18 -0700</bug_when>
    <thetext>My project use angular as the basic framework, using angular resizeObserver to get get the canvas&apos;s width, the code as follows:

```
ngAfterViewInit() {
    const canvas = this.canvasRef.nativeElement;

    this.resizeObserver = new ResizeObserver(entries =&gt; {
      const entry = entries[0]
      if (this.images.length &gt; 0 &amp;&amp; this.images[this.currentPage -1]) {
        // console.log(&apos;resize current page:&apos; + this.currentPage);
        // console.log(&apos;resize image width:&apos; + this.images[this.currentPage - 1].naturalWidth)
        this.scale = entry.contentRect.width / this.images[this.currentPage - 1].naturalWidth;
      }
    });
    this.resizeObserver.observe(canvas);
  }
```

The canvas is used to load image the loading method is as follows:

```
onFileSelected(event: Event) {
    if (this.islocked) return;
    const input = event.target as HTMLInputElement;
    if (!input.files) { return; }
    const file = input.files[0]; 
    const reader = new FileReader();

    reader.onload = (e: ProgressEvent&lt;FileReader&gt;) =&gt; {
      const imageUrl = e.target?.result as string;
      const image = new Image() as HTMLImageElement;
      image.src = imageUrl;
      image.onload = () =&gt; {

        this.images.push(image);
        this.currentPage = this.images.length;
        this.totalPages = this.currentPage;
        console.log(&apos;current page:&apos; + this.currentPage)
        console.log(&apos;load image width:&apos; + this.images[this.currentPage - 1].naturalWidth)
        this.initMarkersPosition();
        this.drawImageToCanvas(true);
      }
    };
    reader.readAsDataURL(file); // 以 Data URL 的形式读取文件
  }
```
in safari browser after load can get the image correct naturalWidth also width, but in the resize listener the naturalWidth and width is zero
in chrome browser do not have the problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2109894</commentid>
    <comment_count>1</comment_count>
    <who name="">471421641</who>
    <bug_when>2025-04-08 21:12:15 -0700</bug_when>
    <thetext>if I resize the  browser&apos;s view port width, the width in resize listener is correct</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2111247</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-04-15 21:11:48 -0700</bug_when>
    <thetext>&lt;rdar://problem/149358951&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2113046</commentid>
    <comment_count>3</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2025-04-25 00:38:55 -0700</bug_when>
    <thetext>471421641@qq.com,

Thanks for the report, do you think it would be possible to provide a reduced test case which is not dependent on Angular and reproduces the issue you met. That would be helpful.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2113263</commentid>
    <comment_count>4</comment_count>
    <who name="">471421641</who>
    <bug_when>2025-04-26 02:06:26 -0700</bug_when>
    <thetext>I have no idea about your suggestions, if you use a reduced test that the problem do not appear, that will demonstrate the problem is from angular</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>