browsh-org/browsh · error

Browsh tried to run `%s` but failed with: %s, err: %w

Error message

Browsh tried to run `%s` but failed with: %s, err: %w

What it means

`Shell` is browsh's helper for running external commands (`ps aux`, `git rev-parse`, `firefox --version`, etc.). When `exec.Command(...).CombinedOutput()` returns an error, browsh wraps the command, its combined output, and the underlying error via `%w` and calls `Shutdown`. Since core logic depends on these shell calls, any failure is fatal.

Source

Thrown at interfacer/src/browsh/browsh.go:124

	if err := file.Sync(); err != nil {
		Shutdown(err)
	}
	fullPath := file.Name() + ".jpg"
	if err := os.Rename(file.Name(), fullPath); err != nil {
		Shutdown(err)
	}
	message := "Screenshot saved to " + fullPath
	sendMessageToWebExtension("/status," + message)
}

// Shell provides nice and easy shell commands
func Shell(command string) string {
	parts := strings.Fields(command)
	head := parts[0]
	parts = parts[1:]
	out, err := exec.Command(head, parts...).CombinedOutput()
	if err != nil {
		err := fmt.Errorf(
			"Browsh tried to run `%s` but failed with: %s, err: %w",
			command,
			string(out),
			err,
		)
		Shutdown(err)
	}
	return strings.TrimSpace(string(out))
}

// TTYStart starts Browsh
func TTYStart(injectedScreen tcell.Screen) {
	screen = injectedScreen
	setupTcell()
	writeString(1, 0, logo, tcell.StyleDefault)
	writeString(
		0,
		15,

View on GitHub (pinned to 499ef386d4)

Solutions

  1. Read the wrapped output in the message to identify which command failed and why.
  2. Install the missing tool in the environment (e.g. `apt-get install -y procps git` in Debian slim images).
  3. For the web-ext dev path, run browsh from inside the browsh git repository so `git rev-parse --show-toplevel` succeeds.
  4. Ensure PATH includes /usr/bin, /bin, /usr/sbin etc. when launching browsh from a service or IDE.

Example fix

// before (Dockerfile, failing)
FROM debian:slim
RUN apt-get install -y firefox
// after
FROM debian:slim
RUN apt-get install -y firefox procps git ca-certificates
Defensive patterns

Strategy: try-catch

Validate before calling

const { execSync } = require('child_process');
for (const tool of ['ps', 'git']) {
  try { execSync(`command -v ${tool}`, { shell: '/bin/sh' }); }
  catch { throw new Error(`${tool} missing from PATH; install it (e.g. procps/git)`); }
}

Try / catch

try {
  startBrowsh();
} catch (e) {
  if (/Browsh tried to run/.test(e.message)) {
    // message contains the command, its output and the wrapped err
    console.error('Fix environment for failed shell command:', e.message);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Any caller (`checkIfFirefoxIsAlreadyRunning`, `startWERFirefox`, `getFirefoxPath`, `ensureFirefoxVersion`, `stopFirefox`) invokes a command whose binary is missing (PATH lookup fails), exits non-zero, or is unlaunchable — e.g. `ps` or `git` not installed in a slim container.

Common situations: Running browsh in a minimal Docker image without `ps` or `git`; `git rev-parse --show-toplevel` executed outside a git repo during web-ext dev mode; PATH lacking standard system directories when launched from a daemon/IDE; a Firefox path failing to execute with `--version`.


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