Community程式設計與開發github.com

trailofbits/chrome-mcp-troubleshooting

診斷並修復 Claude in Chrome MCP 擴充功能的連線問題。在 mcp__claude-in-chrome__* 工具失敗、回傳「Browser extension is not connected」或行為異常時使用。

chrome-mcp-troubleshooting 是什麼?

這個技能專門用來處理 Claude Code CLI 與 Claude.app(Cowork)之間因原生訊息傳遞主機衝突而導致的 Chrome MCP 連線問題。當你遇到「Browser extension is not connected」錯誤、瀏覽器自動化不穩定或超時時,可以用這個技能進行診斷和修復。它支援 macOS 平台,主要透過檢查和管理 Chrome 的原生訊息傳遞設定檔來解決問題。技能的核心是識別 Claude.app 和 Claude Code 使用了不同格式的 socket 檔案,並提供腳本讓你輕鬆切換兩者。此外,它也涵蓋了多重 Chrome 設定檔、多重 Claude Code 工作階段、包裝腳本版本過舊以及 TMPDIR 未設定等常見問題的解決方案。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/trailofbits/skills/tree/main/plugins/claude-in-chrome-troubleshooting/skills/chrome-mcp-troubleshooting

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Claude in Chrome MCP 故障排除

在 Claude in Chrome MCP 工具無法連線或運作不正常時,使用此技能。

使用時機

  • mcp__claude-in-chrome__* 工具失敗,並出現「Browser extension is not connected」錯誤
  • 瀏覽器自動化運作異常或經常超時
  • 在更新 Claude Code 或 Claude.app 之後
  • 在 Claude Code CLI 與 Claude.app(Cowork)之間切換時
  • 原生主機程序正在執行,但 MCP 工具仍然失敗

不應使用的情況

  • Linux 或 Windows 使用者 - 此技能涵蓋 macOS 專屬的路徑和工具(~/Library/Application Support/、osascript)
  • 與 Claude 擴充功能無關的一般 Chrome 自動化問題
  • Claude.app 桌面版的問題(非瀏覽器相關)
  • 網路連線問題
  • Chrome 擴充功能安裝問題(請使用 Chrome 線上應用程式商店支援)

Claude.app 與 Claude Code 的衝突(主要問題)

背景: 當 Claude.app 加入 Cowork 支援(從桌面應用程式進行瀏覽器自動化)時,它引入了一個與 Claude Code CLI 衝突的原生訊息傳遞主機。

兩個原生主機,兩種 Socket 格式

元件原生主機執行檔Socket 位置
Claude.app (Cowork)/Applications/Claude.app/Contents/Helpers/chrome-native-host/tmp/claude-mcp-browser-bridge-$USER/<PID>.sock
Claude Code CLI~/.local/share/claude/versions/<version> --chrome-native-host$TMPDIR/claude-mcp-browser-bridge-$USER(單一檔案)

衝突原因

  1. 兩者在 Chrome 中註冊了原生訊息傳遞設定:

    • com.anthropic.claude_browser_extension.json → Claude.app 輔助程式
    • com.anthropic.claude_code_browser_extension.json → Claude Code 包裝腳本
  2. Chrome 擴充功能會根據名稱請求原生主機

  3. 如果啟用了錯誤的設定,就會執行錯誤的執行檔

  4. 錯誤的執行檔會以 MCP 用戶端不預期的格式或位置建立 socket

  5. 結果:即使一切看似正常執行,仍會出現「Browser extension is not connected」

解決方案:停用 Claude.app 的原生主機

如果你使用 Claude Code CLI 進行瀏覽器自動化(而非 Cowork):

# 停用 Claude.app 的原生訊息傳遞設定
mv ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json \
   ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json.disabled

# 確認 Claude Code 的設定存在並指向包裝腳本
cat ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json

如果你使用 Cowork(Claude.app)進行瀏覽器自動化:

# 停用 Claude Code 的原生訊息傳遞設定
mv ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json \
   ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.json.disabled

你無法同時使用兩者。 選擇其中一個,並停用另一個。

切換腳本

將此內容加入 ~/.zshrc 或直接執行:

