Skip to content

Commit 133cbb3

Browse files
linesightclaude
andcommitted
fix: make OnTextSelectionChanged click target robust against CI layout variance
Move onclick from <h1> to <body> and click at viewport center (400,300) instead of hardcoded h1 coordinates (200,43). selectText() now selects the h1 via querySelector rather than ev.target, so any click on the page reliably triggers OnTextSelectionChanged regardless of font metrics or rendering differences in CI environments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 19a0863 commit 133cbb3

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

unittests/osr_test.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
function selectText(ev) {
5252
// Selection API must run inside a real user-gesture handler so that
5353
// CEF fires OnTextSelectionChanged (Chrome 130+ requirement).
54-
var el = ev.target;
54+
// Always target the h1 directly so any click on the page works.
55+
var el = document.querySelector('h1');
5556
var range = document.createRange();
5657
range.selectNodeContents(el);
5758
var sel = window.getSelection();
@@ -64,9 +65,9 @@
6465
}
6566
</script>
6667
</head>
67-
<body>
68+
<body onclick="selectText(event)">
6869
<!-- FrameSourceVisitor hash = 747ef3e6011b6a61e6b3c6e54bdd2dee -->
69-
<h1 onclick="selectText(event)">Off-screen rendering test</h1>
70+
<h1>Off-screen rendering test</h1>
7071
<div id="console"></div>
7172
<div id="OnTextSelectionChanged">Test selection.</div>
7273
</body>
@@ -265,17 +266,17 @@ def _OnAccessibilityLocationChange(self, **_):
265266

266267

267268
def _click_h1_to_select(browser):
268-
"""Send a real click to the h1 element after layout is complete.
269+
"""Send a real click anywhere in the viewport after layout is complete.
269270
270271
Chrome 130+ requires the Selection API to run inside a real user-gesture
271-
event handler for OnTextSelectionChanged to fire. The h1 has an onclick
272-
handler (selectText) that selects the element's text via the Selection API.
273-
h1 position: body margin 8px + h1 margin-block-start ~20px ≈ y=28 top,
274-
h1 font-size ~29px ≈ y=57px bottom; click center at y=43.
272+
event handler for OnTextSelectionChanged to fire. The body has an onclick
273+
handler (selectText) that selects the h1 text via the Selection API.
274+
Click at the center of the 800x600 viewport — guaranteed to land on the
275+
body regardless of font metrics or CI rendering differences.
275276
"""
276-
browser.SendMouseClickEvent(200, 43, cef.MOUSEBUTTON_LEFT,
277+
browser.SendMouseClickEvent(400, 300, cef.MOUSEBUTTON_LEFT,
277278
mouseUp=False, clickCount=1)
278-
browser.SendMouseClickEvent(200, 43, cef.MOUSEBUTTON_LEFT,
279+
browser.SendMouseClickEvent(400, 300, cef.MOUSEBUTTON_LEFT,
279280
mouseUp=True, clickCount=1)
280281
browser.Invalidate(cef.PET_VIEW)
281282
subtest_message("_click_h1_to_select() ok")

0 commit comments

Comments
 (0)