You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
browser: screenshot returns stale frame after client-side navigation #52407
browser.screenshot kept returning an outdated frame after an OAuth redirect (Keycloak → SPA), while tabs.list and browser.evaluate already reported the final URL and DOM. Repeated screenshots showed the login page although the tab was on the dashboard the whole time.
Environment
opencode version: v2.0.20
OS: Darwin 24.6.0 (darwin arm64)
Terminal: Unavailable: terminal environment variables are not set
Shell: /bin/zsh
Install/channel: latest
Active plugins: none found in config
Reproduction
Open a tab that redirects through an auth provider to an SPA (Keycloak → the application under test in my case).
Wait for tabs.list to report the final URL/title.
Confirm via browser.evaluate that location.href and document.body.innerText show the post-login page.
Call browser.screenshot({tabID}).
Expected Behavior
screenshot captures the currently rendered frame of the target tab, i.e. the post-login dashboard.
Actual Behavior
screenshot returned a stale image of the login form. This persisted across reload, tabs.focus, scroll, and repeated captures (varying byte sizes: 9.7 KB / 102 KB / 43 KB, all showing the login form). The dashboard finally appeared only after several more attempts, without any code change.
Note: tabs.open on the same URL reported ERR_ABORTED (-3) for the auth redirect, and browser.snapshot returned an empty accessibility tree on the Keycloak page (158 chars, no refs), while browser.evaluate saw the inputs — these may share the same root cause around cross-origin redirect handling.
Additional Context
browser.snapshot returned no refs on the Keycloak page, so the form had to be filled via browser.evaluate with native value setters; find also returned truncated content for it.
Frequency: reproduced 4/4 times in one session, then resolved spontaneously.
Workarounds tried: tabs.focus, scroll, reload, switching png/jpeg — all still showed the stale frame.
this issue → screenshot succeeds but returns a stale frame
The failure mode here is worse: there is no error, the tool returns an image that looks plausible but shows the previous page. Anything built on top of it (visual verification, regression checks, "did this render?" assertions) silently gets a wrong answer instead of failing loudly.
Reproduction
Navigate to a page that renders client-side (SPA / history-API navigation).
Change the route or fragment (location.hash, history.pushState, or an in-app link).
Wait for the DOM to actually update — confirmed via evaluate, e.g. document.querySelector('h1').textContent already returns the new content.
Call screenshot.
Observed: the captured surface still shows the frame from before the navigation, for several consecutive calls. A reload (or a fresh tabs.open) produces the correct image.
So the accessibility/DOM view and the compositor surface appear to diverge after client-side navigation — the page tree is updated, but the surface that fromSurface reads is not invalidated.
Would be glad to re-test with a build that logs surface invalidation on navigation.
Triage: source located, ~63 scenarios, no reproduction
Where the code lives
The capture path is not on the default branch. It is on v2, in packages/gui-extensions/src/browser/chromium.ts, case "screenshot" (~lines 688–735). On beta the same code is packages/desktop/src/main/browser-chromium.ts.
Between sizing the clip and capturing there is no wait for a frame:
constmetrics=awaitcdp.send("Page.getLayoutMetrics")// current layoutconstbounds= ... // from those metricsconstcapture=awaitcdp.send("Page.captureScreenshot",{
format,captureBeyondViewport: true,clip: { ...bounds, scale },})// pixels from the surface
The file already contains a helper for exactly this situation — painted() at ~line 1375:
// double requestAnimationFrame raced against a 150 ms timeoutasyncfunctionpainted(sessionID?: string){ ... }
but it is only called by the element-comment highlight path, never by screenshot. Inserting await painted() before Page.getLayoutMetrics would be a plausible hardening — I did not open a PR for it, because the reason is below: it is unverified.
What was tested
Level
Scenarios
Stale frames
Isolated Electron harness replicating the exact capture sequence
~50
0
The shipped app's own browser.* tools, v2.0.20 — the version in this report
5
0
createBrowserPage from branch v2 bundled and run under Electron
8
0
Covered: cross-site 302 redirect, cross-site JS redirect, cross-origin iframe (OOPIF), sibling-view and window occlusion, view.setVisible(false), tall pages with captureBeyondViewport + fullPage, pushState navigation that changes both content and layout height, scroll, reload-then-capture-immediately, and screenshotting a non-focused tab.
Confirmed from this report:
ERR_ABORTED (-3) reproduces with a JS location.replace() auth redirect — the secondary symptom is real.
A screenshot of a non-focused tab fails loudly with needs a visible tab — that gate works as intended.
A reproduction of the symptom that needs no product bug
Loading a page that renders the dashboard and then redirects itself back to the login form ~670 ms later (session not yet established):
Step
browser.evaluate
browser.screenshot
T1
DASHBOARD, green, /bouncedash
—
page navigates on its own
T2
—
LOGIN, red
T3
LOGIN, /bounceback
—
Byte sizes differ between the two captures — mirroring the "varying byte sizes (9.7 KB / 102 KB / 43 KB)" in the report.
This also explains the rest of the report economically: "persisted across reload" (the session cookie is still missing, so every load lands on login again) and "resolved spontaneously" (the cookie finally arrived). Nothing in the product needs to be wrong.
What would settle it
The deciding detail is what the page itself reported at the moment of each stale capture:
did a fresh location.href / document.body.innerText still say dashboard, or had it already gone back to the login form?
did tabs.list still report the dashboard URL after a screenshot that came back stale?
A stale image together with the matching evaluate output and the tab URL captured in the same moment would answer it either way. If the URL was already the login form at that point, this is a page-side effect during session establishment rather than a capture bug.
Thanks for the detailed report. The browser.* tools run inside the OpenCode Desktop app's built-in Chromium, and our automated sandbox can't run the desktop app, so I couldn't try to reproduce this here. It needs a maintainer with the desktop app on macOS.
If you can, these details would help them:
Whether it still happens on the latest desktop release
A minimal setup that triggers it, e.g. any public OAuth/Keycloak login that redirects to an SPA, or a local Keycloak setup
Whether the stale screenshot and the empty browser.snapshot tree on the Keycloak page happen in the same sessions
This was fixed in #63002, which waits for a fresh frame before capturing, so screenshots after client-side navigation are no longer stale. If you still see this on the latest version, comment here and we'll reopen.
Activity
github-actions commentedon Oct 1, 2026
This issue might be a duplicate of existing issues. Please check:
thevladimirzh commentedon Oct 1, 2026
This may be related to #50781, but the symptoms differ:
needs a visible tabThe failure mode here is worse: there is no error, the tool returns an image that looks plausible but shows the previous page. Anything built on top of it (visual verification, regression checks, "did this render?" assertions) silently gets a wrong answer instead of failing loudly.
Reproduction
location.hash,history.pushState, or an in-app link).evaluate, e.g.document.querySelector('h1').textContentalready returns the new content.screenshot.Observed: the captured surface still shows the frame from before the navigation, for several consecutive calls. A
reload(or a freshtabs.open) produces the correct image.So the accessibility/DOM view and the compositor surface appear to diverge after client-side navigation — the page tree is updated, but the surface that
fromSurfacereads is not invalidated.Would be glad to re-test with a build that logs surface invalidation on navigation.
thevladimirzh commentedon Oct 1, 2026
Triage: source located, ~63 scenarios, no reproduction
Where the code lives
The capture path is not on the default branch. It is on
v2, inpackages/gui-extensions/src/browser/chromium.ts,case "screenshot"(~lines 688–735). Onbetathe same code ispackages/desktop/src/main/browser-chromium.ts.Between sizing the clip and capturing there is no wait for a frame:
The file already contains a helper for exactly this situation —
painted()at ~line 1375:but it is only called by the element-comment highlight path, never by
screenshot. Insertingawait painted()beforePage.getLayoutMetricswould be a plausible hardening — I did not open a PR for it, because the reason is below: it is unverified.What was tested
browser.*tools, v2.0.20 — the version in this reportcreateBrowserPagefrom branchv2bundled and run under ElectronCovered: cross-site 302 redirect, cross-site JS redirect, cross-origin iframe (OOPIF), sibling-view and window occlusion,
view.setVisible(false), tall pages withcaptureBeyondViewport+fullPage,pushStatenavigation that changes both content and layout height, scroll, reload-then-capture-immediately, and screenshotting a non-focused tab.Confirmed from this report:
ERR_ABORTED (-3)reproduces with a JSlocation.replace()auth redirect — the secondary symptom is real.needs a visible tab— that gate works as intended.A reproduction of the symptom that needs no product bug
Loading a page that renders the dashboard and then redirects itself back to the login form ~670 ms later (session not yet established):
browser.evaluatebrowser.screenshotDASHBOARD, green,/bouncedashLOGIN, redLOGIN,/bouncebackByte sizes differ between the two captures — mirroring the "varying byte sizes (9.7 KB / 102 KB / 43 KB)" in the report.
This also explains the rest of the report economically: "persisted across
reload" (the session cookie is still missing, so every load lands on login again) and "resolved spontaneously" (the cookie finally arrived). Nothing in the product needs to be wrong.What would settle it
The deciding detail is what the page itself reported at the moment of each stale capture:
location.href/document.body.innerTextstill say dashboard, or had it already gone back to the login form?tabs.liststill report the dashboard URL after a screenshot that came back stale?A stale image together with the matching
evaluateoutput and the tab URL captured in the same moment would answer it either way. If the URL was already the login form at that point, this is a page-side effect during session establishment rather than a capture bug.thevladimirzh commentedon Oct 2, 2026
@Hona could you add the "bug" label to this issue?
opencodejr commentedon Oct 28, 2026
Thanks for the detailed report. The
browser.*tools run inside the OpenCode Desktop app's built-in Chromium, and our automated sandbox can't run the desktop app, so I couldn't try to reproduce this here. It needs a maintainer with the desktop app on macOS.If you can, these details would help them:
browser.snapshottree on the Keycloak page happen in the same sessionsneriousy commentedon Nov 23, 2026
This was fixed in #63002, which waits for a fresh frame before capturing, so screenshots after client-side navigation are no longer stale. If you still see this on the latest version, comment here and we'll reopen.