-
Notifications
You must be signed in to change notification settings - Fork 1.6k
docs(screenshots): backgrounded tabs pause rAF β screenshots of animated pages can lie #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,3 +15,12 @@ capture_screenshot("/tmp/shot.png", max_dim=1800) | |||||
| The downscale only happens when the image actually exceeds `max_dim`, so it's safe to leave on for every shot. | ||||||
|
|
||||||
| Use full-page screenshots (`full=True`) only when you need to see content below the fold β they are much larger and slower than viewport-only. | ||||||
|
|
||||||
| ## Backgrounded tabs freeze animations | ||||||
|
|
||||||
| Chrome pauses `requestAnimationFrame` in backgrounded or occluded tabs, so count-ups, reveals, and JS-driven animations render blank or stale in screenshots even though the page is "loaded". Before trusting a screenshot of anything animated: | ||||||
|
|
||||||
| - Probe `js("document.visibilityState")` β anything but `"visible"` means the screenshot may lie. | ||||||
| - Foreground the tab (`Target.activateTarget` via `cdp(...)`) and nudge it (scroll 1px or dispatch a mousemove) to restart rAF, then re-screenshot. | ||||||
| - For numbers and layout, prefer DOM reads (`js(...)` with `getBoundingClientRect` / `scrollHeight`) over pixels β they are immune to the pause. | ||||||
| - Animated values need two samples a few seconds apart that match before you read them as final. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Two matching reads do not establish that an animated value is final; a paused or temporarily held animation yields identical intermediate values. This can recreate the stale-frame false positive the section is meant to prevent. Suggest using matching samples only as a stability check and requiring the page/app's animation completion signal (or another known terminal condition) before calling a value final. Prompt for AI agents
Suggested change
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: DOM reads avoid screenshot-pixel artifacts, but they are not immune to a paused rAF animation: they return the same frozen intermediate text and geometry that the paused callbacks last wrote. This can make the guidance report a stale count-up or layout as authoritative. Suggest describing DOM reads as an inspection of the current state and requiring visibility plus an animation-completion condition before treating the value as final.
Prompt for AI agents