Skip to content

fix(navigate): return beforeunload dialogs from browser_navigate_back - #277

Merged
JustasMonkev merged 2 commits into
mainfrom
claude/tender-ramanujan-11kvom
Oct 13, 2026
Merged

JustasMonkev merged 2 commits into
mainfrom
claude/tender-ramanujan-11kvom

Conversation

@JustasMonkev

@JustasMonkev JustasMonkev commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Upstream change

Upstream now runs page.goBack() / page.goForward() inside _raceAgainstModalStates. Before that, a beforeunload dialog on the current page blocked the tool until the navigation timeout ran out, and the dialog never came back as a modal state.

Why it matters here

browser_navigate_back in src/tools/navigate.ts awaited tab.goBack() directly, so it had the same bug. browser_navigate already races against modal states (Tab.navigate(..., { returnOnDialog: true })), but going back did not. I reproduced it locally: the new test hangs past 5 s on main. (This repo has no browser_navigate_forward, so only going back needs the fix.)

Fix

  • Tab.goBackReturningOnDialog() races the history navigation against modal states, the same way navigate() does. If a dialog wins the race, a later navigation failure is kept as a console message instead of becoming an unhandled rejection.
  • browser_navigate_back uses it and leaves out the page.goBack() code line when it returns a dialog, the same as browser_navigate.
  • auditKeyboard's internal tab.goBack() is unchanged.

Tests

  • New integration test in tests/navigation-dialogs.test.ts: a page with a beforeunload handler, then a click, then browser_navigate_back. The tool returns the "beforeunload" dialog right away, and browser_handle_dialog then finishes the navigation. It fails on main and passes with this fix.
  • Updated the tools-navigate unit-test mock.
  • npm run lint and npm run knip are clean. The full vitest run fails the same 30 tests with and without this change. They are in history-downloads, extension-protocol, cdp-frame-tree and browser-upgrade-controls, and fail because the sandbox has no full Chromium 1243 binary. None of them are caused by this change.

Other upstream MCP commits reviewed (no action)

  • #43227 and #43244 (browser_route header fixes): this repo has no browser_route tool.
  • #43258 (--redact-url-params): this is a new opt-in feature, not a fix. I'm leaving it for a separate decision.
  • #43264 (bare-host URL normalization): browser_navigate here never added a scheme to bare URLs, so nothing regresses.
  • #43229 and #43203: these only touch the upstream CLI daemon.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NYnf61YoZEXnVaQJ52XjUT


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Browser back navigation now reports confirmation dialogs promptly and waits for the dialog to be handled before completing navigation. When a dialog is open, the response omits the replay instruction for navigating back. If navigation later fails, the failure is reported in page console messages when the page has not changed.
  • Documentation
    • Clarified how confirmation dialogs affect back navigation and how to accept or dismiss them.

RetriggerConfidence Score: 4/5

The PR appears safe to merge, with a non-blocking request to test later errors from back navigation.

Findings

  1. P2 Later errors lack tests ▶
Fix with agent prompt
### Issue 1
src/tab.ts:338-343
The new integration test accepts the dialog, but never checks a later rejection from `goBackReturningOnDialog()`. The existing `navigate()` tests do not exercise this method, so its error-reporting branch could break unnoticed.

Add focused tests in `tests/tab.test.ts` that reject the pending `goBack()` after the dialog returns. Check that the error reaches `consoleMessages()` when the page stays unchanged, and is ignored after `framenavigated`. This is non-blocking test coverage feedback.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR lets browser_navigate_back return an open dialog instead of waiting for the navigation timeout.

  • Back navigation returns a dialog when the page asks before leaving.

Diagram

sequenceDiagram
  participant User
  participant Tool as browser_navigate_back
  participant Tab
  participant Page
  User->>Tool: Go back
  Tool->>Tab: goBackReturningOnDialog()
  Tab->>Page: goBack()
  Page-->>Tab: beforeunload dialog
  Tab-->>Tool: Modal state
  Tool-->>User: Dialog response
  User->>Page: browser_handle_dialog accepts
  Page->>Page: Finish history navigation
