{"record":{"id":"e3ae15ca0e4a2c89","repo":"browsh-org/browsh","slug":"there-appears-to-already-be-an-existing-web-extens","errorCode":null,"errorMessage":"There appears to already be an existing Web Extension connection","messagePattern":"There appears to already be an existing Web Extension connection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"interfacer/src/browsh/firefox.go","lineNumber":164,"sourceCode":"\t\t\tvo[j+1] = b\n\t\t\tcontinue\n\t\t}\n\t\tif vo[j]+1 > maxByte {\n\t\t\tpanic(\"VersionOrdinal: invalid version\")\n\t\t}\n\t\tvo = append(vo, b)\n\t\tvo[j]++\n\t}\n\treturn string(vo)\n}\n\n// Start Firefox via the `web-ext` CLI tool. This is for development and testing,\n// because I haven't been able to recreate the way `web-ext` injects an unsigned\n// extension.\nfunc startWERFirefox() {\n\tslog.Info(\"Attempting to start headless Firefox with `web-ext`\")\n\tif IsConnectedToWebExtension {\n\t\tShutdown(errors.New(\"There appears to already be an existing Web Extension connection\"))\n\t}\n\tcheckIfFirefoxIsAlreadyRunning()\n\trootDir := Shell(\"git rev-parse --show-toplevel\")\n\targs := []string{\n\t\t\"run\",\n\t\t\"--firefox=\" + rootDir + \"/webext/contrib/firefoxheadless.sh\",\n\t\t\"--verbose\",\n\t\t\"--no-reload\",\n\t}\n\tfirefoxProcess := exec.Command(rootDir+\"/webext/node_modules/.bin/web-ext\", args...)\n\tfirefoxProcess.Dir = rootDir + \"/webext/dist/\"\n\tstdout, err := firefoxProcess.StdoutPipe()\n\tif err != nil {\n\t\tShutdown(err)\n\t}\n\tif err := firefoxProcess.Start(); err != nil {\n\t\tShutdown(err)\n\t}","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/browsh-org/browsh/blob/499ef386d45cd1e2b5457dd04887c017f77b7e27/interfacer/src/browsh/firefox.go#L146-L182","documentation":"`startWERFirefox` launches Firefox through the `web-ext` CLI tool, which browsh uses for development and testing. Before launching it checks browsh's `IsConnectedToWebExtension` flag; if a Web Extension is already attached, starting another web-ext instance would create a second connection, so browsh calls `Shutdown` with this error.","triggerScenarios":"Calling `StartFirefox` with the web-ext runner (`startWERFirefox`) while `IsConnectedToWebExtension` is true — i.e. a Web Extension already connected to browsh's websocket, typically from a previously started Firefox that is still running.","commonSituations":"Running browsh in dev mode (`web-ext`) twice without killing the first instance; an existing headless Firefox from a prior run still holds the extension connection; restarting only part of the dev stack.","solutions":["Kill the already-running browsh/Firefox dev instance before starting again.","Restart the whole browsh process so `IsConnectedToWebExtension` resets to false.","In scripts, wait for the previous web-ext Firefox to exit before relaunching.","Check for orphaned web-ext processes: `pgrep -fa web-ext`."],"exampleFix":"// before (dev workflow)\n./bin/browsh  # second invocation -> existing Web Extension connection\n// after\npkill -f 'web-ext' ; pkill -f 'firefox.*--headless'\n./bin/browsh","handlingStrategy":"validation","validationCode":"if (execSync('pgrep -fa web-ext || true').toString().trim() !== '') {\n  throw new Error('A web-ext/Firefox dev instance is already running');\n}","typeGuard":null,"tryCatchPattern":"try {\n  startBrowshDev();\n} catch (e) {\n  if (/already be an existing Web Extension connection/.test(e.message)) {\n    execSync('pkill -f web-ext');\n    startBrowshDev();\n  } else { throw e; }\n}","preventionTips":["Run only one browsh dev (web-ext) instance at a time.","Restart the full dev stack rather than partial components.","Kill leftover web-ext/Firefox processes before re-running dev scripts.","Serialize dev-mode invocations in test harnesses."],"tags":["firefox","webextension","dev-mode","startup"],"backgroundTag":"duplicate-webextension-connection","analyzedSha":"499ef386d45cd1e2b5457dd04887c017f77b7e27","analyzedAt":"2026-09-02T19:05:32.228Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}