Repository navigation
fix(chromium): account for visual viewport offsets in hit testing - #44148
microsoft-playwright-automation[bot] wants to merge 2 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
🟢 All four failures predate this PRHi, I'm the Playwright bot. I checked the MCP failures against the diff and test history. Failure evidenceCovers MCP run 43961625956 at Pre-existing flake / infra
Checked the failures on Linux by the Playwright bot - agent run |
This comment has been minimized.
This comment has been minimized.
🟢 Both failures predate this PRHi, I'm the Playwright bot. I checked the Windows reporter failures against the diff and earlier CI logs. Failure evidenceCovers Pre-existing test failure
The small fix is to expect The MCP failures already have a separate verdict. Checked the failures on Linux by the Playwright bot - agent run |
|
|
||
| expectHitTarget(hitPoint: { x: number, y: number }, targetElement: Element) { | ||
| expectHitTarget(hitPoint: { x: number, y: number }, targetElement: Element, coordinateSystem: 'viewport' | 'client') { | ||
| // Chromium protocol coordinates are relative to the visual viewport, but DOM hit testing uses the layout viewport. |
There was a problem hiding this comment.
is this actually an upstream bug?
or is it something that just needs a "workaround" in playwright?
There was a problem hiding this comment.
Hi, I'm the Playwright bot; this fixes a coordinate-conversion bug in Playwright, not an upstream Chromium defect. Chromium deliberately converts CDP quads to the visual viewport, while DOM hit testing uses the layout viewport.
I confirmed with direct CDP input on Chromium 159.0.8154.6: a tap at (891,450) reaches the button, whose DOM center and touch clientX/clientY are (1233,707) after visual offsets of (342,257), so Playwright must convert the preliminary hit-test point but leave event client coordinates alone.
Revised on Linux by the Playwright bot - agent run
This comment has been minimized.
This comment has been minimized.
|
Hi, I'm the Playwright bot. This is a Playwright coordinate-conversion bug, not an upstream Chromium defect; I kept the implementation unchanged and answered the review thread with the source and direct-protocol evidence. Rebased onto Revised on Linux by the Playwright bot - agent run |
903421f to
35eba62
Compare
This comment has been minimized.
This comment has been minimized.
🟢 All three failures predate this PRHi, I'm the Playwright bot. I checked the failed MCP run against the PR diff and the logs from its base commit. Failure evidenceCovers MCP run 44150622356 at Pre-existing flake / infra All three Chrome tests also fail on the PR's exact base commit,
These are confirmed pre-existing failures; the matching logs alone do not establish whether they are intermittent. Checked the failures on Linux by the Playwright bot - agent run |
This comment has been minimized.
This comment has been minimized.
🟢 All three failures predate this PRHi, I'm the Playwright bot. I checked the failed run against the PR diff, earlier CI logs and test history. Failure evidenceCovers Pre-existing test failure
Pre-existing flake / infra
The MCP failures already have a separate verdict. Checked the failures on Linux by the Playwright bot - agent run |
|
|
||
| expectHitTarget(hitPoint: { x: number, y: number }, targetElement: Element) { | ||
| expectHitTarget(hitPoint: { x: number, y: number }, targetElement: Element, coordinateSystem: 'viewport' | 'client') { | ||
| // Chromium protocol coordinates are relative to the visual viewport, but DOM hit testing uses the layout viewport. |
There was a problem hiding this comment.
Does this mean that WebKit uses "layout viewport" for both input and hit testing? Vice versa? Or does visualViewport stay at 0;0 there?
Also, what do element.getBoundingClientRect() and our locator.boundingBox() api return? Are these relative to layout viewport or visual viewport?
There was a problem hiding this comment.
In this Linux mobile-emulation case, WebKit 27.2 keeps visualViewport.offsetLeft/Top at (0,0) and scrolls the layout viewport by (342,583), so input and DOM hit testing have the same origin. For the main-frame button, Chromium's getBoundingClientRect() and touch-event clientX/Y are layout-relative, while locator.boundingBox() and raw touchscreen input are visual-relative; Firefox uses layout-relative coordinates for all four even with visual offsets (342,0).
Measurements after scrolling the button into view
All three used isMobile: true, hasTouch: true and a 1200x900 viewport; the button is 50x50.
| Browser | Visual offsets | DOM rectangle origin | boundingBox() origin |
Raw tap -> touch clientX/Y |
|---|---|---|---|---|
| Chromium 159.0.8154.6 | (342,257) | (1208,682) | (866,425) | (891,450) -> (1233,707) |
| Firefox 159.0 | (342,0) | (1208,425) | (1208,425) | (1233,450) -> (1233,450) |
| WebKit 27.2 | (0,0) | (866,425) | (866,425) | (891,450) -> (891,450) |
document.elementFromPoint() finds the button at its DOM rectangle center in all three; subtracting the visual offset instead finds MAIN in Chromium and Firefox.
These measurements do not establish WebKit's behavior with a nonzero visual offset on real iOS.
Revised on Linux by the Playwright bot - agent run
| }, async ({ contextFactory, browserName }) => { | ||
| const context = await contextFactory({ | ||
| hasTouch: true, | ||
| isMobile: browserName !== 'firefox', |
There was a problem hiding this comment.
I think we do support isMobile on Firefox now, let's try passing true there.
There was a problem hiding this comment.
Set isMobile: true unconditionally in the separate regression test. It passes in Firefox 159.0, as well as Chromium and WebKit.
Revised on Linux by the Playwright bot - agent run
| onclick="this.textContent = 'tapped'">b</button> | ||
| </main> | ||
| `); | ||
| await page.locator('#a').tap(); |
There was a problem hiding this comment.
I don't understand why tapping this button would move the visual viewport off the 0;0 origin. Or is there anything else that causes the viewport movement? A more detailed explanation would be nice.
There was a problem hiding this comment.
It is the automatic scroll before the tap, not the touch event: the oversized content gives Chromium a 1542x1157 layout viewport but a 1200x900 visual viewport, and Playwright's DOM.scrollIntoViewIfNeeded pans the visual viewport to reveal the off-screen button. Calling scrollIntoViewIfNeeded() alone produces visual offsets (342,257) and layout scroll (0,326), before any input is sent. I removed the unnecessary first button/tap and added this explanation beside the remaining tap.
Revised on Linux by the Playwright bot - agent run
|
|
||
| it.describe('locators', () => { | ||
| it('TA-009 should send all of the correct events', async ({ page }) => { | ||
| it('TA-009 should send all of the correct events', { |
There was a problem hiding this comment.
Please don't update this test, and make a new one instead.
There was a problem hiding this comment.
Restored TA-009 unchanged and moved the regression into TA-011 should tap outside the initial visual viewport, with its own mobile context and issue annotation.
Revised on Linux by the Playwright bot - agent run
This comment has been minimized.
This comment has been minimized.
|
Hi, I'm the Playwright bot. I restored the existing locator test and added a separate mobile regression, with Rebased onto Revised on Linux by the Playwright bot - agent run |
35eba62 to
d87a105
Compare
Test results for "tests 1"3 failed 1 flaky23643 passed, 716 skipped Merge workflow run. |
🟢 All three failures also occur on mainHi, I'm the Playwright bot. I checked the failed run against the PR diff and matching failures on Failure evidenceCovers Pre-existing failures
Pre-existing flake / infra
The UI-mode test listed as flaky passed on retry and is not one of the three failed tests. Checked the failures on Linux by the Playwright bot - agent run |
Test results for "MCP"4 failed 5236 passed, 633 skipped Merge workflow run. |
🟢 All four failures predate this PRHi, I'm the Playwright bot. I checked the MCP failures against the PR diff, test history and independent CI logs. Failure evidenceCovers MCP run 44357191774 at Pre-existing failures
Pre-existing flake / infra
The Checked the failures on Linux by the Playwright bot - agent run |
Convert Chromium protocol hit-test points from visual viewport coordinates to layout viewport coordinates. Keep event client coordinates unchanged, and use the same conversion when checking parent frames.
Extend the existing locator tap test with a mobile page that pans horizontally and vertically.
Fixes #44121
Triaged on Linux by the Playwright bot - agent run