Loading

Reviews (1) · Last reviewed commit: "fix(navigate): return beforeunload dialo..." · Reviewed by Greptile

browser_navigate_back awaited page.goBack() directly, so a beforeunload
(or load-time) dialog blocked the tool until the navigation timeout.
Race the history navigation against modal states the same way
browser_navigate already does, and report the dialog immediately.

Mirrors upstream microsoft/playwright#43252.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYnf61YoZEXnVaQJ52XjUT
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T09:37:18.184455Z 9a61750 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f8b8784a-348a-4597-b998-016103e60268
📥 Commits

Reviewing files that changed from the base of the PR and between efb5f63 and 9a61750.

📒 Files selected for processing (4)
  • README.md
  • src/tools/navigate.ts
  • tests/navigation-dialogs.test.ts
  • tests/tab.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Back navigation now races history navigation against modal-state events. The navigation tool uses returned modal states to decide whether to include page.goBack() replay code. Tests cover dialog handling, delayed navigation failures, and replay behavior.

Changes: Modal-aware back navigation

Layer / File(s) Summary
Return modal states and update navigation output
src/tab.ts, src/tools/navigate.ts
Tab.goBackReturningOnDialog returns modal states that interrupt history navigation. browser_navigate_back omits page.goBack() replay code while a modal state is returned.
Validate dialog handling and replay behavior
tests/navigation-dialogs.test.ts, tests/tab.test.ts, tests/tools-navigate.test.ts, README.md
Tests cover dialog acceptance, navigation failures, listener cleanup, and replay-code behavior. The navigation mock and documentation reflect the modal-aware behavior.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: claude

Merge Risk: ⚪ Minimal · up to 9a617

Back navigation can return a beforeunload dialog without waiting for it to be handled. No merge-blocking issue was identified.

Pre-merge checks · Passed 5
Passed Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: returning beforeunload dialogs from browser_navigate_back.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 5…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread src/tab.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: efb5f63819

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools/navigate.ts Resolved
Comment thread src/tools/navigate.ts Resolved

Copy link
Copy Markdown
Owner Author

Addressed all three reviewed concerns in 9a61750; replied to and resolved each thread after verification.

The stale-modal replay defect is reproduced with a controlled dialogclosed event and a real browser dialog accepted outside MCP. The two-line production fix checks live modal state, matching browser_navigate. Delayed-error handling already passed the new coverage, so it needed no production change. The README now describes the pending beforeunload flow and browser_handle_dialog.

Validation:

  • Focused navigation/dialog suites: 122 passed, including real Chromium coverage.
  • Lint/typecheck, build, Knip, and diff whitespace check: passed.
  • Mutation checks: reversing the document-generation guard fails all three delayed-error cases; restoring the stale-array check fails the real-browser external-close test. Both mutations were reverted.
  • Full suite: 1601 passed, 37 failed, 5 skipped. Untouched efb5f63 baseline: 1594 passed, 37 failed, 5 skipped. Failing case names match exactly: no new failures. Existing failures span history-downloads, extension-protocol, CDP frame-tree, details-visibility, and auditKeyboard integration. Logs show sandbox socket denials in persistent/full Chromium launches, a missing Chrome channel, and existing attach/test failures. These are reported separately from regressions.

Lazy-clean triage:

  • Changed-line scan: clean across all three changed TypeScript files.
  • Whole-file scan: 100 findings on unchanged test code: 87 no-any, 10 type assertions missing safety comments, 2 await Promise.resolve() calls, and 1 fixture delay. Existing test doubles/fixtures account for the first two groups; the awaits flush existing test microtasks; the route delay simulates delayed navigation. All were retained to avoid unrelated refactoring, without weakening or suppressing checks.
  • Manual review found no new dead code, speculative generality, duplicate platform logic, hidden errors, or debug leftovers. No dependency, lockfile, or CI changes.

GitHub CI is running on the new commit.

@JustasMonkev
JustasMonkev merged commit 1a50c89 into main Oct 13, 2026
13 checks 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.

2 participants