PageWebView: bound a script call's wait for the Chromium start

Merged
TE
3d ago
+67-2

What

PageWebView.callPageScript now waits at most chromiumScriptWait (5 s, roughly what a page script already waits for its own hook) for a Chromium start that is still in flight. If the start hasn't ended by then, the call returns nil instead of hanging. Fixes #34154.

Why

#34151 made the call wait for an in-flight Chromium start, so it runs in the engine that actually shows the page. makePage has no deadline of its own, though. If CEF never makes the browser, Copy Last Code Block, copy-conversation and the debug reads would wait forever. Before #34151 they returned at once from the empty WebKit view.

The wait is a DemandTimer on chromiumClock, raced against the start. A MainActor race object resumes the continuation exactly once, and the timer is cancelled when the start wins. The task that waits on the start ends when the start ends; close() cancels a hung start.

Test

  • New: PageWebViewEngineNeutralTests.aScriptCallReturnsNilWhenTheChromiumStartNeverEnds. It uses FakeChromiumHosting.hangs and PageTestClock.immediate, and has a 1-minute time limit, so a regression fails instead of hanging.
  • Existing: aScriptCalledWhileChromiumStartsRunsInChromium (the start wins) still passes.

Review follow-up kept from the subagent: a cold CEF start slower than 5 s now returns nil to a first call where #34151 waited it out. makePage still needs a deadline of its own. That is filed separately; #34154's hang is what this PR fixes.

Agent session: agent session

šŸ¤– Generated with Claude Code


Summary by cubic

PageWebView.callPageScript now waits at most 5 seconds (chromiumScriptWait, about a page script's own hook wait) for a Chromium start still in flight; if it hasn't ended by then, the call returns nil instead of hanging. Fixes #34154, where CEF never making the browser held Copy Last Code Block, copy-conversation, and debug reads forever, when before #34151 they returned at once.

Caveat

  • A cold CEF start slower than 5 s now returns nil to a first call where #34151 waited it out; makePage still needs its own deadline.