@@ -115,23 +115,67 @@ zle -N __llm_cmdcomp
115115# Launch OpenCode with a Firefox DevTools MCP for browser debugging.
116116# All arguments are passed through to the opencode binary.
117117#
118- # Usage: opencode-firefox [opencode args...]
118+ # Usage: opencode-firefox [--url <browser-url>] [opencode args...]
119+ #
120+ # Options:
121+ # --url <url> Connect to an already-running browser at this URL (e.g.
122+ # http://localhost:9222). Skips launching Firefox.
119123#
120124# This function:
121- # 1. Finds an available port for Firefox remote debugging
122- # 2. Launches Firefox with remote debugging enabled
125+ # 1. Finds an available port for Firefox remote debugging (or uses --url)
126+ # 2. Launches Firefox with remote debugging enabled (unless --url given)
123127# 3. Passes MCP config via OPENCODE_CONFIG_CONTENT env var
124128# 4. Invokes opencode with any provided arguments
125- # 5. Cleans up the browser on exit
129+ # 5. Cleans up the browser on exit (unless --url given)
126130opencode-firefox () {
127131 local FIREFOX_DEBUG_PORT_MIN=9222
128132 local FIREFOX_DEBUG_PORT_MAX=9322
129133
130- local id port mcp_name user_data_dir firefox_pid mcp_config
134+ local browser_url=" " id port mcp_name user_data_dir firefox_pid mcp_config
135+
136+ # Parse our own options, leaving the rest for opencode
137+ while [[ $# -gt 0 ]]; do
138+ case " $1 " in
139+ --url)
140+ browser_url=" $2 "
141+ shift 2
142+ ;;
143+ --url=* )
144+ browser_url=" ${1# --url=} "
145+ shift
146+ ;;
147+ * )
148+ break
149+ ;;
150+ esac
151+ done
131152
132153 # Generate short random identifier (3 hex chars)
133154 id=$( head -c 2 /dev/urandom | xxd -p | head -c 3)
134155 mcp_name=" firefox-${id} "
156+
157+ if [[ -n " $browser_url " ]]; then
158+ # Connect to an existing browser — no launch, no cleanup
159+ mcp_config=$( jq -n \
160+ --arg name " $mcp_name " \
161+ --arg url " $browser_url " \
162+ ' {
163+ "$schema": "https://opencode.ai/config.json",
164+ "mcp": {
165+ ($name): {
166+ "type": "local",
167+ "command": ["npx", "-y", "chrome-devtools-mcp@latest", "--browserUrl=\($url)"]
168+ }
169+ }
170+ }' )
171+
172+ echo " Connecting to existing browser at ${browser_url} " >&2
173+ echo " MCP server: ${mcp_name} " >&2
174+
175+ OPENCODE_CONFIG_CONTENT=" $mcp_config " opencode " $@ "
176+ return $?
177+ fi
178+
135179 user_data_dir=" /tmp/opencode-firefox-debug-${id} "
136180
137181 # Find an available port in the range
0 commit comments