Repository navigation
fix(open_url): reuse active tab when target shares origin - #721
Merged
Merged
Conversation
`open_url` previously always spawned a new Chrome tab — the voice agent calling it during a research flow leaves dozens of half-used tabs the same way `mcp__claude-in-chrome__navigate` did (which PR #719 just addressed for the core-agent CLAUDE.md path). This patches the voice-side surface: `open_url` now queries the active tab's URL, parses both origins (scheme + host + port), and reuses the active tab when they match. Cross-origin and unparseable URLs fall back to new-tab. Any osascript failure falls back to new-tab too — callers never silently lose the open. Tool description updated to describe the new behavior so Gemini's prompt sees it. Companion to PR #719 (which fixed the core-agent / CLAUDE.md path). Together they cover both navigation surfaces. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
sonichi
commented
May 15, 2026
sonichi
left a comment
Owner
Author
There was a problem hiding this comment.
LGTM (cannot --approve own PR).
Logic trace (src/browser-tools.ts:openUrlTool):
- Target URL parsed via
new URL(url).originwith try/catch → falls through to new-tab on bad input (about:blank, chrome:// schemes) ✓ - Active tab URL queried with 3s timeout; if same-origin, AppleScript
set URL of active tabreuses it ✓ - Any failure on either osascript call falls through to new-tab — caller never silently loses the open ✓
- Logging + return-status distinguish
reusedvsopenedpaths ✓
Security: safeUrl escaping unchanged — still backslash → quote → double-quote sequence for the shell-+-AppleScript double envelope. The new osascript read takes no user input. No new injection vector.
Tool description: description grew from 65 → ~280 chars. That's longer than peers but justified — Gemini's tool-selection reads this; baking the new behavior into the description avoids needing a separate Gemini system-prompt update. Good call.
Edge cases verified by inspection:
about:blank/chrome://settings/→ unparseable origin → new-tab fall-through ✓- No front window → read errors → new-tab fall-through ✓
- Origin mismatch (cross-origin nav) → new-tab ✓
CI green, mergeable. Companion to merged PR #719 — both navigation paths into Chrome now respect same-origin tab reuse. Safe to land.
liususan091219
pushed a commit
to liususan091219/sutando-fork
that referenced
this pull request
May 28, 2026
`open_url` previously always spawned a new Chrome tab — the voice agent calling it during a research flow leaves dozens of half-used tabs the same way `mcp__claude-in-chrome__navigate` did (which PR sonichi#719 just addressed for the core-agent CLAUDE.md path). This patches the voice-side surface: `open_url` now queries the active tab's URL, parses both origins (scheme + host + port), and reuses the active tab when they match. Cross-origin and unparseable URLs fall back to new-tab. Any osascript failure falls back to new-tab too — callers never silently lose the open. Tool description updated to describe the new behavior so Gemini's prompt sees it. Companion to PR sonichi#719 (which fixed the core-agent / CLAUDE.md path). Together they cover both navigation surfaces. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion to PR #719 (merged as
429de3d). #719 fixed the core-agent / CLAUDE.md path somcp__claude-in-chrome__navigatereuses same-origin tabs. This PR fixes the voice-agent path:open_url(the inline tool Gemini Live calls for "open X" / "go to that link") previously always spawned a new Chrome tab.Change
src/browser-tools.ts:openUrlTool:Why now
Same root cause as the CLAUDE.md fix (PR #719) but on a different surface. Together they cover both navigation paths into Chrome:
mcp__claude-in-chrome__navigateopen_urlinline toolPer Chi: "for voice what's the solution" (2026-05-15 09:31 PT).
Test plan
tsc + tests (clean install)— should pass; only browser-tools.ts changed.🤖 Generated with Claude Code