Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix(browsers): discover Chrome on Windows

Darshan Jaindbce448eec9a
diff --git a/internal/browserprobe/binary.go b/internal/browserprobe/binary.go
index f074244c..242d32bb 100644
--- a/internal/browserprobe/binary.go
+++ b/internal/browserprobe/binary.go
@@ -27,7 +27,7 @@ func DiscoverBinary(names, paths []string) BinaryDiscovery {
if err != nil || info.IsDir() {
continue
}
- if info.Mode()&0o111 == 0 {
+ if !IsExecutable(info, p) {
continue
}
return BinaryDiscovery{Found: p, Probed: probed}
diff --git a/internal/browserprobe/executable_other.go b/internal/browserprobe/executable_other.go
new file mode 100644
index 00000000..357d80df
--- /dev/null
+++ b/internal/browserprobe/executable_other.go
@@ -0,0 +1,11 @@
+//go:build !windows
+
+package browserprobe
+
+import "io/fs"
+
+// IsExecutable reports whether a probed path is runnable. On unix that is the
+// mode bits.
+func IsExecutable(info fs.FileInfo, _ string) bool {
+ return info.Mode()&0o111 != 0
+}
diff --git a/internal/browserprobe/executable_test.go b/internal/browserprobe/executable_test.go
new file mode 100644
index 00000000..d5208b7c
--- /dev/null
+++ b/internal/browserprobe/executable_test.go
@@ -0,0 +1,55 @@
+package browserprobe
+
+import (
+ "os"
+ "path/filepath"
+ "runtime"
+ "testing"
+)
+
+// A browser at a common install path must be discovered without being on PATH.
+// On Windows this failed for every candidate: os.Stat reports no execute bits
+// there, so the mode check rejected the whole per-OS fallback list and PinchTab
+// reported "no chrome browser found on this host" on machines with Chrome
+// installed at the default location.
+func TestDiscoverBinaryAcceptsPlatformExecutableFallback(t *testing.T) {
+ dir := t.TempDir()
+ name := "fallback-browser"
+ if runtime.GOOS == "windows" {
+ name += ".exe"
+ }
+ fallback := filepath.Join(dir, name)
+ if err := os.WriteFile(fallback, []byte("#!/bin/sh\n"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ t.Setenv("PATH", t.TempDir())
+
+ got := DiscoverBinary([]string{"definitely-not-installed"}, []string{fallback})
+ if got.Found != fallback {
+ t.Fatalf("Found = %q, want %q (probed %v)", got.Found, fallback, got.Probed)
+ }
+}
+
+func TestIsExecutableRejectsNonExecutableCandidates(t *testing.T) {
+ dir := t.TempDir()
+
+ // A name the platform would not run: no extension on Windows, no mode bits
+ // on unix.
+ name := "not-a-program"
+ perm := os.FileMode(0o644)
+ if runtime.GOOS == "windows" {
+ name = "not-a-program.txt"
+ perm = 0o666
+ }
+ path := filepath.Join(dir, name)
+ if err := os.WriteFile(path, []byte("data"), perm); err != nil {
+ t.Fatal(err)
+ }
+ info, err := os.Stat(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if IsExecutable(info, path) {
+ t.Fatalf("IsExecutable(%q) = true, want false", path)
+ }
+}
diff --git a/internal/browserprobe/executable_windows.go b/internal/browserprobe/executable_windows.go
new file mode 100644
index 00000000..d71307e3
--- /dev/null
+++ b/internal/browserprobe/executable_windows.go
@@ -0,0 +1,39 @@
+//go:build windows
+
+package browserprobe
+
+import (
+ "io/fs"
+ "os"
+ "path/filepath"
+ "strings"
+)
+
+// defaultPATHEXT mirrors the Windows default when the environment does not set
+// PATHEXT. Only the extensions that can name a browser launcher matter here.
+const defaultPATHEXT = ".COM;.EXE;.BAT;.CMD"
+
+// IsExecutable reports whether a probed path is runnable.
+//
+// Windows has no execute permission bit: os.Stat reports every readable file as
+// -rw-rw-rw-, so a unix-style mode check rejects every candidate. Chrome's
+// installer does not put chrome.exe on PATH, which left the entire per-OS
+// fallback list in chrome.CommonPaths("windows") unreachable — PinchTab reported
+// "no chrome browser found on this host" on machines with Chrome installed at the
+// default location. Decide by extension instead, the same way exec.LookPath does.
+func IsExecutable(_ fs.FileInfo, path string) bool {
+ ext := strings.ToLower(filepath.Ext(path))
+ if ext == "" {
+ return false
+ }
+ pathExt := os.Getenv("PATHEXT")
+ if strings.TrimSpace(pathExt) == "" {
+ pathExt = defaultPATHEXT
+ }
+ for _, candidate := range strings.Split(pathExt, ";") {
+ if strings.ToLower(strings.TrimSpace(candidate)) == ext {
+ return true
+ }
+ }
+ return false
+}
diff --git a/internal/browserprobe/version.go b/internal/browserprobe/version.go
index 79569b5d..99770cba 100644
--- a/internal/browserprobe/version.go
+++ b/internal/browserprobe/version.go
@@ -22,6 +22,12 @@ import (
const FallbackChromeVersion = "144.0.7559.133"
func RunVersion(ctx context.Context, binary string) (string, error) {
+ // Some platforms cannot answer this by execution; prefer the install layout
+ // where one is available. See versionFromInstallLayout.
+ if v := versionFromInstallLayout(binary); v != "" {
+ return v, nil
+ }
+
cctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
out, err := exec.CommandContext(cctx, binary, "--version").CombinedOutput()
diff --git a/internal/browserprobe/version_other.go b/internal/browserprobe/version_other.go
new file mode 100644
index 00000000..493e0e97
--- /dev/null
+++ b/internal/browserprobe/version_other.go
@@ -0,0 +1,7 @@
+//go:build !windows
+
+package browserprobe
+
+// versionFromInstallLayout has no unix implementation: `chrome --version` prints
+// the version on stdout there, so RunVersion's exec probe is authoritative.
+func versionFromInstallLayout(string) string { return "" }
diff --git a/internal/browserprobe/version_windows.go b/internal/browserprobe/version_windows.go
new file mode 100644
index 00000000..2190b011
--- /dev/null
+++ b/internal/browserprobe/version_windows.go
@@ -0,0 +1,43 @@
+//go:build windows
+
+package browserprobe
+
+import (
+ "os"
+ "path/filepath"
+)
+
+// versionFromInstallLayout reads Chrome's version from its install layout instead
+// of running the binary.
+//
+// On Windows `chrome.exe --version` does not print a version: it hands the
+// arguments to the already-running browser and prints "Opening in existing browser
+// session.", so the exec probe both fails to parse AND pops a browser window open
+// during `pinchtab doctor`. Chrome's installer always places a versioned directory
+// beside chrome.exe:
+//
+// C:\Program Files\Google\Chrome\Application\chrome.exe
+// C:\Program Files\Google\Chrome\Application\151.0.7922.175\
+//
+// Read that name. Returns "" when the layout does not match, which leaves
+// RunVersion's exec probe as the fallback.
+func versionFromInstallLayout(binary string) string {
+ entries, err := os.ReadDir(filepath.Dir(binary))
+ if err != nil {
+ return ""
+ }
+ best := ""
+ for _, e := range entries {
+ if !e.IsDir() {
+ continue
+ }
+ name := e.Name()
+ if !hasDottedDigits(name) {
+ continue
+ }
+ if best == "" || CompareSemver(name, best) > 0 {
+ best = name
+ }
+ }
+ return best
+}
diff --git a/internal/browsers/chrome/chrome.go b/internal/browsers/chrome/chrome.go
index 40883f00..9944ae8d 100644
--- a/internal/browsers/chrome/chrome.go
+++ b/internal/browsers/chrome/chrome.go
@@ -62,15 +62,66 @@ func CommonPaths(goos string) []string {
primaryChromeAppMacOS,
}
case "windows":
- return []string{
- `C:\Program Files\Google\Chrome\Application\chrome.exe`,
- `C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`,
- }
+ return windowsChromePaths()
default:
return nil
}
}
+// windowsInstallRoots are the directory roots probed for a Chrome install, in
+// preference order. The values come from the environment so a non-C: system
+// drive or a redirected profile still resolves; the literals are the documented
+// defaults and only apply when the variable is unset (which is the case when
+// CommonPaths("windows") is called from a test on another OS).
+func windowsInstallRoots() []string {
+ roots := []string{
+ envOr("ProgramFiles", `C:\Program Files`),
+ envOr("ProgramFiles(x86)", `C:\Program Files (x86)`),
+ }
+ // %LOCALAPPDATA% is where Chrome's installer puts the browser when it runs
+ // without administrator rights, which is the common case on managed machines.
+ // There is no useful default for it, so it is only probed when set.
+ if local := os.Getenv("LOCALAPPDATA"); local != "" {
+ roots = append(roots, local)
+ }
+ return roots
+}
+
+// windowsChromeRelativePaths are the per-install-root executable locations, in
+// preference order: stable Chrome first, then the dedicated automation builds,
+// then the pre-release channels.
+var windowsChromeRelativePaths = []string{
+ `Google\Chrome\Application\chrome.exe`,
+ `Google\Chrome for Testing\Application\chrome.exe`,
+ `Chromium\Application\chrome.exe`,
+ `Google\Chrome Beta\Application\chrome.exe`,
+ `Google\Chrome SxS\Application\chrome.exe`,
+}
+
+// windowsChromePaths returns the Chrome/Chromium locations probed after PATH
+// misses. Chrome's Windows installer does not add chrome.exe to PATH, so this
+// list is the only way discovery succeeds on a default install.
+func windowsChromePaths() []string {
+ roots := windowsInstallRoots()
+ paths := make([]string, 0, len(roots)*len(windowsChromeRelativePaths))
+ for _, rel := range windowsChromeRelativePaths {
+ for _, root := range roots {
+ // Joined with a literal separator rather than filepath.Join: CommonPaths
+ // takes goos as a parameter, so it must produce Windows paths even when
+ // it is called from a test running on another OS.
+ paths = append(paths, strings.TrimRight(root, `\`)+`\`+rel)
+ }
+ }
+ return paths
+}
+
+func envOr(key, fallback string) string {
+ if v := os.Getenv(key); v != "" {
+ return v
+ }
+ return fallback
+}
+
func existingExtensionPaths(paths []string) []string {
if len(paths) == 0 {
return nil
diff --git a/internal/browsers/chrome/chrome_test.go b/internal/browsers/chrome/chrome_test.go
index 81e3e091..a27c55a9 100644
--- a/internal/browsers/chrome/chrome_test.go
+++ b/internal/browsers/chrome/chrome_test.go
@@ -580,7 +580,8 @@ func TestChrome_ValidateTarget(t *testing.T) {
// chrome/chromium found" FAIL while the binary_* checks pass right below it.
func TestChromePresentHonorsBrowserBinaryOverride(t *testing.T) {
if runtime.GOOS == "windows" {
- t.Skip("chrome_present is skipped on windows")
+ t.Skip("the override stub is a shell script; the windows path is covered by " +
+ "TestChromePresent_ProducesAVerdictOnWindows in internal/doctor")
}
dir := t.TempDir()
fake := filepath.Join(dir, "fakechrome")
diff --git a/internal/browsers/chrome/chrome_windows_paths_test.go b/internal/browsers/chrome/chrome_windows_paths_test.go
new file mode 100644
index 00000000..1183e1a4
--- /dev/null
+++ b/internal/browsers/chrome/chrome_windows_paths_test.go
@@ -0,0 +1,63 @@
+package chrome_test
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/pinchtab/pinchtab/internal/browsers/chrome"
+)
+
+// The Windows list used to be two hardcoded C:\Program Files paths. Chrome's
+// installer puts the browser under %LOCALAPPDATA% whenever it runs without
+// administrator rights — the common case on managed machines — and neither that
+// nor the dedicated automation builds were probed.
+func TestWindowsCommonPathsCoverPerUserAndAutomationInstalls(t *testing.T) {
+ t.Setenv("ProgramFiles", `D:\Progs`)
+ t.Setenv("LOCALAPPDATA", `D:\Users\alice\AppData\Local`)
+
+ paths := chrome.CommonPaths("windows")
+ if len(paths) == 0 {
+ t.Fatal("windows CommonPaths empty")
+ }
+
+ for _, want := range []string{
+ `D:\Users\alice\AppData\Local\Google\Chrome\Application\chrome.exe`,
+ `D:\Progs\Google\Chrome\Application\chrome.exe`,
+ `Google\Chrome for Testing\Application\chrome.exe`,
+ `Chromium\Application\chrome.exe`,
+ } {
+ if !containsSubstring(paths, want) {
+ t.Errorf("windows CommonPaths missing %q; got %v", want, paths)
+ }
+ }
+
+ // Stable Chrome stays ahead of the pre-release channels.
+ stable := indexOfSubstring(paths, `Google\Chrome\Application\chrome.exe`)
+ canary := indexOfSubstring(paths, `Google\Chrome SxS\Application\chrome.exe`)
+ if stable < 0 || canary < 0 || stable > canary {
+ t.Errorf("stable Chrome should precede Canary; stable=%d canary=%d in %v", stable, canary, paths)
+ }
+}
+
+// CommonPaths takes goos as a parameter, so it must emit Windows-shaped paths
+// even when the test runs on another OS.
+func TestWindowsCommonPathsUseBackslashesOnAnyHost(t *testing.T) {
+ for _, p := range chrome.CommonPaths("windows") {
+ if strings.Contains(p, "/") {
+ t.Fatalf("windows path contains a forward slash: %q", p)
+ }
+ }
+}
+
+func containsSubstring(haystack []string, needle string) bool {
+ return indexOfSubstring(haystack, needle) >= 0
+}
+
+func indexOfSubstring(haystack []string, needle string) int {
+ for i, h := range haystack {
+ if strings.Contains(h, needle) {
+ return i
+ }
+ }
+ return -1
+}
diff --git a/internal/browsers/chrome/doctor.go b/internal/browsers/chrome/doctor.go
index 4cb53c27..18540722 100644
--- a/internal/browsers/chrome/doctor.go
+++ b/internal/browsers/chrome/doctor.go
@@ -63,12 +63,6 @@ func chromePresenceCheck(ctx context.Context, cfg interface{}) browsers.DoctorCh
}
overridden := override != ""
- if runtime.GOOS == "windows" {
- return browsers.DoctorCheckResult{
- Status: browsers.DoctorSkip,
- Detail: "chrome discovery not implemented on windows",
- }
- }
found := override
if found == "" {
d := browserprobe.DiscoverBinary(BinaryNames(), CommonPaths(runtime.GOOS))
@@ -76,8 +70,8 @@ func chromePresenceCheck(ctx context.Context, cfg interface{}) browsers.DoctorCh
if found == "" {
return browsers.DoctorCheckResult{
Status: browsers.DoctorFail,
- Detail: "no chrome/chromium found. Install Chrome/Chromium (e.g. Google Chrome " +
- "for Testing, or `apt-get install -y chromium` on Debian/Ubuntu) or set " +
+ Detail: "no chrome/chromium found. Install Chrome/Chromium (" +
+ browsers.InstallHint(runtime.GOOS) + ") or set " +
"browser.binary to an existing build. Probed: " + strings.Join(d.Probed, ", "),
}
}
diff --git a/internal/browsers/cloak/doctor.go b/internal/browsers/cloak/doctor.go
index e387feaf..cc98520e 100644
--- a/internal/browsers/cloak/doctor.go
+++ b/internal/browsers/cloak/doctor.go
@@ -76,12 +76,6 @@ func (Browser) DoctorChecks(_ browsers.TargetConfig) []browsers.DoctorCheck {
}
func cloakPresenceCheck(ctx context.Context, cfg interface{}) browsers.DoctorCheckResult {
- if runtime.GOOS == "windows" {
- return browsers.DoctorCheckResult{
- Status: browsers.DoctorSkip,
- Detail: "cloakbrowser discovery not implemented on windows",
- }
- }
// An explicit browser.binary override is what the runtime launches, so resolve
// against it before falling back to discovery. The CloakBrowser installer drops
// its Chromium in a versioned dir that isn't on the static probe list, so without
diff --git a/internal/browsers/installhint.go b/internal/browsers/installhint.go
new file mode 100644
index 00000000..239426f8
--- /dev/null
+++ b/internal/browsers/installhint.go
@@ -0,0 +1,22 @@
+package browsers
+
+// InstallHint returns the platform-appropriate way to obtain a Chrome/Chromium
+// build, for use in "no browser found" diagnostics.
+//
+// The advice used to be `apt-get install -y chromium` unconditionally, which is
+// wrong on the two platforms where a user is most likely to hit it: PinchTab
+// publishes windows and darwin binaries, and a blocked operator on either one was
+// handed a Debian command.
+func InstallHint(goos string) string {
+ switch goos {
+ case "linux":
+ return "`apt-get install -y chromium` on Debian/Ubuntu, or install Google Chrome for Testing"
+ case "darwin":
+ return "`brew install --cask chromium`, or install Google Chrome for Testing " +
+ "(preferred over your daily Chrome for automation)"
+ case "windows":
+ return "`winget install Google.Chrome`, or download Google Chrome for Testing"
+ default:
+ return "install Google Chrome, Chromium, or Google Chrome for Testing"
+ }
+}
diff --git a/internal/doctor/checks_binary.go b/internal/doctor/checks_binary.go
index 66f1f075..f374ab5d 100644
--- a/internal/doctor/checks_binary.go
+++ b/internal/doctor/checks_binary.go
@@ -8,6 +8,7 @@ import (
"strings"
"time"
+ "github.com/pinchtab/pinchtab/internal/browserprobe"
"github.com/pinchtab/pinchtab/internal/config"
)
@@ -56,10 +57,13 @@ func checkBinaryExecutable(_ context.Context, cfg *config.RuntimeConfig) CheckRe
return CheckResult{Status: StatusFail, Detail: err.Error(), Err: err}
}
mode := info.Mode()
- if mode&0o111 == 0 {
+ // Executability is platform-specific: Windows has no execute bit and every file
+ // stats as -rw-rw-rw-, so a mode check fails every configured browser.binary
+ // there. browserprobe owns the one rule discovery also uses.
+ if !browserprobe.IsExecutable(info, bin) {
return CheckResult{
Status: StatusFail,
- Detail: fmt.Sprintf("file mode %#o has no executable bit", mode.Perm()),
+ Detail: fmt.Sprintf("file mode %#o is not executable on this platform", mode.Perm()),
}
}
return CheckResult{
diff --git a/internal/doctor/checks_system_test.go b/internal/doctor/checks_system_test.go
index 8e4d793e..64d6e317 100644
--- a/internal/doctor/checks_system_test.go
+++ b/internal/doctor/checks_system_test.go
@@ -212,13 +212,20 @@ func TestChromePresent_FailWhenAbsent(t *testing.T) {
}
}
-func TestChromePresent_SkipOnWindows(t *testing.T) {
+// Chrome discovery used to short-circuit to StatusSkip on Windows, so `pinchtab
+// doctor` answered "not implemented on windows" and told the user nothing on the
+// one platform where discovery was actually broken. It works now, so the check
+// must reach a real verdict rather than opting out.
+func TestChromePresent_ProducesAVerdictOnWindows(t *testing.T) {
if runtime.GOOS != "windows" {
- t.Skip("chrome provider skip-on-windows requires actual windows")
+ t.Skip("windows discovery behaviour requires actual windows")
}
r := runChromePresent(t)
- if r.Status != StatusSkip {
- t.Fatalf("status = %v want skip", r.Status)
+ if r.Status == StatusSkip {
+ t.Fatalf("chrome_present skipped on windows; want a real verdict. detail=%q", r.Detail)
+ }
+ if strings.Contains(r.Detail, "not implemented") {
+ t.Fatalf("detail still claims discovery is unimplemented: %q", r.Detail)
}
}
diff --git a/internal/doctor/runner_test.go b/internal/doctor/runner_test.go
index 9e4dd0c0..80217549 100644
--- a/internal/doctor/runner_test.go
+++ b/internal/doctor/runner_test.go
@@ -165,7 +165,13 @@ func TestBinaryExecutable_NotExecutable(t *testing.T) {
func TestBinaryExecutable_Executable(t *testing.T) {
dir := t.TempDir()
- path := filepath.Join(dir, "exec")
+ // Windows decides executability by extension, not mode bits, so the stub needs
+ // a name the platform would actually run.
+ name := "exec"
+ if runtime.GOOS == "windows" {
+ name = "exec.exe"
+ }
+ path := filepath.Join(dir, name)
if err := os.WriteFile(path, []byte("#!/bin/sh\n"), 0o755); err != nil {
t.Fatal(err)
}
diff --git a/internal/orchestrator/browser_preflight.go b/internal/orchestrator/browser_preflight.go
index db3aaa8a..011c28d8 100644
--- a/internal/orchestrator/browser_preflight.go
+++ b/internal/orchestrator/browser_preflight.go
@@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"os"
+ "runtime"
"strings"
"github.com/pinchtab/pinchtab/internal/browsers"
@@ -46,7 +47,8 @@ func (o *Orchestrator) BrowserUnavailableReason(r *http.Request) (string, bool)
}
if effective.Binary == "" {
return fmt.Sprintf("no %s browser found on this host — install Chrome/Chromium "+
- "(e.g. `apt-get install -y chromium`) or set a browser binary in config (run `pinchtab doctor`)", provider), true
+ "(%s) or set a browser binary in config (run `pinchtab doctor`)",
+ provider, browsers.InstallHint(runtime.GOOS)), true
}
return "", false
}