Skip to content

Browser: skip unused screenshot after load failure - #333737

Draft
Alexandru Dima (alexdima) wants to merge 2 commits into
mainfrom
agents/log-analysis-error-fix-prioritization-c3f3ed8e
Draft

Browser: skip unused screenshot after load failure#333737
Alexandru Dima (alexdima) wants to merge 2 commits into
mainfrom
agents/log-analysis-error-fix-prioritization-c3f3ed8e

Conversation

@alexdima

@alexdima Alexandru Dima (alexdima) commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

Avoid capturing an internal browser placeholder screenshot after a page has entered a load-error state.

Healthy pages still capture a screenshot before the native WebContentsView is hidden for an overlapping workbench overlay or editor visibility change. Failed or empty pages skip the capture because their placeholder is not rendered.

Evidence

I found this sequence while scanning recent Code - Insiders renderer logs:

2026-09-01 10:10:28.579 [error] [LanguageModelToolsService#invokeTool] Error from tool open_browser_page with parameters {"url":"https://github.com/user-attachments/assets/7e0c9c58-da83-41f5-baae-5342a2b5ea00","forceNew":true}:
ERR_FAILED (-2) loading 'https://github.com/user-attachments/assets/7e0c9c58-da83-41f5-baae-5342a2b5ea00': Error: ERR_FAILED (-2) loading 'https://github.com/user-attachments/assets/7e0c9c58-da83-41f5-baae-5342a2b5ea00'
2026-09-01 10:10:28.591 [error] Failed to capture browser view screenshot Cannot read properties of undefined (reading 'capturePage')
2026-09-01 10:10:28.591 [error] Failed to capture browser view screenshot Cannot read properties of undefined (reading 'capturePage')

The screenshot errors occur immediately after the failed navigation.

Root cause

WebContentsViewRendererFeature._refresh() already determines whether its HTML screenshot placeholder is useful:

const placeholderActive = !!this._model?.url && !this._model?.error;

A failed main-frame load populates model.error. That makes both placeholderActive and _shouldShowPage() false: the editor transitions to its error UI, and the native browser view should be hidden.

Before this change, every transition into the hidden state called _doScreenshot() unconditionally. This requested a screenshot even though the placeholder was disabled and the result could not be displayed. During failed-navigation teardown, that request reached Electron after the underlying capture target was no longer available and produced the capturePage error above.

Change

Make _doScreenshot() clear its pending timer, then return unless the model has a URL, has no load error, and remains visible. This centralizes the rule for refreshes, model attachment, visibility events, and recurring timer callbacks.

This preserves the intended screenshot swap for healthy pages while avoiding an unused capture for failed or empty pages. The existing deferred setVisible(false) behavior is unchanged.

Hidden-state reason Placeholder screenshot
Workbench overlay overlaps a healthy page Captured
Healthy browser editor becomes hidden Captured
Navigation has failed and error UI is active Skipped
No page URL is available Skipped

Review focus

Kyle Cutler (@kycutler), could you please confirm that skipping the renderer-owned placeholder capture is the intended boundary here? In particular, is there any failed-load state in which the browser error UI still needs the last successful page screenshot, or would you prefer additional hardening in the main-process capture path?

This is a draft because the exact external URL failure has not yet been reproduced against the patched build. The change is based on the logged event ordering and the existing placeholder/error-state contract.

Validation

  • npm run eslint -- src/vs/workbench/contrib/browserView/electron-browser/features/webContentsViewRendererFeature.ts
  • Repository pre-commit hygiene hook
  • git diff --check origin/main...HEAD

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Balanced
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​vs/​workbench/​contrib/​browserView/​electron-browser/​features/​webContentsViewRendererFeature.ts — This guard only suppresses _refresh's immediate capture. _doScreenshot() also reschedules…
What changed in this PR

Prevents unnecessary browser placeholder screenshots after load failures or empty-page states.

Changes:

  • Gates hidden-state screenshot capture on placeholder availability.
File Description
webContentsViewRendererFeature.ts Skips capture when the placeholder is inactive.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants