browsh-org/browsh · error

There appears to already be an existing Web Extension connec

Error message

There appears to already be an existing Web Extension connection

What it means

`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.

Source

Thrown at interfacer/src/browsh/firefox.go:164

			vo[j+1] = b
			continue
		}
		if vo[j]+1 > maxByte {
			panic("VersionOrdinal: invalid version")
		}
		vo = append(vo, b)
		vo[j]++
	}
	return string(vo)
}

// Start Firefox via the `web-ext` CLI tool. This is for development and testing,
// because I haven't been able to recreate the way `web-ext` injects an unsigned
// extension.
func startWERFirefox() {
	slog.Info("Attempting to start headless Firefox with `web-ext`")
	if IsConnectedToWebExtension {
		Shutdown(errors.New("There appears to already be an existing Web Extension connection"))
	}
	checkIfFirefoxIsAlreadyRunning()
	rootDir := Shell("git rev-parse --show-toplevel")
	args := []string{
		"run",
		"--firefox=" + rootDir + "/webext/contrib/firefoxheadless.sh",
		"--verbose",
		"--no-reload",
	}
	firefoxProcess := exec.Command(rootDir+"/webext/node_modules/.bin/web-ext", args...)
	firefoxProcess.Dir = rootDir + "/webext/dist/"
	stdout, err := firefoxProcess.StdoutPipe()
	if err != nil {
		Shutdown(err)
	}
	if err := firefoxProcess.Start(); err != nil {
		Shutdown(err)
	}

View on GitHub (pinned to 499ef386d4)

Solutions

  1. Kill the already-running browsh/Firefox dev instance before starting again.
  2. Restart the whole browsh process so `IsConnectedToWebExtension` resets to false.
  3. In scripts, wait for the previous web-ext Firefox to exit before relaunching.
  4. Check for orphaned web-ext processes: `pgrep -fa web-ext`.

Example fix

// before (dev workflow)
./bin/browsh  # second invocation -> existing Web Extension connection
// after
pkill -f 'web-ext' ; pkill -f 'firefox.*--headless'
./bin/browsh
Defensive patterns

Strategy: validation

Validate before calling

if (execSync('pgrep -fa web-ext || true').toString().trim() !== '') {
  throw new Error('A web-ext/Firefox dev instance is already running');
}

Try / catch

try {
  startBrowshDev();
} catch (e) {
  if (/already be an existing Web Extension connection/.test(e.message)) {
    execSync('pkill -f web-ext');
    startBrowshDev();
  } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of browsh-org/browsh@499ef386d4 (2026-09-02). Data as JSON: /api/errors/e3ae15ca0e4a2c89. Report an issue: GitHub.