chrome-mcp-toggle() {
    local CONFIG_DIR=~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts
    local CLAUDE_APP="$CONFIG_DIR/com.anthropic.claude_browser_extension.json"
    local CLAUDE_CODE="$CONFIG_DIR/com.anthropic.claude_code_browser_extension.json"

    if [[ -f "$CLAUDE_APP" && ! -f "$CLAUDE_APP.disabled" ]]; then
        # 目前使用 Claude.app,切換至 Claude Code
        mv "$CLAUDE_APP" "$CLAUDE_APP.disabled"
        [[ -f "$CLAUDE_CODE.disabled" ]] && mv "$CLAUDE_CODE.disabled" "$CLAUDE_CODE"
        echo "已切換至 Claude Code CLI"
        echo "請重新啟動 Chrome 與 Claude Code 以套用變更"
    elif [[ -f "$CLAUDE_CODE" && ! -f "$CLAUDE_CODE.disabled" ]]; then
        # 目前使用 Claude Code,切換至 Claude.app
        mv "$CLAUDE_CODE" "$CLAUDE_CODE.disabled"
        [[ -f "$CLAUDE_APP.disabled" ]] && mv "$CLAUDE_APP.disabled" "$CLAUDE_APP"
        echo "已切換至 Claude.app (Cowork)"
        echo "請重新啟動 Chrome 以套用變更"
    else
        echo "目前狀態不明,請檢查設定:"
        ls -la "$CONFIG_DIR"/com.anthropic*.json* 2>/dev/null
    fi
}

用法:執行 chrome-mcp-toggle,然後重新啟動 Chrome(若切換至 CLI 則需一併重啟 Claude Code)。

快速診斷

# 1. 哪個原生主機執行檔正在執行?
ps aux | grep chrome-native-host | grep -v grep
# Claude.app: /Applications/Claude.app/Contents/Helpers/chrome-native-host
# Claude Code: ~/.local/share/claude/versions/X.X.X --chrome-native-host

# 2. socket 在哪裡?
# 若使用 Claude Code(TMPDIR 中的單一檔案):
ls -la "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER" 2>&1

# 若使用 Claude.app(包含 PID 檔案的目錄):
ls -la /tmp/claude-mcp-browser-bridge-$USER/ 2>&1

# 3. 原生主機連線到什麼?
lsof -U 2>&1 | grep claude-mcp-browser-bridge

# 4. 哪些設定是啟用的?
ls ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic*.json

關鍵見解

MCP 在啟動時連線。 如果啟動 Claude Code 時瀏覽器橋接器尚未就緒,整個工作階段的連線都會失敗。修復方法通常是:確保 Chrome 與擴充功能使用正確的設定執行,然後再重新啟動 Claude Code。

完整重置程序(Claude Code CLI)

# 1. 確保正確的設定已啟用
mv ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json \
   ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.json.disabled 2>/dev/null

# 2. 更新包裝腳本以使用最新版本的 Claude Code
cat > ~/.claude/chrome/chrome-native-host << 'EOF'
#!/bin/bash
LATEST=$(ls -t ~/.local/share/claude/versions/ 2>/dev/null | head -1)
exec "$HOME/.local/share/claude/versions/$LATEST" --chrome-native-host
EOF
chmod +x ~/.claude/chrome/chrome-native-host

# 3. 終止現有原生主機並清理 socket
pkill -f chrome-native-host
rm -rf /tmp/claude-mcp-browser-bridge-$USER/
rm -f "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER"

# 4. 重新啟動 Chrome
osascript -e 'quit app "Google Chrome"' && sleep 2 && open -a "Google Chrome"

# 5. 等待 Chrome 啟動,點擊 Claude 擴充功能圖示

# 6. 確認正確的原生主機正在執行
ps aux | grep chrome-native-host | grep -v grep
# 應顯示:~/.local/share/claude/versions/X.X.X --chrome-native-host

# 7. 確認 socket 存在
ls -la "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER"

# 8. 重新啟動 Claude Code

其他常見原因

多個 Chrome 設定檔

如果你在多個 Chrome 設定檔中安裝了 Claude 擴充功能,每個設定檔都會產生自己的原生主機和 socket。這可能導致混亂。

解決方法: 只在一個 Chrome 設定檔中啟用 Claude 擴充功能。

多個 Claude Code 工作階段

執行多個 Claude Code 實例可能會導致 socket 衝突。

解決方法: 一次只執行一個 Claude Code 工作階段,或在關閉其他工作階段後使用 /mcp 重新連線。

包裝腳本中寫死版本號

