High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
refactor: rename ensureChrome to ensureBrowser and thread effective config
Luigi Agosti21c23195c7af
diff --git a/internal/bridge/bridge_lifecycle.go b/internal/bridge/bridge_lifecycle.goindex 338900ea..0fe6e2c6 100644--- a/internal/bridge/bridge_lifecycle.go+++ b/internal/bridge/bridge_lifecycle.go@@ -123,14 +123,25 @@ func (b *Bridge) StealthStatus() *stealth.Status {return stealth.StatusFromBundle(b.StealthBundle, b.Config, b.stealthLaunchMode)}-func (b *Bridge) EnsureChrome(cfg *config.RuntimeConfig) error {+func (b *Bridge) EnsureBrowser(cfg *config.RuntimeConfig) error {b.initMu.Lock()defer b.initMu.Unlock()+ if cfg == nil {+ cfg = b.Config+ }+ if cfg == nil {+ return fmt.Errorf("runtime config is required")+ }+if b.draining {return ErrBrowserDraining}+ if !b.initialized || b.BrowserCtx == nil || b.BrowserCtx.Err() != nil {+ b.prepareConfigForLaunch(cfg)+ }+if b.initialized && b.BrowserCtx != nil {if b.BrowserCtx.Err() == nil {return nil@@ -238,8 +249,24 @@ func (b *Bridge) EnsureChrome(cfg *config.RuntimeConfig) error {return nil}+func (b *Bridge) prepareConfigForLaunch(cfg *config.RuntimeConfig) {+ if cfg == nil || b.Config == cfg {+ return+ }+ b.Config = cfg+ b.StealthBundle = nil+ if b.netMonitor != nil {+ b.netMonitor.ConfigureBodyRetention(cfg.RetainNetworkBodies, cfg.RetainNetworkBodyMaxBytes)+ }+}++// EnsureChrome is the compatibility alias for older callers.+func (b *Bridge) EnsureChrome(cfg *config.RuntimeConfig) error {+ return b.EnsureBrowser(cfg)+}+// RestartBrowser performs a soft restart: drains in-flight requests, tears-// down Chrome contexts, and re-initializes via EnsureChrome.+// down browser contexts, and re-initializes via EnsureBrowser.func (b *Bridge) RestartBrowser(cfg *config.RuntimeConfig) error {if cfg == nil {cfg = b.Config@@ -325,7 +352,7 @@ func (b *Bridge) RestartBrowser(cfg *config.RuntimeConfig) error {b.drainUntil = time.Time{}b.initMu.Unlock()- if err := b.EnsureChrome(cfg); err != nil {+ if err := b.EnsureBrowser(cfg); err != nil {return err}b.CleanupSavedStateBackup()diff --git a/internal/browsers/ghostchrome/bridgekit/bridge_adapter.go b/internal/browsers/ghostchrome/bridgekit/bridge_adapter.goindex 4d731240..2d42d397 100644--- a/internal/browsers/ghostchrome/bridgekit/bridge_adapter.go+++ b/internal/browsers/ghostchrome/bridgekit/bridge_adapter.go@@ -62,7 +62,7 @@ func NewBridgeAdapter(chromeBridge bridge.BridgeAPI, cfg *config.RuntimeConfig)lite := staticfetch.NewBrowser()chromeAdapter := &chromeActionAdapter{BridgeAPI: chromeBridge}proxy := ghostchrome.NewBridgeProxy(chromeAdapter, lite, func() error {- return chromeBridge.EnsureChrome(cfg)+ return ensureBrowser(chromeBridge, cfg)})return &BridgeAdapter{BridgeAPI: chromeBridge,@@ -71,6 +71,23 @@ func NewBridgeAdapter(chromeBridge bridge.BridgeAPI, cfg *config.RuntimeConfig)}}+func ensureBrowser(b bridge.BridgeAPI, cfg *config.RuntimeConfig) error {+ if provider, ok := b.(interface {+ EnsureBrowser(*config.RuntimeConfig) error+ }); ok {+ return provider.EnsureBrowser(cfg)+ }+ return b.EnsureChrome(cfg)+}++func (a *BridgeAdapter) EnsureBrowser(cfg *config.RuntimeConfig) error {+ return ensureBrowser(a.BridgeAPI, cfg)+}++func (a *BridgeAdapter) EnsureChrome(cfg *config.RuntimeConfig) error {+ return a.EnsureBrowser(cfg)+}+func (a *BridgeAdapter) TabContext(tabID string) (*bridge.TabHandle, string, error) {ctx, resolvedID, err := a.proxy.TabContext(tabID)if err != nil {diff --git a/internal/handlers/action_execution.go b/internal/handlers/action_execution.goindex 7f136a3d..64e3f7f4 100644--- a/internal/handlers/action_execution.go+++ b/internal/handlers/action_execution.go@@ -8,6 +8,7 @@ import ("time""github.com/pinchtab/pinchtab/internal/bridge"+ "github.com/pinchtab/pinchtab/internal/config""github.com/pinchtab/semantic""github.com/pinchtab/semantic/recovery")@@ -40,11 +41,11 @@ func (h *Handlers) cacheActionIntent(tabID string, req bridge.ActionRequest) {})}-func (h *Handlers) executeAction(ctx context.Context, req bridge.ActionRequest) (map[string]any, string, error) {+func (h *Handlers) executeAction(ctx context.Context, req bridge.ActionRequest, cfg *config.RuntimeConfig) (map[string]any, string, error) {req.Kind = bridge.CanonicalActionKind(req.Kind)- if err := h.ensureChrome(); err != nil {- return nil, "", fmt.Errorf("chrome initialization: %w", err)+ if err := h.ensureBrowser(cfg); err != nil {+ return nil, "", fmt.Errorf("browser initialization: %w", err)}result, err := h.Bridge.ExecuteAction(ctx, req.Kind, req)return result, "", errdiff --git a/internal/handlers/actions.go b/internal/handlers/actions.goindex 2c0404fe..c0ec5dd6 100644--- a/internal/handlers/actions.go+++ b/internal/handlers/actions.go@@ -283,7 +283,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {tCtx, resolvedTabID, req.Ref, req.Kind,func(ctx context.Context, kind string, nodeID int64) (map[string]any, error) {req.NodeID = nodeID- res, _, err := h.executeAction(ctx, req)+ res, _, err := h.executeAction(ctx, req, effectiveCfg)return res, err},)@@ -297,7 +297,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {httpx.Error(w, 404, fmt.Errorf("ref %s not found - take a /snapshot first", req.Ref))return} else {- result, actionBackend, actionErr = h.executeAction(tCtx, req)+ result, actionBackend, actionErr = h.executeAction(tCtx, req, effectiveCfg)if actionErr != nil && shouldRetryPointerAction(req, actionErr) {if req.Ref != "" && shouldRetryStaleRef(actionErr) {recordStaleRefRetry()@@ -310,7 +310,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {}h.refreshActionNodeIDFromSelector(tCtx, &req)time.Sleep(pointerRetryDelay)- result, actionBackend, actionErr = h.executeAction(tCtx, req)+ result, actionBackend, actionErr = h.executeAction(tCtx, req, effectiveCfg)}// Semantic self-healing: if stale-ref retry still failed, attempt// recovery via the semantic matcher.@@ -320,7 +320,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {recovery.ClassifyFailure(actionErr),func(ctx context.Context, kind string, nodeID int64) (map[string]any, error) {req.NodeID = nodeID- res, _, err := h.executeAction(ctx, req)+ res, _, err := h.executeAction(ctx, req, effectiveCfg)return res, err},)@@ -643,7 +643,7 @@ func (h *Handlers) handleActionsBatch(w http.ResponseWriter, r *http.Request, retCtx, resolvedTabID, action.Ref, action.Kind,func(ctx context.Context, kind string, nodeID int64) (map[string]any, error) {action.NodeID = nodeID- res, _, err := h.executeAction(ctx, action)+ res, _, err := h.executeAction(ctx, action, effectiveCfg)return res, err},)@@ -664,7 +664,7 @@ func (h *Handlers) handleActionsBatch(w http.ResponseWriter, r *http.Request, re}continue} else {- actionRes, _, err = h.executeAction(tCtx, action)+ actionRes, _, err = h.executeAction(tCtx, action, effectiveCfg)if err != nil && shouldRetryPointerAction(action, err) {if action.Ref != "" && shouldRetryStaleRef(err) {recordStaleRefRetry()@@ -677,7 +677,7 @@ func (h *Handlers) handleActionsBatch(w http.ResponseWriter, r *http.Request, re}h.refreshActionNodeIDFromSelector(tCtx, &action)time.Sleep(pointerRetryDelay)- actionRes, _, err = h.executeAction(tCtx, action)+ actionRes, _, err = h.executeAction(tCtx, action, effectiveCfg)}// Semantic self-healing for batched actions.if err != nil && action.Ref != "" && h.Recovery != nil && h.Recovery.ShouldAttempt(err, action.Ref) {@@ -686,7 +686,7 @@ func (h *Handlers) handleActionsBatch(w http.ResponseWriter, r *http.Request, rerecovery.ClassifyFailure(err),func(ctx context.Context, kind string, nodeID int64) (map[string]any, error) {action.NodeID = nodeID- res, _, err := h.executeAction(ctx, action)+ res, _, err := h.executeAction(ctx, action, effectiveCfg)return res, err},)@@ -909,7 +909,7 @@ func (h *Handlers) HandleMacro(w http.ResponseWriter, r *http.Request) {tCtx, resolvedTabID, step.Ref, step.Kind,func(ctx context.Context, kind string, nodeID int64) (map[string]any, error) {step.NodeID = nodeID- res, _, err := h.executeAction(ctx, step)+ res, _, err := h.executeAction(ctx, step, macroEffectiveCfg)return res, err},)@@ -930,7 +930,7 @@ func (h *Handlers) HandleMacro(w http.ResponseWriter, r *http.Request) {}continue} else {- res, _, err = h.executeAction(tCtx, step)+ res, _, err = h.executeAction(tCtx, step, macroEffectiveCfg)if err != nil && shouldRetryPointerAction(step, err) {if step.Ref != "" && shouldRetryStaleRef(err) {recordStaleRefRetry()@@ -943,7 +943,7 @@ func (h *Handlers) HandleMacro(w http.ResponseWriter, r *http.Request) {}h.refreshActionNodeIDFromSelector(tCtx, &step)time.Sleep(pointerRetryDelay)- res, _, err = h.executeAction(tCtx, step)+ res, _, err = h.executeAction(tCtx, step, macroEffectiveCfg)}// Semantic self-healing for macro steps.if err != nil && step.Ref != "" && h.Recovery != nil && h.Recovery.ShouldAttempt(err, step.Ref) {@@ -952,7 +952,7 @@ func (h *Handlers) HandleMacro(w http.ResponseWriter, r *http.Request) {recovery.ClassifyFailure(err),func(ctx context.Context, kind string, nodeID int64) (map[string]any, error) {step.NodeID = nodeID- res, _, err := h.executeAction(ctx, step)+ res, _, err := h.executeAction(ctx, step, macroEffectiveCfg)return res, err},)diff --git a/internal/handlers/attr.go b/internal/handlers/attr.goindex dfa6ddbf..85bf56a2 100644--- a/internal/handlers/attr.go+++ b/internal/handlers/attr.go@@ -33,7 +33,7 @@ func (h *Handlers) HandleGetAttr(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/box.go b/internal/handlers/box.goindex 0042934e..516dea6e 100644--- a/internal/handlers/box.go+++ b/internal/handlers/box.go@@ -37,7 +37,7 @@ func (h *Handlers) HandleGetBox(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/cache.go b/internal/handlers/cache.goindex ae7e6312..243feca8 100644--- a/internal/handlers/cache.go+++ b/internal/handlers/cache.go@@ -11,7 +11,7 @@ import (// HandleCacheClear clears the browser's HTTP disk cache.// POST /cache/clearfunc (h *Handlers) HandleCacheClear(w http.ResponseWriter, r *http.Request) {- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {httpx.Error(w, http.StatusServiceUnavailable, err)return}@@ -33,7 +33,7 @@ func (h *Handlers) HandleCacheClear(w http.ResponseWriter, r *http.Request) {// HandleCacheStatus checks if the browser cache can be cleared.// GET /cache/statusfunc (h *Handlers) HandleCacheStatus(w http.ResponseWriter, r *http.Request) {- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {httpx.Error(w, http.StatusServiceUnavailable, err)return}diff --git a/internal/handlers/capture.go b/internal/handlers/capture.goindex 06df2d64..b314d8cb 100644--- a/internal/handlers/capture.go+++ b/internal/handlers/capture.go@@ -113,11 +113,11 @@ func (h *Handlers) HandleCapture(w http.ResponseWriter, r *http.Request) {}h.recordActivity(r, activity.Update{Route: captureRoute})- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(effectiveCfg); err != nil {if h.writeBridgeUnavailable(w, err) {return}- httpx.Error(w, 500, fmt.Errorf("chrome initialization: %w", err))+ httpx.Error(w, 500, fmt.Errorf("browser initialization: %w", err))return}diff --git a/internal/handlers/checked.go b/internal/handlers/checked.goindex 4a2bd070..bd9d3008 100644--- a/internal/handlers/checked.go+++ b/internal/handlers/checked.go@@ -26,7 +26,7 @@ func (h *Handlers) HandleGetChecked(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/cookies.go b/internal/handlers/cookies.goindex aee4f153..4aa6696c 100644--- a/internal/handlers/cookies.go+++ b/internal/handlers/cookies.go@@ -141,7 +141,7 @@ func (h *Handlers) HandleClearCookies(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {httpx.Error(w, http.StatusServiceUnavailable, err)return}diff --git a/internal/handlers/count.go b/internal/handlers/count.goindex 46fbe5de..e7ef4f46 100644--- a/internal/handlers/count.go+++ b/internal/handlers/count.go@@ -28,7 +28,7 @@ func (h *Handlers) HandleCount(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/enabled.go b/internal/handlers/enabled.goindex acd0194e..08a87a63 100644--- a/internal/handlers/enabled.go+++ b/internal/handlers/enabled.go@@ -26,7 +26,7 @@ func (h *Handlers) HandleGetEnabled(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/find.go b/internal/handlers/find.goindex e415b488..ee6f1443 100644--- a/internal/handlers/find.go+++ b/internal/handlers/find.go@@ -54,7 +54,7 @@ type findResponse struct {// @Response 404 application/json Tab not found// @Response 500 application/json Snapshot or matching errorfunc (h *Handlers) HandleFind(w http.ResponseWriter, r *http.Request) {- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.goindex 68e40bd6..d8df5f16 100644--- a/internal/handlers/handlers.go+++ b/internal/handlers/handlers.go@@ -154,17 +154,26 @@ type restartStatusProvider interface {RestartStatus() (bool, time.Duration)}-// ensureChrome ensures Chrome is initialized before handling requests that need it-func (h *Handlers) ensureChrome() error {- return h.Bridge.EnsureChrome(h.Config)+type ensureBrowserProvider interface {+ EnsureBrowser(cfg *config.RuntimeConfig) error}-func (h *Handlers) ensureChromeOrRespond(w http.ResponseWriter) bool {- if err := h.ensureChrome(); err != nil {+func (h *Handlers) ensureBrowser(cfg *config.RuntimeConfig) error {+ if cfg == nil {+ cfg = h.Config+ }+ if provider, ok := h.Bridge.(ensureBrowserProvider); ok {+ return provider.EnsureBrowser(cfg)+ }+ return h.Bridge.EnsureChrome(cfg)+}++func (h *Handlers) ensureBrowserOrRespond(w http.ResponseWriter, cfg *config.RuntimeConfig) bool {+ if err := h.ensureBrowser(cfg); err != nil {if h.writeBridgeUnavailable(w, err) {return false}- httpx.Error(w, 500, fmt.Errorf("chrome initialization: %w", err))+ httpx.Error(w, 500, fmt.Errorf("browser initialization: %w", err))return false}return truediff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.goindex 16ab1823..fa394212 100644--- a/internal/handlers/handlers_test.go+++ b/internal/handlers/handlers_test.go@@ -27,6 +27,7 @@ type mockBridge struct {frameScopes map[string]bridge.FrameScopeensureChromeErr errorensureChromeCall int+ ensureChromeCfg *config.RuntimeConfigdialogManager *bridge.DialogManagerexecuteActionErr errorautoCloseArmed []string@@ -91,6 +92,7 @@ func (m *mockBridge) CancelAutoClose(tabID string) {func (m *mockBridge) EnsureChrome(cfg *config.RuntimeConfig) error {m.ensureChromeCall+++ m.ensureChromeCfg = cfgreturn m.ensureChromeErr}diff --git a/internal/handlers/health_tabs.go b/internal/handlers/health_tabs.goindex 28a1100d..cde7c323 100644--- a/internal/handlers/health_tabs.go+++ b/internal/handlers/health_tabs.go@@ -28,7 +28,7 @@ func (h *Handlers) HandleHealth(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}@@ -58,7 +58,7 @@ func (h *Handlers) HandleHealth(w http.ResponseWriter, r *http.Request) {}func (h *Handlers) HandleEnsureChrome(w http.ResponseWriter, r *http.Request) {- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/history.go b/internal/handlers/history.goindex 2ca6a1c7..1b1e2280 100644--- a/internal/handlers/history.go+++ b/internal/handlers/history.go@@ -33,7 +33,7 @@ func (h *Handlers) HandleTabReload(w http.ResponseWriter, r *http.Request) {// HandleBack navigates the current (or specified) tab back in history.func (h *Handlers) HandleBack(w http.ResponseWriter, r *http.Request) {- if !h.ensureChromeOrRespond(w) {+ if !h.ensureBrowserOrRespond(w, h.Config) {return}tabID := r.URL.Query().Get("tabId")@@ -60,7 +60,7 @@ func (h *Handlers) HandleBack(w http.ResponseWriter, r *http.Request) {// HandleForward navigates the current (or specified) tab forward in history.func (h *Handlers) HandleForward(w http.ResponseWriter, r *http.Request) {- if !h.ensureChromeOrRespond(w) {+ if !h.ensureBrowserOrRespond(w, h.Config) {return}tabID := r.URL.Query().Get("tabId")@@ -87,7 +87,7 @@ func (h *Handlers) HandleForward(w http.ResponseWriter, r *http.Request) {// HandleReload reloads the current (or specified) tab.func (h *Handlers) HandleReload(w http.ResponseWriter, r *http.Request) {- if !h.ensureChromeOrRespond(w) {+ if !h.ensureBrowserOrRespond(w, h.Config) {return}tabID := r.URL.Query().Get("tabId")diff --git a/internal/handlers/inspect.go b/internal/handlers/inspect.goindex 0e9ec2d9..1f1c8ec5 100644--- a/internal/handlers/inspect.go+++ b/internal/handlers/inspect.go@@ -74,7 +74,7 @@ func (h *Handlers) handleInspect(w http.ResponseWriter, r *http.Request, kind intabID := r.URL.Query().Get("tabId")h.recordReadRequest(r, string(kind), tabID)- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/navigation.go b/internal/handlers/navigation.goindex 53622e1e..0d409f5b 100644--- a/internal/handlers/navigation.go+++ b/internal/handlers/navigation.go@@ -191,7 +191,7 @@ func (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {}h.recordActivity(r, activity.Update{Route: navRoute})- if !h.ensureChromeOrRespond(w) {+ if !h.ensureBrowserOrRespond(w, effectiveCfg) {return}diff --git a/internal/handlers/navigation_browser_test.go b/internal/handlers/navigation_browser_test.goindex 88f501a6..2a2a4eaf 100644--- a/internal/handlers/navigation_browser_test.go+++ b/internal/handlers/navigation_browser_test.go@@ -43,6 +43,39 @@ func TestHandleNavigate_BrowserParam_Valid(t *testing.T) {}}+func TestHandleNavigate_EnsuresResolvedBrowserTargetConfig(t *testing.T) {+ m := &mockBridge{}+ h := New(m, &config.RuntimeConfig{+ DefaultBrowser: config.BrowserChrome,+ BrowsersAvailable: []string{"chrome", "cloak"},+ ChromeBinary: "/usr/bin/chrome",+ Targets: config.BrowserTargetsConfig{+ "cloak-local": {+ Provider: config.BrowserCloak,+ Binary: "/opt/cloakbrowser/chrome",+ },+ },+ }, nil, nil, nil)++ body := []byte(`{"url":"about:blank","browser":"cloak"}`)+ req := httptest.NewRequest("POST", "/navigate", bytes.NewReader(body))+ w := httptest.NewRecorder()+ h.HandleNavigate(w, req)++ if m.ensureChromeCall != 1 {+ t.Fatalf("expected startup to be ensured once, got %d", m.ensureChromeCall)+ }+ if m.ensureChromeCfg == nil {+ t.Fatal("expected startup config to be recorded")+ }+ if m.ensureChromeCfg.DefaultBrowser != config.BrowserCloak {+ t.Fatalf("DefaultBrowser = %q, want %q", m.ensureChromeCfg.DefaultBrowser, config.BrowserCloak)+ }+ if m.ensureChromeCfg.ChromeBinary != "/opt/cloakbrowser/chrome" {+ t.Fatalf("ChromeBinary = %q, want target binary", m.ensureChromeCfg.ChromeBinary)+ }+}+func TestHandleNavigate_BrowserParam_Invalid_Returns400(t *testing.T) {h := New(&mockBridge{}, &config.RuntimeConfig{BrowsersAvailable: []string{"chrome"},diff --git a/internal/handlers/navigation_test.go b/internal/handlers/navigation_test.goindex a29a8bbd..948a5dfe 100644--- a/internal/handlers/navigation_test.go+++ b/internal/handlers/navigation_test.go@@ -51,8 +51,8 @@ func TestHandleNavigate_EnsureChromeFailureStopsBeforeCreateTab(t *testing.T) {if len(m.createTabURLs) != 0 {t.Fatalf("CreateTab should not be called when EnsureChrome fails, got %v", m.createTabURLs)}- if !strings.Contains(w.Body.String(), "chrome initialization") {- t.Fatalf("expected chrome initialization error, got %s", w.Body.String())+ if !strings.Contains(w.Body.String(), "browser initialization") {+ t.Fatalf("expected browser initialization error, got %s", w.Body.String())}}@@ -73,8 +73,8 @@ func TestHandleTab_EnsureChromeFailureStopsBeforeCreateTab(t *testing.T) {if len(m.createTabURLs) != 0 {t.Fatalf("CreateTab should not be called when EnsureChrome fails, got %v", m.createTabURLs)}- if !strings.Contains(w.Body.String(), "chrome initialization") {- t.Fatalf("expected chrome initialization error, got %s", w.Body.String())+ if !strings.Contains(w.Body.String(), "browser initialization") {+ t.Fatalf("expected browser initialization error, got %s", w.Body.String())}}diff --git a/internal/handlers/network.go b/internal/handlers/network.goindex c0246fee..788922af 100644--- a/internal/handlers/network.go+++ b/internal/handlers/network.go@@ -155,7 +155,7 @@ func populateLiveBodyResult(result map[string]any, body string, base64Encoded bo// @Response 200 application/json List of network entries// @Response 404 application/json Tab not foundfunc (h *Handlers) HandleNetwork(w http.ResponseWriter, r *http.Request) {- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}@@ -229,7 +229,7 @@ func (h *Handlers) HandleNetwork(w http.ResponseWriter, r *http.Request) {// @Response 200 application/json Network entry details// @Response 404 application/json Request not foundfunc (h *Handlers) HandleNetworkByID(w http.ResponseWriter, r *http.Request) {- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}@@ -369,7 +369,7 @@ func (h *Handlers) HandleNetworkStream(w http.ResponseWriter, r *http.Request) {// (e.g. httptest.ResponseRecorder doesn't support this)._ = http.NewResponseController(w).SetWriteDeadline(time.Time{})- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/network_export.go b/internal/handlers/network_export.goindex 9008e0c5..1a077936 100644--- a/internal/handlers/network_export.go+++ b/internal/handlers/network_export.go@@ -72,7 +72,7 @@ func CleanupStaleTmpExports(stateDir string) {// @Response 423 application/json Tab is locked// @Response 500 application/json Export errorfunc (h *Handlers) HandleNetworkExport(w http.ResponseWriter, r *http.Request) {- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/network_export_stream.go b/internal/handlers/network_export_stream.goindex 9a3a2b4b..4e5406d5 100644--- a/internal/handlers/network_export_stream.go+++ b/internal/handlers/network_export_stream.go@@ -30,7 +30,7 @@ import (// @Response 200 text/event-stream SSE progress events// @Response 423 application/json Tab is lockedfunc (h *Handlers) HandleNetworkExportStream(w http.ResponseWriter, r *http.Request) {- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/network_route.go b/internal/handlers/network_route.goindex cd6f71e2..616ca422 100644--- a/internal/handlers/network_route.go+++ b/internal/handlers/network_route.go@@ -108,7 +108,7 @@ func (h *Handlers) requireRouteContext(w http.ResponseWriter, r *http.Request, tfalse, map[string]any{"setting": "security.allowNetworkIntercept"})return nil, "", false}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return nil, "", false}diff --git a/internal/handlers/pdf.go b/internal/handlers/pdf.goindex 5ea9fef0..35c2b529 100644--- a/internal/handlers/pdf.go+++ b/internal/handlers/pdf.go@@ -56,7 +56,7 @@ func (h *Handlers) HandlePDF(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/record.go b/internal/handlers/record.goindex 08a54812..8a7aa03a 100644--- a/internal/handlers/record.go+++ b/internal/handlers/record.go@@ -589,7 +589,7 @@ func (h *Handlers) HandleRecordStart(w http.ResponseWriter, r *http.Request) {return}- if !h.ensureChromeOrRespond(w) {+ if !h.ensureBrowserOrRespond(w, h.Config) {return}diff --git a/internal/handlers/screenshot.go b/internal/handlers/screenshot.goindex 12bb600f..68ac7b95 100644--- a/internal/handlers/screenshot.go+++ b/internal/handlers/screenshot.go@@ -22,7 +22,7 @@ import (//// @Endpoint GET /screenshotfunc (h *Handlers) HandleScreenshot(w http.ResponseWriter, r *http.Request) {- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/snapshot.go b/internal/handlers/snapshot.goindex 3f167ec6..3d0562b4 100644--- a/internal/handlers/snapshot.go+++ b/internal/handlers/snapshot.go@@ -126,11 +126,11 @@ func (h *Handlers) HandleSnapshot(w http.ResponseWriter, r *http.Request) {}h.recordActivity(r, activity.Update{Route: snapChromeRoute})- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(effectiveCfg); err != nil {if h.writeBridgeUnavailable(w, err) {return}- httpx.Error(w, 500, fmt.Errorf("chrome initialization: %w", err))+ httpx.Error(w, 500, fmt.Errorf("browser initialization: %w", err))return}diff --git a/internal/handlers/tab_lifecycle.go b/internal/handlers/tab_lifecycle.goindex d3b88637..2d56aee3 100644--- a/internal/handlers/tab_lifecycle.go+++ b/internal/handlers/tab_lifecycle.go@@ -53,7 +53,7 @@ func (h *Handlers) HandleTab(w http.ResponseWriter, r *http.Request) {}}- if !h.ensureChromeOrRespond(w) {+ if !h.ensureBrowserOrRespond(w, h.Config) {return}@@ -105,7 +105,7 @@ func (h *Handlers) HandleTab(w http.ResponseWriter, r *http.Request) {httpx.Error(w, 400, fmt.Errorf("tabId required"))return}- if !h.ensureChromeOrRespond(w) {+ if !h.ensureBrowserOrRespond(w, h.Config) {return}if err := h.Bridge.FocusTab(req.TabID); err != nil {@@ -165,7 +165,7 @@ func (h *Handlers) HandleClose(w http.ResponseWriter, r *http.Request) {}func (h *Handlers) closeTab(w http.ResponseWriter, r *http.Request, tabID string) {- if !h.ensureChromeOrRespond(w) {+ if !h.ensureBrowserOrRespond(w, h.Config) {return}if tabID == "" {diff --git a/internal/handlers/text.go b/internal/handlers/text.goindex a403de14..c27c2156 100644--- a/internal/handlers/text.go+++ b/internal/handlers/text.go@@ -85,11 +85,11 @@ func (h *Handlers) HandleText(w http.ResponseWriter, r *http.Request) {}h.recordActivity(r, activity.Update{Route: textRoute})- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(effectiveCfg); err != nil {if h.writeBridgeUnavailable(w, err) {return}- httpx.Error(w, 500, fmt.Errorf("chrome initialization: %w", err))+ httpx.Error(w, 500, fmt.Errorf("browser initialization: %w", err))return}diff --git a/internal/handlers/value.go b/internal/handlers/value.goindex 922527ad..7e8d427a 100644--- a/internal/handlers/value.go+++ b/internal/handlers/value.go@@ -26,7 +26,7 @@ func (h *Handlers) HandleGetValue(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/handlers/visible.go b/internal/handlers/visible.goindex 2d68892b..6fa13bd2 100644--- a/internal/handlers/visible.go+++ b/internal/handlers/visible.go@@ -26,7 +26,7 @@ func (h *Handlers) HandleGetVisible(w http.ResponseWriter, r *http.Request) {return}- if err := h.ensureChrome(); err != nil {+ if err := h.ensureBrowser(h.Config); err != nil {if h.writeBridgeUnavailable(w, err) {return}diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.goindex ddd75e96..3404eb66 100644--- a/internal/orchestrator/orchestrator.go+++ b/internal/orchestrator/orchestrator.go@@ -177,7 +177,7 @@ func NewOrchestratorWithRunner(baseDir string, runner HostRunner) *Orchestrator// - First request to an instance triggers lazy Chrome initialization (8-20+ seconds)// - Navigation can take up to 60s (NavigateTimeout in bridge config)// - Proxied requests (e.g., POST /tabs/{tabId}/navigate) must wait for:- // 1. Instance /health handler to initialize Chrome (via ensureChrome())+ // 1. Instance /health handler to initialize the browser// 2. Tab operations to complete (navigate, snapshot, actions, etc.)// - Short timeout (<5s) would break first-request scenarios// See: internal/orchestrator/health.go (monitor), internal/bridge/init.go (InitChrome)