* Create a wrapper script in ~/.claude/chrome/ that invokes the given command. This is * necessary because Chrome's native host manifest "path" field cannot contain arguments. * * @param command - The full command to execute (e.g., "/path/to/claude --chrome-native-host") * @returns The path to t
(command: string)
| 306 | * @returns The path to the wrapper script |
| 307 | */ |
| 308 | async function createWrapperScript(command: string): Promise<string> { |
| 309 | const platform = getPlatform() |
| 310 | const chromeDir = join(getClaudeConfigHomeDir(), 'chrome') |
| 311 | const wrapperPath = |
| 312 | platform === 'windows' |
| 313 | ? join(chromeDir, 'chrome-native-host.bat') |
| 314 | : join(chromeDir, 'chrome-native-host') |
| 315 | |
| 316 | const scriptContent = |
| 317 | platform === 'windows' |
| 318 | ? `@echo off |
| 319 | REM Chrome native host wrapper script |
| 320 | REM Generated by Claude Code - do not edit manually |
| 321 | ${command} |
| 322 | ` |
| 323 | : `#!/bin/sh |
| 324 | # Chrome native host wrapper script |
| 325 | # Generated by Claude Code - do not edit manually |
| 326 | exec ${command} |
| 327 | ` |
| 328 | |
| 329 | // Check if content matches to avoid unnecessary writes |
| 330 | const existingContent = await readFile(wrapperPath, 'utf-8').catch(() => null) |
| 331 | if (existingContent === scriptContent) { |
| 332 | return wrapperPath |
| 333 | } |
| 334 | |
| 335 | await mkdir(chromeDir, { recursive: true }) |
| 336 | await writeFile(wrapperPath, scriptContent) |
| 337 | |
| 338 | if (platform !== 'windows') { |
| 339 | await chmod(wrapperPath, 0o755) |
| 340 | } |
| 341 | |
| 342 | logForDebugging( |
| 343 | `[Claude in Chrome] Created Chrome native host wrapper script: ${wrapperPath}`, |
| 344 | ) |
| 345 | return wrapperPath |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Get cached value of whether Chrome extension is installed. Returns |
no test coverage detected