~/.claude/chrome/chrome-native-host 包裝腳本中可能寫死了版本號,導致更新後無法使用。

診斷方法:

cat ~/.claude/chrome/chrome-native-host
# 錯誤範例:exec "/Users/.../.local/share/claude/versions/2.0.76" --chrome-native-host
# 正確範例:使用 $(ls -t ...) 動態尋找最新版本

解決方法: 使用上述「完整重置程序」中的動態版本包裝腳本。

TMPDIR 未設定

Claude Code 預期 TMPDIR 已設定,以便找到 socket。

# 檢查
echo $TMPDIR
# 應顯示:/var/folders/XX/.../T/

# 修復:加入 ~/.zshrc
export TMPDIR="${TMPDIR:-$(getconf DARWIN_USER_TEMP_DIR)}"

深入診斷

echo "=== 原生主機執行檔 ==="
ps aux | grep chrome-native-host | grep -v grep

echo -e "\n=== Socket(Claude Code 位置)==="
ls -la "$(getconf DARWIN_USER_TEMP_DIR)/claude-mcp-browser-bridge-$USER" 2>&1

echo -e "\n=== Socket(Claude.app 位置)==="
ls -la /tmp/claude-mcp-browser-bridge-$USER/ 2>&1

echo -e "\n=== 原生主機開啟的檔案 ==="
pgrep -f chrome-native-host | xargs -I {} lsof -p {} 2>/dev/null | grep -E "(sock|claude-mcp)"

echo -e "\n=== 啟用的原生訊息傳遞設定 ==="
ls ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.anthropic*.json 2>/dev/null

echo -e "\n=== 自訂包裝腳本內容 ==="
cat ~/.claude/chrome/chrome-native-host 2>/dev/null || echo "無自訂包裝腳本"

echo -e "\n=== TMPDIR ==="
echo "TMPDIR=$TMPDIR"
echo "預期值:$(getconf DARWIN_USER_TEMP_DIR)"

檔案參考

檔案用途
~/.claude/chrome/chrome-native-hostClaude Code 的自訂包裝腳本
/Applications/Claude.app/Contents/Helpers/chrome-native-hostClaude.app (Cowork) 原生主機
~/.local/share/claude/versions/<version>Claude Code 執行檔(以 --chrome-native-host 執行)
~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_browser_extension.jsonClaude.app 原生主機的設定
~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.anthropic.claude_code_browser_extension.jsonClaude Code 原生主機的設定
$TMPDIR/claude-mcp-browser-bridge-$USERSocket 檔案(Claude Code)
/tmp/claude-mcp-browser-bridge-$USER/<PID>.sockSocket 檔案(Claude.app)

總結

  1. 主要問題: Claude.app (Cowork) 與 Claude Code 使用不同的原生主機,且 socket 格式不相容
  2. 解決方法: 停用你未使用的那個原生訊息傳遞設定
  3. 任何修復後: 必須重新啟動 Chrome 和 Claude Code(MCP 在啟動時連線)
  4. 一個設定檔: 只在一個 Chrome 設定檔中啟用 Claude 擴充功能
  5. 一個工作階段: 只執行一個 Claude Code 實例

原版技能由 @jeffzwang 來自 @ExaAILabs 製作。針對 Claude Desktop 和 Claude Code 的現行版本進行了強化與更新。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

trailofbits/address-sanitizer

AddressSanitizer detects memory errors during fuzzing. Use when fuzzing C/C++ code to find buffer overflows and use-after-free bugs.

trailofbits/aflpp

AFL++ is a fork of AFL with better fuzzing performance and advanced features. Use for multi-core fuzzing of C/C++ projects.

trailofbits/agentic-actions-auditor

Audits GitHub Actions workflows for security vulnerabilities in AI agent integrations including Claude Code Action, Gemini CLI, OpenAI Codex, and GitHub AI Inference. Detects attack vectors where attacker-controlled input reaches AI agents running in CI/CD pipelines, including env var intermediary patterns, direct expression injection, dangerous sandbox configurations, and wildcard user allowlists. Use when reviewing workflow files that invoke AI coding agents, auditing CI/CD pipeline security for prompt injection risks, or evaluating agentic action configurations.

trailofbits/algorand-vulnerability-scanner

Scans Algorand smart contracts for 11 common vulnerabilities including rekeying attacks, unchecked transaction fees, missing field validations, and access control issues. Use when auditing Algorand projects (TEAL/PyTeal).

trailofbits/ask-questions-if-underspecified

Clarify requirements before implementing. Use when serious doubts arise.

trailofbits/atheris

Atheris is a coverage-guided Python fuzzer based on libFuzzer. Use for fuzzing pure Python code and Python C extensions.

trailofbits/audit-augmentation

Augments Trailmark code graphs with external audit findings from SARIF static analysis results and weAudit annotation files. Maps findings to graph nodes by file and line overlap, creates severity-based subgraphs, and enables cross-referencing findings with pre-analysis data (blast radius, taint, etc.). Use when projecting SARIF results onto a code graph, overlaying weAudit annotations, cross-referencing Semgrep or CodeQL findings with call graph data, or visualizing audit findings in the context of code structure.

trailofbits/audit-context-building

Enables ultra-granular, line-by-line code analysis to build deep architectural context before vulnerability or bug finding.

trailofbits/audit-prep-assistant

Prepares codebases for security review using Trail of Bits' checklist. Helps set review goals, runs static analysis tools, increases test coverage, removes dead code, ensures accessibility, and generates documentation (flowcharts, user stories, inline comments).

trailofbits/burpsuite-project-parser

Searches and explores Burp Suite project files (.burp) from the command line. Use when searching response headers or bodies with regex patterns, extracting security audit findings, dumping proxy history or site map data, or analyzing HTTP traffic captured in a Burp project.

trailofbits/cairo-vulnerability-scanner

Scans Cairo/StarkNet smart contracts for 6 critical vulnerabilities including felt252 arithmetic overflow, L1-L2 messaging issues, address conversion problems, and signature replay. Use when auditing StarkNet projects.

trailofbits/cargo-fuzz

cargo-fuzz is the de facto fuzzing tool for Rust projects using Cargo. Use for fuzzing Rust code with libFuzzer backend.

trailofbits/claude-in-chrome-troubleshooting

Diagnose and fix Claude in Chrome MCP extension connectivity issues. Use when mcp__claude-in-chrome__* tools fail, return "Browser extension is not connected", or behave erratically.

trailofbits/code-improver

Runs an autonomous review-and-fix improvement loop over any code target — a skill, plugin, module, or directory — using a reviewer the user names: any installed skill or agent. Keeps a cross-round findings ledger, escalates when fixes stop converging, and guards scope mechanically. Use when asked to 'improve this code until review passes', 'run an improvement loop with <reviewer>', or to iterate review-and-fix with a specific reviewer. For skills prefer the skill-improver entry; for a branch prefer pr-improver.

trailofbits/code-maturity-assessor

Systematic code maturity assessment using Trail of Bits' 9-category framework. Analyzes codebase for arithmetic safety, auditing practices, access controls, complexity, decentralization, documentation, MEV risks, low-level code, and testing. Produces professional scorecard with evidence-based ratings and actionable recommendations.

trailofbits/codeql

Scans a codebase for security vulnerabilities using CodeQL's interprocedural data flow and taint tracking analysis. Triggers on "run codeql", "codeql scan", "codeql analysis", "build codeql database", or "find vulnerabilities with codeql". Supports "run all" (security-and-quality + security-experimental suites) and "important only" (high-precision security findings) scan modes. Also handles creating data extension models and processing CodeQL SARIF output.

trailofbits/constant-time-analysis

Detects timing side-channel vulnerabilities in cryptographic code. Use when implementing or reviewing crypto code, encountering division on secrets, secret-dependent branches, or constant-time programming questions in C, C++, Go, Rust, Swift, Java, Kotlin, C#, PHP, JavaScript, TypeScript, Python, or Ruby.

trailofbits/constant-time-testing

Constant-time testing detects timing side channels in cryptographic code. Use when auditing crypto implementations for timing vulnerabilities.

trailofbits/cosmos-vulnerability-scanner

Scans Cosmos SDK blockchain modules and CosmWasm contracts for consensus-critical vulnerabilities — chain halts, fund loss, state divergence. 25 core + 16 IBC + 10 EVM + 3 CosmWasm patterns. Use when auditing custom x/ modules, reviewing IBC integrations, or assessing pre-launch chain security. Updated for SDK v0.53.x.

trailofbits/coverage-analysis

Coverage analysis measures code exercised during fuzzing. Use when assessing harness effectiveness or identifying fuzzing blockers.

相關技能