scroll() hangs then raises TimeoutError on a background tab (0.1.9, Windows)
Summary
Since #618 made background tabs the default for named daemons, scroll() on a tab that
is not its window's selected tab never returns. Chrome does not ACK the
Input.dispatchMouseEvent(type="mouseWheel"), the helper has no timeout handling, and the
IPC read raises TimeoutError — which propagates out of scroll() and kills the whole
script. The page does not scroll either.
Activating the same tab makes the identical call succeed immediately.
This is Windows-specific as far as I can test (Chrome 152.0.7977.42, Windows 11).
Why it matters
new_tab() and switch_tab() no longer activate, so a script that opens a tab and scrolls
it — pagination, lazy-loaded lists, infinite scroll — now hits this on the first scroll()
unless the caller happens to have activated that tab. The failure is a hard
TimeoutError from the IPC layer rather than anything mentioning input or tab state, so it
reads as a daemon problem.
Notably click_at_xy() and press_key() are fine in the same background tab — only the
wheel event is affected. That asymmetry made it confusing to pin down.
Repro
Self-contained, uses only public helpers. Counters live in the page, so each number is what the page's own listeners observed — not merely that the CDP call returned.
import json
PAGE = (
"data:text/html,"
"<title>probe</title>"
"<button id=b style='font-size:20px;padding:16px'>click me</button>"
"<input id=i style='font-size:20px'>"
"<div style='height:4000px'></div>"
"<script>"
"window.c={click:0,keydown:0,scrolled:0};"
"document.getElementById('b').addEventListener('click',()=>c.click++);"
"document.getElementById('i').addEventListener('keydown',()=>c.keydown++);"
"document.addEventListener('scroll',()=>c.scrolled++,{passive:true});"
"</script>"
)
def probe(label):
js("window.c={click:0,keydown:0,scrolled:0};"
"document.getElementById('i').value='';window.scrollTo(0,0)")
box = js("(()=>{const r=document.getElementById('b').getBoundingClientRect();"
"return [r.x+r.width/2, r.y+r.height/2];})()")
click_at_xy(box[0], box[1])
js("document.getElementById('i').focus()")
press_key("a")
type_text("bc")
try: # dy is POSITIVE: the default -300 scrolls up
scroll(box[0], box[1], dy=600) # and does nothing at scrollY 0
scroll_err = None
except Exception as e:
scroll_err = f"{type(e).__name__}: {e}"
seen = js("[window.c.click, window.c.keydown, window.c.scrolled,"
" document.getElementById('i').value, document.hidden, window.scrollY]")
print(json.dumps({
"tab": label, "document.hidden": seen[4],
"click_at_xy -> click handlers": seen[0],
"press_key -> keydown handlers": seen[1],
"type_text -> input value": seen[3],
"scroll -> scroll events": seen[2], "scrollY": seen[5],
"scroll raised": scroll_err,
}, indent=2), flush=True)
a = new_tab(PAGE)
b = new_tab(PAGE)
activate_tab(b) # make A definitively not the selected tab
switch_tab(a)
probe("A - B is the window's selected tab")
activate_tab(a)
switch_tab(a)
probe("A - same tab, now activated")
Actual
{
"tab": "A - B is the window's selected tab",
"document.hidden": true,
"click_at_xy -> click handlers": 1,
"press_key -> keydown handlers": 1,
"type_text -> input value": "abc",
"scroll -> scroll events": 0,
"scrollY": 0,
"scroll raised": "TimeoutError: timed out"
}
{
"tab": "A - same tab, now activated",
"document.hidden": false,
"click_at_xy -> click handlers": 1,
"press_key -> keydown handlers": 1,
"type_text -> input value": "abc",
"scroll -> scroll events": 2,
"scrollY": 600,
"scroll raised": null
}
Deterministic — identical across repeated runs.
Expected
scroll() on an attached background tab either scrolls the page, or fails with something
that names the cause. A TimeoutError out of the IPC layer is neither.
Notes toward a fix
The dispatch not being ACKed is the actual signal, so the timeout is usable evidence rather than just a failure: catching it and falling back to a DOM scroll of the element under the point (or of the window) restores the behaviour, and reporting which path ran keeps it honest. Activating the tab also works but takes the user's visible tab, which is what #618 set out to stop doing.
Happy to open a PR if that direction seems right.
Environment
- browser-harness 0.1.9 (
41108b8) - Chrome 152.0.7977.42 (stable), launched with
--disable-features=CalculateNativeWinOcclusion - Windows 11 (10.0.26300), Python 3.12.11