Skip to content

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

fix: under ghost-chrome the BridgeAdapter hides ten optional bridge capabilities from the handlers (session-end tab close, awake holds, tab-removed hooks, restart status, tab policy state, browser-context tabs), because it embeds the BridgeAPI interface and handlers reach extras by type assertion (PIN-375)

Luigi Agosti982227ee314f
diff --git a/internal/browsers/ghostchrome/bridgekit/bridge_adapter.go b/internal/browsers/ghostchrome/bridgekit/bridge_adapter.go
index d6dcc8da..e85b4036 100644
--- a/internal/browsers/ghostchrome/bridgekit/bridge_adapter.go
+++ b/internal/browsers/ghostchrome/bridgekit/bridge_adapter.go
@@ -87,6 +87,10 @@ func NewBridgeAdapter(chromeBridge bridge.BridgeAPI, cfg *config.RuntimeConfig)
}
}
+func (a *BridgeAdapter) Unwrap() bridge.BridgeAPI {
+ return a.BridgeAPI
+}
+
func ensureBrowser(b bridge.BridgeAPI, cfg *config.RuntimeConfig) error {
return b.EnsureBrowser(cfg)
}
diff --git a/internal/browsers/ghostchrome/bridgekit/bridge_adapter_passthrough.go b/internal/browsers/ghostchrome/bridgekit/bridge_adapter_passthrough.go
index 4aefa76e..f4788dd3 100644
--- a/internal/browsers/ghostchrome/bridgekit/bridge_adapter_passthrough.go
+++ b/internal/browsers/ghostchrome/bridgekit/bridge_adapter_passthrough.go
@@ -1,12 +1,5 @@
package bridgekit
-import (
- "fmt"
- "time"
-
- "github.com/pinchtab/pinchtab/internal/bridge"
-)
-
func (a *BridgeAdapter) FocusTab(tabID string) error {
if chromeID, ok := a.proxy.ChromeTabID(tabID); ok {
return a.BridgeAPI.FocusTab(chromeID)
@@ -17,9 +10,6 @@ func (a *BridgeAdapter) FocusTab(tabID string) error {
func (a *BridgeAdapter) CloseTab(tabID string) error {
if chromeID, ok := a.proxy.ChromeTabID(tabID); ok {
err := a.BridgeAPI.CloseTab(chromeID)
- // Scrub the mapping even if the Chrome close errored — the caller
- // asked for the tab to be gone; a stale mapping would resurrect it
- // on the next TabContext.
a.proxy.ReleaseTab(tabID)
return err
}
@@ -34,35 +24,6 @@ func (a *BridgeAdapter) AvailableActions() []string {
return a.proxy.AvailableActions()
}
-func (a *BridgeAdapter) GetDocumentReadyState(tabID string) (string, error) {
- type readyStater interface {
- GetDocumentReadyState(string) (string, error)
- }
- if rs, ok := a.BridgeAPI.(readyStater); ok {
- return rs.GetDocumentReadyState(tabID)
- }
- return "", nil
-}
-
-func (a *BridgeAdapter) IsNetworkIdle(tabID string) (bool, bool) {
- type idleChecker interface {
- IsNetworkIdle(string) (bool, bool)
- }
- if ic, ok := a.BridgeAPI.(idleChecker); ok {
- return ic.IsNetworkIdle(tabID)
- }
- return false, false
-}
-
-func (a *BridgeAdapter) SetFingerprintRotateActive(tabID string, active bool) {
- type setter interface {
- SetFingerprintRotateActive(string, bool)
- }
- if s, ok := a.BridgeAPI.(setter); ok {
- s.SetFingerprintRotateActive(tabID, active)
- }
-}
-
func (a *BridgeAdapter) FingerprintRotateActive(tabID string) bool {
type getter interface {
FingerprintRotateActive(string) bool
@@ -74,78 +35,8 @@ func (a *BridgeAdapter) FingerprintRotateActive(tabID string) bool {
if g.FingerprintRotateActive(tabID) {
return true
}
- // The rotate handler stores the flag under the resolved Chrome tab ID,
- // but callers may query with the original lite tab ID.
if chromeID, mapped := a.proxy.ChromeTabID(tabID); mapped {
return g.FingerprintRotateActive(chromeID)
}
return false
}
-
-func (a *BridgeAdapter) GetFrameScope(tabID string) (bridge.FrameScope, bool) {
- type frameScopeAPI interface {
- GetFrameScope(string) (bridge.FrameScope, bool)
- }
- if fs, ok := a.BridgeAPI.(frameScopeAPI); ok {
- return fs.GetFrameScope(tabID)
- }
- return bridge.FrameScope{}, false
-}
-
-func (a *BridgeAdapter) SetFrameScope(tabID string, scope bridge.FrameScope) {
- type frameScopeAPI interface {
- SetFrameScope(string, bridge.FrameScope)
- }
- if fs, ok := a.BridgeAPI.(frameScopeAPI); ok {
- fs.SetFrameScope(tabID, scope)
- }
-}
-
-func (a *BridgeAdapter) ClearFrameScope(tabID string) {
- type frameScopeAPI interface {
- ClearFrameScope(string)
- }
- if fs, ok := a.BridgeAPI.(frameScopeAPI); ok {
- fs.ClearFrameScope(tabID)
- }
-}
-
-func (a *BridgeAdapter) SetTabHandoff(tabID, reason string, timeout time.Duration) error {
- type handoffAPI interface {
- SetTabHandoff(string, string, time.Duration) error
- }
- if h, ok := a.BridgeAPI.(handoffAPI); ok {
- return h.SetTabHandoff(tabID, reason, timeout)
- }
- return fmt.Errorf("bridge does not support handoff state")
-}
-
-func (a *BridgeAdapter) ResumeTabHandoff(tabID string) error {
- type handoffAPI interface {
- ResumeTabHandoff(string) error
- }
- if h, ok := a.BridgeAPI.(handoffAPI); ok {
- return h.ResumeTabHandoff(tabID)
- }
- return fmt.Errorf("bridge does not support handoff state")
-}
-
-func (a *BridgeAdapter) TabHandoffState(tabID string) (bridge.TabHandoffState, bool) {
- type handoffAPI interface {
- TabHandoffState(string) (bridge.TabHandoffState, bool)
- }
- if h, ok := a.BridgeAPI.(handoffAPI); ok {
- return h.TabHandoffState(tabID)
- }
- return bridge.TabHandoffState{}, false
-}
-
-func (a *BridgeAdapter) CurrentTabID() string {
- type currentTabReader interface {
- CurrentTabID() string
- }
- if r, ok := a.BridgeAPI.(currentTabReader); ok {
- return r.CurrentTabID()
- }
- return ""
-}
diff --git a/internal/browsers/ghostchrome/bridgekit/bridge_adapter_test.go b/internal/browsers/ghostchrome/bridgekit/bridge_adapter_test.go
index 5b95a650..8b87ad34 100644
--- a/internal/browsers/ghostchrome/bridgekit/bridge_adapter_test.go
+++ b/internal/browsers/ghostchrome/bridgekit/bridge_adapter_test.go
@@ -812,6 +812,12 @@ type escalatingChromeAPI struct {
bridge.BridgeAPI // nil — panics on unimplemented methods
esc *escalatingChromeBridge
closedTabs []string
+ focusedTabs []string
+}
+
+func (c *escalatingChromeAPI) FocusTab(tabID string) error {
+ c.focusedTabs = append(c.focusedTabs, tabID)
+ return nil
}
func (c *escalatingChromeAPI) GetRefCache(string) *bridge.RefCache { return nil }
@@ -903,6 +909,30 @@ func TestAdapterCloseTab_EscalatedTab_NoResurrection(t *testing.T) {
}
}
+func TestAdapterFocusTab_EscalatedLiteTabFocusesItsChromeTab(t *testing.T) {
+ ts := newRichTestServer()
+ defer ts.Close()
+
+ lite := staticfetch.NewBrowser()
+ defer func() { _ = lite.Close() }()
+ adapter, _, api := newEscalatingAdapter(t, lite)
+
+ res, err := lite.Navigate(context.Background(), ts.URL)
+ if err != nil {
+ t.Fatalf("static Navigate: %v", err)
+ }
+ if _, _, err := adapter.TabContext(res.TabID); err != nil {
+ t.Fatalf("TabContext (escalate): %v", err)
+ }
+
+ if err := adapter.FocusTab(res.TabID); err != nil {
+ t.Fatalf("FocusTab: %v", err)
+ }
+ if len(api.focusedTabs) != 1 || api.focusedTabs[0] != "chrome-tab" {
+ t.Fatalf("focusedTabs = %v, want [chrome-tab]", api.focusedTabs)
+ }
+}
+
func TestAdapterCloseTab_UnescalatedLiteTab_NoChromeInvolved(t *testing.T) {
ts := newRichTestServer()
defer ts.Close()
diff --git a/internal/browsers/ghostchrome/bridgekit/current_tab_listing_test.go b/internal/browsers/ghostchrome/bridgekit/current_tab_listing_test.go
index c1d96520..f6aa1b68 100644
--- a/internal/browsers/ghostchrome/bridgekit/current_tab_listing_test.go
+++ b/internal/browsers/ghostchrome/bridgekit/current_tab_listing_test.go
@@ -34,9 +34,6 @@ func TestTheTabListingThroughTheAdapterLeadsWithTheCurrentTab(t *testing.T) {
chrome.RegisterTab("tabB", ctx)
adapter := NewBridgeAdapter(chrome, cfg)
- if got := adapter.CurrentTabID(); got != "tabB" {
- t.Errorf("adapter CurrentTabID = %q, want the chrome bridge's current tab tabB", got)
- }
_, resolved, err := adapter.TabContext("")
if err != nil || resolved != "tabB" {
t.Fatalf("adapter TabContext(\"\") = %q, %v; the reader must agree with it", resolved, err)
diff --git a/internal/handlers/activity_helpers.go b/internal/handlers/activity_helpers.go
index 45209c4b..c57a2416 100644
--- a/internal/handlers/activity_helpers.go
+++ b/internal/handlers/activity_helpers.go
@@ -90,7 +90,7 @@ type tabAwakeHolder interface {
var _ tabAwakeHolder = (*bridge.Bridge)(nil)
func (h *Handlers) holdTabAwakeForRequest(r *http.Request, tabID string) {
- if holder, ok := h.Bridge.(tabAwakeHolder); ok {
+ if holder, ok := bridgeAs[tabAwakeHolder](h.Bridge); ok {
holder.HoldAwakeUntil(r.Context(), tabID)
}
}
@@ -106,7 +106,7 @@ func (h *Handlers) tabScopes() (tabScopeTracker, bool) {
if h == nil {
return nil, false
}
- tracker, ok := h.Bridge.(tabScopeTracker)
+ tracker, ok := bridgeAs[tabScopeTracker](h.Bridge)
return tracker, ok
}
diff --git a/internal/handlers/bridge_optional.go b/internal/handlers/bridge_optional.go
new file mode 100644
index 00000000..9608e2e5
--- /dev/null
+++ b/internal/handlers/bridge_optional.go
@@ -0,0 +1,22 @@
+package handlers
+
+import "github.com/pinchtab/pinchtab/internal/bridge"
+
+type bridgeUnwrapper interface {
+ Unwrap() bridge.BridgeAPI
+}
+
+func bridgeAs[T any](b bridge.BridgeAPI) (T, bool) {
+ for b != nil {
+ if capability, ok := any(b).(T); ok {
+ return capability, true
+ }
+ wrapper, ok := b.(bridgeUnwrapper)
+ if !ok {
+ break
+ }
+ b = wrapper.Unwrap()
+ }
+ var zero T
+ return zero, false
+}
diff --git a/internal/handlers/bridge_optional_test.go b/internal/handlers/bridge_optional_test.go
new file mode 100644
index 00000000..377bdeb8
--- /dev/null
+++ b/internal/handlers/bridge_optional_test.go
@@ -0,0 +1,296 @@
+package handlers
+
+import (
+ "context"
+ "encoding/json"
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "net/http"
+ "net/http/httptest"
+ "path/filepath"
+ "reflect"
+ "sort"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/chromedp/chromedp"
+ "github.com/pinchtab/pinchtab/internal/bridge"
+ "github.com/pinchtab/pinchtab/internal/browsers/ghostchrome/bridgekit"
+ "github.com/pinchtab/pinchtab/internal/config"
+)
+
+type optionalCapabilitySite struct {
+ pos string
+ iface string
+ methods []string
+ raw bool
+}
+
+func parseHandlerSources(t *testing.T, extra map[string]string) (*token.FileSet, []*ast.File) {
+ t.Helper()
+ paths, err := filepath.Glob("*.go")
+ if err != nil {
+ t.Fatal(err)
+ }
+ fset := token.NewFileSet()
+ var files []*ast.File
+ for _, path := range paths {
+ if strings.HasSuffix(path, "_test.go") {
+ continue
+ }
+ file, err := parser.ParseFile(fset, path, nil, 0)
+ if err != nil {
+ t.Fatalf("parse %s: %v", path, err)
+ }
+ files = append(files, file)
+ }
+ for name, src := range extra {
+ file, err := parser.ParseFile(fset, name, src, 0)
+ if err != nil {
+ t.Fatalf("parse %s: %v", name, err)
+ }
+ files = append(files, file)
+ }
+ return fset, files
+}
+
+func interfaceDecls(files []*ast.File) map[string]*ast.InterfaceType {
+ decls := map[string]*ast.InterfaceType{}
+ for _, file := range files {
+ ast.Inspect(file, func(n ast.Node) bool {
+ if spec, ok := n.(*ast.TypeSpec); ok {
+ if iface, ok := spec.Type.(*ast.InterfaceType); ok {
+ decls[spec.Name.Name] = iface
+ }
+ }
+ return true
+ })
+ }
+ return decls
+}
+
+func interfaceMethods(t *testing.T, expr ast.Expr, decls map[string]*ast.InterfaceType) (string, []string) {
+ t.Helper()
+ var iface *ast.InterfaceType
+ name := "interface{...}"
+ switch e := expr.(type) {
+ case *ast.Ident:
+ name = e.Name
+ iface = decls[e.Name]
+ case *ast.InterfaceType:
+ iface = e
+ }
+ if iface == nil {
+ t.Fatalf("optional capability %s is not an interface declared in package handlers; the census cannot read its methods", name)
+ }
+ var methods []string
+ for _, field := range iface.Methods.List {
+ if len(field.Names) == 0 {
+ _, embedded := interfaceMethods(t, field.Type, decls)
+ methods = append(methods, embedded...)
+ continue
+ }
+ for _, n := range field.Names {
+ methods = append(methods, n.Name)
+ }
+ }
+ sort.Strings(methods)
+ return name, methods
+}
+
+func isHBridge(e ast.Expr) bool {
+ sel, ok := e.(*ast.SelectorExpr)
+ if !ok || sel.Sel.Name != "Bridge" {
+ return false
+ }
+ recv, ok := sel.X.(*ast.Ident)
+ return ok && recv.Name == "h"
+}
+
+func optionalCapabilitySites(t *testing.T, fset *token.FileSet, files []*ast.File) []optionalCapabilitySite {
+ t.Helper()
+ decls := interfaceDecls(files)
+ var sites []optionalCapabilitySite
+ add := func(n ast.Node, typ ast.Expr, raw bool) {
+ name, methods := interfaceMethods(t, typ, decls)
+ sites = append(sites, optionalCapabilitySite{pos: fset.Position(n.Pos()).String(), iface: name, methods: methods, raw: raw})
+ }
+ for _, file := range files {
+ ast.Inspect(file, func(n ast.Node) bool {
+ switch e := n.(type) {
+ case *ast.TypeAssertExpr:
+ if e.Type != nil && isHBridge(e.X) {
+ add(e, e.Type, true)
+ }
+ case *ast.CallExpr:
+ if idx, ok := e.Fun.(*ast.IndexExpr); ok {
+ if fn, ok := idx.X.(*ast.Ident); ok && fn.Name == "bridgeAs" {
+ add(e, idx.Index, false)
+ }
+ }
+ }
+ return true
+ })
+ }
+ return sites
+}
+
+func ghostChromeAdapterOverRealBridge(t *testing.T) bridge.BridgeAPI {
+ t.Helper()
+ ctx, cancel := chromedp.NewContext(context.Background())
+ t.Cleanup(cancel)
+ cfg := &config.RuntimeConfig{StateDir: t.TempDir()}
+ return bridgekit.NewBridgeAdapter(bridge.New(context.Background(), ctx, cfg), cfg)
+}
+
+func reachableThroughUnwrap(b bridge.BridgeAPI, methods []string) bool {
+ for b != nil {
+ v := reflect.ValueOf(b)
+ all := true
+ for _, m := range methods {
+ if !v.MethodByName(m).IsValid() {
+ all = false
+ break
+ }
+ }
+ if all {
+ return true
+ }
+ wrapper, ok := b.(bridgeUnwrapper)
+ if !ok {
+ return false
+ }
+ b = wrapper.Unwrap()
+ }
+ return false
+}
+
+func unreachableCapabilities(sites []optionalCapabilitySite, b bridge.BridgeAPI) []string {
+ var missing []string
+ for _, site := range sites {
+ if !reachableThroughUnwrap(b, site.methods) {
+ missing = append(missing, site.pos+" "+site.iface+" "+strings.Join(site.methods, ","))
+ }
+ }
+ return missing
+}
+
+func TestEveryOptionalBridgeCapabilityIsReachableUnderGhostChrome(t *testing.T) {
+ fset, files := parseHandlerSources(t, nil)
+ sites := optionalCapabilitySites(t, fset, files)
+ if len(sites) < 17 {
+ t.Fatalf("census found %d optional-capability lookups on h.Bridge, want at least the 17 known; it would pass vacuously", len(sites))
+ }
+
+ for _, missing := range unreachableCapabilities(sites, ghostChromeAdapterOverRealBridge(t)) {
+ t.Errorf("under the ghost-chrome adapter the handlers cannot reach %s", missing)
+ }
+}
+
+func TestOptionalBridgeCapabilitiesAreLookedUpThroughBridgeAs(t *testing.T) {
+ fset, files := parseHandlerSources(t, nil)
+ for _, site := range optionalCapabilitySites(t, fset, files) {
+ if site.raw {
+ t.Errorf("%s asserts h.Bridge.(%s) directly, which never looks past a decorator; use bridgeAs[%s](h.Bridge)", site.pos, site.iface, site.iface)
+ }
+ }
+}
+
+func TestTheCapabilityCensusCoversAPlantedInterface(t *testing.T) {
+ const planted = `package handlers
+type plantedCapability interface {
+ PlantedMethodNoBridgeHas()
+}
+func (h *Handlers) planted() {
+ if c, ok := bridgeAs[plantedCapability](h.Bridge); ok {
+ c.PlantedMethodNoBridgeHas()
+ }
+ _, _ = h.Bridge.(interface{ RecordTabScope(string, string, bool) })
+}
+`
+ fset, files := parseHandlerSources(t, map[string]string{"planted.go": planted})
+ var plantedSites []optionalCapabilitySite
+ for _, site := range optionalCapabilitySites(t, fset, files) {
+ if strings.HasPrefix(site.pos, "planted.go") {
+ plantedSites = append(plantedSites, site)
+ }
+ }
+ if len(plantedSites) != 2 || !plantedSites[1].raw {
+ t.Fatalf("planted sites = %+v, want the bridgeAs lookup and the raw assertion", plantedSites)
+ }
+
+ missing := unreachableCapabilities(plantedSites, ghostChromeAdapterOverRealBridge(t))
+
+ if len(missing) != 1 || !strings.Contains(missing[0], "plantedCapability") {
+ t.Fatalf("unreachable = %v, want only the planted capability", missing)
+ }
+}
+
+func TestBridgeAsPrefersTheDecoratorAndFallsBackToWhatItWraps(t *testing.T) {
+ adapter := ghostChromeAdapterOverRealBridge(t)
+
+ translating, ok := bridgeAs[interface{ FingerprintRotateActive(string) bool }](adapter)
+ if !ok || any(translating) != any(adapter) {
+ t.Fatal("the adapter's own translating FingerprintRotateActive must win over the wrapped bridge's")
+ }
+ tracker, ok := bridgeAs[tabScopeTracker](adapter)
+ if !ok {
+ t.Fatal("RecordTabScope is not reachable through the adapter")
+ }
+ if _, isBridge := tracker.(*bridge.Bridge); !isBridge {
+ t.Fatalf("tabScopeTracker resolved to %T, want the wrapped *bridge.Bridge", tracker)
+ }
+ if _, ok := bridgeAs[tabScopeTracker](nil); ok {
+ t.Fatal("a nil bridge must offer no capability")
+ }
+}
+
+func TestUnderGhostChromeAnEndedSessionClosesItsTabAndTheListingLeadsWithTheCurrentTab(t *testing.T) {
+ f := newSessionTabsFixture(t)
+ f.b.Config.NavigateTimeout = 20 * time.Second
+ f.h = New(bridgekit.NewBridgeAdapter(f.b, f.b.Config), f.b.Config, nil, nil, nil)
+ page := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ _, _ = w.Write([]byte("<title>page</title>"))
+ }))
+ t.Cleanup(page.Close)
+ openAt := func(sessionID string, trusted bool) string {
+ rec := f.serve(f.h.HandleTab, "/tab", `{"action":"new","url":"`+page.URL+`"}`, sessionID, trusted)
+ var out struct {
+ TabID string `json:"tabId"`
+ }
+ if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil || out.TabID == "" {
+ t.Fatalf("new tab answered %d: %s", rec.Code, rec.Body.String())
+ }
+ return out.TabID
+ }
+ own := openAt("sess_s", true)
+ first := openAt("", false)
+ second := openAt("", false)
+ if rec := f.serve(f.h.HandleTab, "/tab", `{"action":"focus","tabId":"`+first+`"}`, "", false); rec.Code != http.StatusOK {
+ t.Fatalf("focus answered %d: %s", rec.Code, rec.Body.String())
+ }
+
+ w := httptest.NewRecorder()
+ f.h.HandleTabs(w, httptest.NewRequest(http.MethodGet, "/tabs", nil))
+ var listing struct {
+ Tabs []struct {
+ ID string `json:"id"`
+ } `json:"tabs"`
+ }
+ if err := json.Unmarshal(w.Body.Bytes(), &listing); err != nil || len(listing.Tabs) == 0 {
+ t.Fatalf("GET /tabs = %d %s", w.Code, w.Body.String())
+ }
+ if listing.Tabs[0].ID != first {
+ t.Fatalf("GET /tabs through the adapter leads with %s, want the focused tab %s (second was %s)", listing.Tabs[0].ID, first, second)
+ }
+
+ closed := f.closeFor("sess_s")
+ if len(closed.Closed) != 1 || closed.Closed[0] != own {
+ t.Fatalf("session end through the adapter closed %v, want [%s]", closed.Closed, own)
+ }
+ if f.open(own) {
+ t.Fatalf("the ended session's tab %s is still open", own)
+ }
+}
diff --git a/internal/handlers/count.go b/internal/handlers/count.go
index bd2b8f08..a9fd5451 100644
--- a/internal/handlers/count.go
+++ b/internal/handlers/count.go
@@ -204,7 +204,7 @@ func (h *Handlers) evaluateCount(ctx context.Context, tabID, expr string, out an
if frameID == "" {
return h.evalRuntime(ctx, expr, out, bridge.EvalOpts{})
}
- evaluator, ok := h.Bridge.(frameCountEvaluator)
+ evaluator, ok := bridgeAs[frameCountEvaluator](h.Bridge)
if !ok {
return fmt.Errorf("frame-scoped count unavailable")
}
diff --git a/internal/handlers/download.go b/internal/handlers/download.go
index b1caddae..4d102eb2 100644
--- a/internal/handlers/download.go
+++ b/internal/handlers/download.go
@@ -122,7 +122,7 @@ func (h *Handlers) enforceDownloadTabPolicy(w http.ResponseWriter, r *http.Reque
return false
}
if currentURL == "" {
- if provider, ok := h.Bridge.(tabPolicyStateProvider); ok {
+ if provider, ok := bridgeAs[tabPolicyStateProvider](h.Bridge); ok {
if state, ok := provider.GetTabPolicyState(resolvedTabID); ok && state.CurrentURL != "" {
currentURL = state.CurrentURL
}
diff --git a/internal/handlers/frame.go b/internal/handlers/frame.go
index a455f1a3..47b80f75 100644
--- a/internal/handlers/frame.go
+++ b/internal/handlers/frame.go
@@ -24,7 +24,7 @@ type frameRequest struct {
}
func (h *Handlers) frameScopes() frameScopeAPI {
- scopes, _ := h.Bridge.(frameScopeAPI)
+ scopes, _ := bridgeAs[frameScopeAPI](h.Bridge)
return scopes
}
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index 56f83ed9..50c45c63 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -112,7 +112,7 @@ func New(b bridge.BridgeAPI, cfg *config.RuntimeConfig, p bridge.ProfileService,
return h.Bridge.Evaluate(ctx, expression, out, opts)
}
- if notifier, ok := h.Bridge.(tabRemovalNotifier); ok {
+ if notifier, ok := bridgeAs[tabRemovalNotifier](h.Bridge); ok {
notifier.AddTabRemovedHook(h.credentialStore.RemoveTab)
}
@@ -266,7 +266,7 @@ func (h *Handlers) clearTabFrameScope(tabID string) {
}
func (h *Handlers) bridgeRestartStatus() (bool, time.Duration) {
- provider, ok := h.Bridge.(restartStatusProvider)
+ provider, ok := bridgeAs[restartStatusProvider](h.Bridge)
if !ok {
return false, 0
}
diff --git a/internal/handlers/handoff.go b/internal/handlers/handoff.go
index a6910843..a48bbdc8 100644
--- a/internal/handlers/handoff.go
+++ b/internal/handlers/handoff.go
@@ -19,7 +19,7 @@ type tabHandoffController interface {
}
func (h *Handlers) handoffController() (tabHandoffController, bool) {
- ctrl, ok := h.Bridge.(tabHandoffController)
+ ctrl, ok := bridgeAs[tabHandoffController](h.Bridge)
return ctrl, ok
}
diff --git a/internal/handlers/health_tabs.go b/internal/handlers/health_tabs.go
index 43955a65..9ed8b5e7 100644
--- a/internal/handlers/health_tabs.go
+++ b/internal/handlers/health_tabs.go
@@ -24,7 +24,7 @@ func (h *Handlers) listedCurrentTabID(r *http.Request, targets []bridge.TabTarge
tabID, _ := h.scopedCurrentTabForRequest(r)
return tabID
}
- if reader, ok := h.Bridge.(currentTabReader); ok {
+ if reader, ok := bridgeAs[currentTabReader](h.Bridge); ok {
if tabID := reader.CurrentTabID(); tabID != "" {
return tabID
}
@@ -199,7 +199,7 @@ func (h *Handlers) HandleTabs(w http.ResponseWriter, r *http.Request) {
if t.BrowserContextID != "" {
entry["browserContextId"] = t.BrowserContextID
}
- if hr, ok := h.Bridge.(tabHandoffReader); ok {
+ if hr, ok := bridgeAs[tabHandoffReader](h.Bridge); ok {
if hs, ok := hr.TabHandoffState(tabID); ok {
entry["status"] = hs.Status
entry["handoffReason"] = hs.Reason
diff --git a/internal/handlers/navigation.go b/internal/handlers/navigation.go
index 49518781..48249657 100644
--- a/internal/handlers/navigation.go
+++ b/internal/handlers/navigation.go
@@ -311,7 +311,7 @@ type staticFirstOutcome struct {
// one budget would let a slow static fetch starve the Chrome attempt that exists
// to rescue it.
func (h *Handlers) tryStaticFirstNavigate(w http.ResponseWriter, r *http.Request, req navigateRequest, effectiveCfg *config.RuntimeConfig, navRoute *browserops.RouteMetadata) staticFirstOutcome {
- sf, ok := h.Bridge.(staticFirstNavigator)
+ sf, ok := bridgeAs[staticFirstNavigator](h.Bridge)
if !ok || !sf.StaticFirstNavigate() || !req.NewTab {
return staticFirstOutcome{}
}
diff --git a/internal/handlers/state_tab.go b/internal/handlers/state_tab.go
index 1ace55f7..b20c7f56 100644
--- a/internal/handlers/state_tab.go
+++ b/internal/handlers/state_tab.go
@@ -70,10 +70,10 @@ func (h *Handlers) HandleTabState(w http.ResponseWriter, r *http.Request) {
}
}
- if bridgeWithState, ok := h.Bridge.(interface {
+ if bridgeWithState, ok := bridgeAs[interface {
GetDocumentReadyState(string) (string, error)
IsNetworkIdle(string) (bool, bool)
- }); ok {
+ }](h.Bridge); ok {
if readyState, err := bridgeWithState.GetDocumentReadyState(resolvedTabID); err == nil {
resp.Load.ReadyState = readyState
switch readyState {
diff --git a/internal/handlers/stealth.go b/internal/handlers/stealth.go
index a621577b..3741d888 100644
--- a/internal/handlers/stealth.go
+++ b/internal/handlers/stealth.go
@@ -98,7 +98,7 @@ func (h *Handlers) HandleFingerprintRotate(w http.ResponseWriter, r *http.Reques
}
}
- if tracker, ok := h.Bridge.(interface{ SetFingerprintRotateActive(string, bool) }); ok {
+ if tracker, ok := bridgeAs[interface{ SetFingerprintRotateActive(string, bool) }](h.Bridge); ok {
tracker.SetFingerprintRotateActive(resolvedTabID, true)
}
diff --git a/internal/handlers/stealth_status.go b/internal/handlers/stealth_status.go
index 086fbcf0..e6d99b52 100644
--- a/internal/handlers/stealth_status.go
+++ b/internal/handlers/stealth_status.go
@@ -21,7 +21,7 @@ func (h *Handlers) HandleStealthStatus(w http.ResponseWriter, r *http.Request) {
status.AdvertisedBrowserVersion = stealth.ResolveBrowserVersion(h.Config)
status.BrowserBinaryVersion = stealth.ProbedBinaryVersion(h.Config)
if tabID := r.URL.Query().Get("tabId"); tabID != "" {
- if tracker, ok := h.Bridge.(interface{ FingerprintRotateActive(string) bool }); ok {
+ if tracker, ok := bridgeAs[interface{ FingerprintRotateActive(string) bool }](h.Bridge); ok {
status.TabOverrides["fingerprintRotateActive"] = tracker.FingerprintRotateActive(tabID)
}
}
diff --git a/internal/handlers/tab_lifecycle.go b/internal/handlers/tab_lifecycle.go
index 3b7cd160..794dcb88 100644
--- a/internal/handlers/tab_lifecycle.go
+++ b/internal/handlers/tab_lifecycle.go
@@ -97,7 +97,7 @@ func (h *Handlers) createBlankTab(w http.ResponseWriter, r *http.Request, browse
httpx.Error(w, 400, fmt.Errorf("browserContextId is not owned by an attached page"))
return
}
- creator, ok := h.Bridge.(browserContextTabCreator)
+ creator, ok := bridgeAs[browserContextTabCreator](h.Bridge)
if !ok {
httpx.Error(w, 501, fmt.Errorf("browser-context tab creation is unavailable"))
return
diff --git a/internal/handlers/tab_policy.go b/internal/handlers/tab_policy.go
index 74cade33..2b2b9e51 100644
--- a/internal/handlers/tab_policy.go
+++ b/internal/handlers/tab_policy.go
@@ -81,7 +81,7 @@ func (h *Handlers) enforceCurrentTabDomainPolicy(w http.ResponseWriter, r *http.
return "", true
}
- if provider, ok := h.Bridge.(tabPolicyStateProvider); ok {
+ if provider, ok := bridgeAs[tabPolicyStateProvider](h.Bridge); ok {
if state, ok := provider.GetTabPolicyState(tabID); ok && !state.UpdatedAt.IsZero() {
if state.CurrentURL != "" {
h.recordResolvedURL(r, state.CurrentURL)
@@ -120,7 +120,7 @@ func (h *Handlers) enforceCurrentTabDomainPolicy(w http.ResponseWriter, r *http.
}
state := bridge.EvaluateTabPolicy(currentURL, h.Config.IDPI, h.Config.AllowedDomains)
- if setter, ok := h.Bridge.(tabPolicyStateSetter); ok {
+ if setter, ok := bridgeAs[tabPolicyStateSetter](h.Bridge); ok {
setter.SetTabPolicyState(tabID, state)
}
h.recordResolvedURL(r, currentURL)