NEW 261109
getBoundingClientRect() reports wrong sizes for foreignObject elements on page zoom
https://bugs.webkit.org/show_bug.cgi?id=261109
Summary getBoundingClientRect() reports wrong sizes for foreignObject elements on pag...
Oleksandr
Reported 2023-09-04 03:40:18 PDT
Created attachment 467537 [details] Safari misplaces the tooltip that should be attached to the embedded XHTML element Given a page with an SVG element with XHTML content embedded via <foreignObject/>, the getBoundingClientRect() method returns sizes that don't match the parent page viewport on zooming with Cmd +/-. It breaks the positioning of the elements next to the target element using the getBoundingClientRect(), which is essential for the various tooltips or outlines. Instead, the getBoundingClientRect() should return the same values as if the element is not being embedded into the <foreignObject/>. That would match the behavior of Chrome and Firefox. I was able to replicate the bugged behavior with additional logs in the sandbox - https://stackblitz.com/edit/stackblitz-starters-jh33b2?file=src%2FApp.tsx. Open it in Safari and try zooming the page with Cmd +/-. You'll see that the teal block will get misplaced. However, in Chrome or Firefox, the teal block will always be displayed right underneath the target orange XHTML block. Here's the comparison table of the tooltip position values I get in Chrome and Safari for the XHTML block: | Zoom level | Safari | Chrome | |------------|--------------------------------------|--------------------------------------| | -2 | { top: '45px', left: '0px' } | { top: '60px', left: '0px' } | | -1 | { top: '51px', left: '0px' } | { top: '60px', left: '0px' } | | 0 | { top: '60px', left: '0px' } | { top: '60px', left: '0px' } | | 1 | { top: '69px', left: '0px' } | { top: '60px', left: '0px' } | | 2 | { top: '75px', left: '0px' } | { top: '60px', left: '0px' } | | 3 | { top: '90px', left: '0px' } | { top: '60px', left: '0px' } | Meanwhile, such misplacement doesn't happen if I'm using getBoundingClientRect() on the plain <div/> located within a body of the page - https://stackblitz.com/edit/stackblitz-starters-lnhzg3?file=src%2FApp.tsx. The `top` and the `left` properties stay the same on an arbitrary zoom level.
Attachments
Safari misplaces the tooltip that should be attached to the embedded XHTML element (9.93 MB, video/quicktime)
2023-09-04 03:40 PDT, Oleksandr
no flags
Chrome properly places the tooltip underneath the embedded XHTML element (6.32 MB, video/quicktime)
2023-09-04 03:42 PDT, Oleksandr
no flags
Oleksandr
Comment 1 2023-09-04 03:42:19 PDT
Created attachment 467538 [details] Chrome properly places the tooltip underneath the embedded XHTML element
David Perkowski
Comment 2 2023-09-05 07:44:11 PDT
I wanted to add that we discovered this problem during the course of work to introduce accessibility improvements to a data chart that we render as an SVG. Having consistent behavior for zoom will make it easier to treat accessibility as a primary aspect of implementation on the web, and will encourage developers to engage with such challenges, rather than backing away when they encounter browser differences/bugs like this.
Alexey Proskuryakov
Comment 3 2023-09-05 09:16:58 PDT
Is this same as bug 71819?
Oleksandr
Comment 4 2023-09-06 01:08:30 PDT
On a second look, I can say that [bug 71819](https://bugs.webkit.org/show_bug.cgi?id=71819) might indeed describe the same buggy behavior of the getBoundingClientRect() for the elements within the <foreignObject/>. Especially looking at the examples attached to that bug. Both I and Gavin Kistner experienced that the getBoundingClientRect() values are transformed against the viewport on zoom and don't correspond to the parent <foreignObject/> dimensions or position
Radar WebKit Bug Importer
Comment 5 2023-09-11 03:41:16 PDT
Note You need to log in before you can comment on or make changes to this bug.