Skip to content

fix(browser): persist interceptor across navigation#1870

Open
cnYui wants to merge 1 commit into
jackwener:mainfrom
cnYui:codex/fix-interceptor-new-document
Open

fix(browser): persist interceptor across navigation#1870
cnYui wants to merge 1 commit into
jackwener:mainfrom
cnYui:codex/fix-interceptor-new-document

Conversation

@cnYui
Copy link
Copy Markdown

@cnYui cnYui commented Jun 6, 2026

Description

installInterceptor(pattern) only patched the current document before this change. If a caller installed the interceptor and then navigated, the new document lost the fetch/XHR monkey patch, so requests fired by the loaded page could not be captured.

This keeps the existing current-document evaluate() injection and, when the page exposes CDP, also registers the same interceptor source through Page.addScriptToEvaluateOnNewDocument. CDP registration is best-effort so non-CDP backends keep the previous behavior instead of failing interceptor setup.

Related issue: fixes #584

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Documentation (if adding/modifying an adapter)

  • Added doc page under docs/adapters/ (if new adapter)
  • Updated docs/adapters/index.md table (if new adapter)
  • Updated sidebar in docs/.vitepress/config.mts (if new adapter)
  • Updated README.md / README.zh-CN.md when command discoverability changed
  • Used positional args for the command's primary subject unless a named flag is clearly better
  • Normalized expected adapter failures to CliError subclasses instead of raw Error

N/A: this PR does not add or modify an adapter.

Screenshots / Output

$ npx vitest run --project unit src/browser/base-page.test.ts
Test Files  1 passed (1)
Tests       44 passed (44)
$ npx tsc --noEmit
# passed

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.

[Bug]: installInterceptor not working after goto a new page

1 participant