fix(desktop): throttle hidden browsers between screenshots

Keep Chromium background throttling enabled outside serialized captures. Temporarily enable frame production and wait for fresh paint so hidden-window screenshots remain usable without continuously animating idle guests.
This commit is contained in:
Mohamed Boudra
2026-09-10 09:11:37 +02:00
parent 92504cd525
commit 4cf4b70ee0
11 changed files with 274 additions and 28 deletions
+14 -7
View File
@@ -12,8 +12,7 @@ It validates the compositor behavior that unit tests cannot see:
by retrying until the frame appears;
- both viewport `capturePage` and full-page CDP screenshots return real pixels from
the permanent production parking state;
- guest background throttling can be disabled once at attach without per-capture
renderer coordination;
- parked guests remain capturable with Chromium background throttling enabled;
- the real-Electron host-composer sentinel proves guest Enter cannot submit a focused
host composer;
- the automation group loads the compiled production keyboard boundary and guest
@@ -73,11 +72,19 @@ The harness writes PNG evidence and `results.json` to:
packages/desktop/capture-harness/out/
```
A passing run prints `PASS` lines for the production P1 attach-off parking state,
A passing run prints `PASS` lines for the production P1 default-throttling parking state,
including fresh, settled, 75-second soak, multi-tab, viewport, and full-page checks. The
PNG sizes may be device-pixel scaled; on a Retina display the 1280x800 logical viewport
is usually saved as 2560x1600.
Run `npm run test:e2e:browser-throttling --workspace=@getpaseo/desktop` to verify
that hiding the window stops guest animation, viewport screenshots contain fresh
pixels, and restoring or closing the browser still works. Pass `-- --full-page` to
also run the below-viewport pixel assertion: this reproduces the existing
[full-page repetition bug](https://github.com/getpaseo/paseo/issues/3196), which the
capture harness's frame-availability checks do not detect.
On Linux, run it under `xvfb-run -a` when no display is available.
## Mechanism
Electron captures copy from the guest web contents' compositor surface. A resident
@@ -96,8 +103,8 @@ plane stays below the overlay plane regardless of body insertion order; menus ke
layering inside `overlay-root`. Activating a presented browser also focuses its registered guest
`WebContents` in main so macOS assigns keyboard first-responder ownership to the page.
There is no renderer prep/restore handshake. Main disables guest background throttling
once when the webview attaches, then screenshot capture uses the shared serialized queue,
invalidates before each attempt, and retries known first-frame failures within the
5-second capture budget. Viewport screenshots use `capturePage({ stayHidden:false })`;
There is no renderer prep/restore handshake or lifetime background-throttling override.
Screenshot capture temporarily enables frame production inside the shared serialized queue,
restores the previous throttling policy on success or failure, invalidates before each attempt,
and retries known first-frame failures within the 5-second capture budget. Viewport screenshots use `capturePage({ stayHidden:false })`;
full-page screenshots use the existing CDP path with layout metrics and screenshot clip.