Skip to content

Integrated browser: Closing a page after resuming deferred Playwright code logs unhandled rejections #330381

Description

When a run_playwright_code execution is resumed after timing out and the integrated browser page closes before the underlying Playwright call settles, the shared process logs an unhandled rejection for every resumed timeout.

Reproduction

  1. In VS Code Insiders, enable workbench.browser.enableChatTools.
  2. Open Chat in Agent mode and ask the agent to open https://example.com in the integrated browser.
  3. Ask the agent to call run_playwright_code for that page with:
    • code: await page.waitForTimeout(60000); return 'done';
    • timeoutMs: 1000
  4. The tool returns a deferredResultId. Ask the agent to call run_playwright_code again with that deferredResultId, the same page ID, no code, and timeoutMs: 1000.
  5. After the resumed call defers again, close the integrated browser tab before the original 60-second wait completes.
  6. Run Developer: Open Logs Folder and inspect sharedprocess.log in the current session directory.

Actual behavior

The Shared Process log contains an unhandled rejection. Repeating step 4 before closing the page produces another copy for each resume:

[uncaught exception in sharedProcess]: page.evaluate: Target page, context or browser has been closed
    at PlaywrightTab.runAndWaitForCompletion
    at PlaywrightTab.safeRunAgainstPage
    at PlaywrightSession._runAgainstPage
    at async PlaywrightSession._runWithDeferral

Expected behavior

Closing the page should reject the deferred tool result when it is observed again, without reporting an unhandled rejection in the shared process.

Root cause

Each call to waitForDeferredResult creates a new DeferredPromise. After that resumed wait times out, the promise is stored for the next resume without a rejection observer. Page closure rejects both the underlying Playwright operation and each stored resume promise. The initial invocation does not have this problem because its completion-telemetry handler observes both settlement paths.

Observed in VS Code Insiders 1.134.0 on Windows.

Metadata

Metadata

Labels

browser-integrationWeb browsing features integrated into VS Code (e.g. integrated browser)bugIssue identified by VS Code Team member as probable buginsiders-releasedPatch has been released in VS Code Insiders

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions