[BUG] javascript_tool fails with regex literals containing backslash escapes
What's Wrong?
When using the mcp__claude-in-chrome__javascript_tool to execute JavaScript containing regex literals with backslash escapes (like \/ or \.), the code fails with a misleading SyntaxError.
The error message says "Unexpected token 'const'" but the actual problem is the regex escapes being mangled during parameter passing.
Steps to Reproduce
- Connect Claude Code to Chrome via the Claude in Chrome extension
- Execute javascript_tool with a regex containing backslash escapes:
Working (no escapes):
const x = "test".match(/test/); x
Failing (with escapes):
const match = url.match(/\/(\d+)_SHARED_snapshot\.jpeg/); match
- The second example fails with:
SyntaxError: Unexpected token 'const'
at <anonymous>:5:13
at <anonymous>:20:11
Expected Behavior
Regex executes normally and returns match result.
Actual Behavior
SyntaxError thrown. The error points to 'const' but is actually caused by backslash escape handling in the parameter passing chain.
Workaround
Use string methods or RegExp constructor instead of regex literals:
// String method approach
url.split("/").pop().split("_")[0]
// RegExp constructor (requires double-escaping)
new RegExp("/(\d+)_SHARED_snapshot\.jpeg")
Environment
- OS: Windows 11
- Claude Code: Latest version
- Chrome extension: 1.0.36+
- The issue occurs specifically with the
mcp__claude-in-chrome__javascript_tool
Additional Context
Simple regex without escapes works fine. The issue is specifically with backslash escape sequences in regex literals being corrupted before reaching the browser's JavaScript engine.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