claude-in-chrome: beforeunload dialog on Medium (and other SPAs) disconnects extension during browser automation
Summary
When automating a site that registers a beforeunload event (e.g. the Medium article editor at /p/{id}/edit), navigating away during automation triggers the browser's \"Leave page?\" confirmation dialog. This dialog blocks all browser events and causes the Claude-in-Chrome extension to become unresponsive — subsequent mcp__claude-in-chrome__* tool calls return:
Browser extension is not connected. Please ensure the Claude browser extension is installed and running...
The extension reconnects after the dialog is manually dismissed, but the automation session is broken at that point.
Steps to Reproduce
- Use browser automation to navigate to a page with a
beforeunloadhandler (e.g.medium.com/p/{id}/edit— the Medium article editor) - Make edits or wait for the page to register the handler
- Call
mcp__claude-in-chrome__navigateto go to a different URL - The browser shows \"Leave site? Changes you made may not be saved\" dialog
- Extension stops responding — all subsequent tool calls return \"Browser extension is not connected\"
Affected Sites
Any SPA or editor that uses beforeunload to warn about unsaved changes:
- Medium article editor (
/p/{id}/edit) - Google Docs, Notion, and similar editors likely have the same behavior
Workaround
Inject window.onbeforeunload = null; via javascript_tool before any navigate() call that leaves a page with a beforeunload handler:
// Run this before navigating away from pages with unsaved-changes dialogs
window.onbeforeunload = null;
This suppresses the dialog and allows navigation to proceed without blocking the extension.
Suggested Fix
The extension could automatically suppress beforeunload dialogs during active automation sessions, similar to how Playwright and Puppeteer handle this. Both frameworks either ignore beforeunload by default or provide a page.on('dialog') handler that auto-dismisses them.
Alternatively, the extension could detect when a dialog is blocking event processing and surface a clear error message (e.g. \"Navigation blocked by browser dialog — dismiss it manually to continue\") rather than appearing to be fully disconnected.
Environment
- OS: Windows 10
- Browser: Chrome
- Claude Code with claude-in-chrome extension
Notes
The workaround (window.onbeforeunload = null) is effective but requires the user/agent to know in advance which pages have this handler. A framework-level fix would be more robust and would benefit all users automating editor-style applications.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