High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
add image blocking: BRIDGE_BLOCK_IMAGES env + per-request blockImages param
Lc0d4b1f837f5
diff --git a/cdp.go b/cdp.goindex 9c728487..49a4c222 100644--- a/cdp.go+++ b/cdp.go@@ -168,6 +168,30 @@ func scrollByNodeID(ctx context.Context, backendNodeID int64) error {return withElement(ctx, backendNodeID, "function() { this.scrollIntoViewIfNeeded(); }")}+// setImageBlocking uses Network.setBlockedURLs to block common image URLs.+// Pass true to block, false to clear the blocklist.+func setImageBlocking(ctx context.Context, block bool) error {+ return chromedp.Run(ctx, chromedp.ActionFunc(func(ctx context.Context) error {+ // Enable Network domain first (idempotent).+ if err := chromedp.FromContext(ctx).Target.Execute(ctx, "Network.enable", nil, nil); err != nil {+ return fmt.Errorf("Network.enable: %w", err)+ }++ var urls []string+ if block {+ urls = []string{+ "*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp", "*.svg", "*.ico",+ "*.bmp", "*.tiff", "*.avif",+ }+ }+ p := map[string]any{"urls": urls}+ if err := chromedp.FromContext(ctx).Target.Execute(ctx, "Network.setBlockedURLs", p, nil); err != nil {+ return fmt.Errorf("Network.setBlockedURLs: %w", err)+ }+ return nil+ }))+}+// resolveNodeToObject converts a backendNodeID to a JS remote object ID.func resolveNodeToObject(ctx context.Context, backendNodeID int64) (string, error) {p := map[string]any{"backendNodeId": backendNodeID}diff --git a/config.go b/config.goindex 770009e3..93f9801b 100644--- a/config.go+++ b/config.go@@ -55,6 +55,7 @@ var (profileDir = envOr("BRIDGE_PROFILE", filepath.Join(homeDir(), ".pinchtab", "chrome-profile"))chromeVersion = envOr("BRIDGE_CHROME_VERSION", "133.0.6943.98")timezone = os.Getenv("BRIDGE_TIMEZONE") // e.g. "America/New_York"+ blockImages = os.Getenv("BRIDGE_BLOCK_IMAGES") == "true"actionTimeout = 15 * time.SecondnavigateTimeout = 30 * time.SecondshutdownTimeout = 10 * time.Seconddiff --git a/handlers.go b/handlers.goindex 1adb60c9..ba0e2aa7 100644--- a/handlers.go+++ b/handlers.go@@ -176,11 +176,12 @@ func (b *Bridge) handleText(w http.ResponseWriter, r *http.Request) {func (b *Bridge) handleNavigate(w http.ResponseWriter, r *http.Request) {var req struct {- TabID string `json:"tabId"`- URL string `json:"url"`- NewTab bool `json:"newTab"`- WaitTitle float64 `json:"waitTitle"` // seconds to wait for title (default 2, max 30)- Timeout float64 `json:"timeout"` // per-request navigate timeout in seconds (default: BRIDGE_NAV_TIMEOUT)+ TabID string `json:"tabId"`+ URL string `json:"url"`+ NewTab bool `json:"newTab"`+ WaitTitle float64 `json:"waitTitle"` // seconds to wait for title (default 2, max 30)+ Timeout float64 `json:"timeout"` // per-request navigate timeout in seconds (default: BRIDGE_NAV_TIMEOUT)+ BlockImages *bool `json:"blockImages"` // per-request override; nil = use global BRIDGE_BLOCK_IMAGES}if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, maxBodySize)).Decode(&req); err != nil {jsonErr(w, 400, fmt.Errorf("decode: %w", err))@@ -209,6 +210,12 @@ func (b *Bridge) handleNavigate(w http.ResponseWriter, r *http.Request) {navTimeout = time.Duration(req.Timeout * float64(time.Second))}+ // Resolve image blocking: per-request overrides global.+ shouldBlockImages := blockImages+ if req.BlockImages != nil {+ shouldBlockImages = *req.BlockImages+ }+if req.NewTab {newTargetID, newCtx, _, err := b.CreateTab(req.URL)if err != nil {@@ -220,6 +227,10 @@ func (b *Bridge) handleNavigate(w http.ResponseWriter, r *http.Request) {defer tCancel()go cancelOnClientDone(r.Context(), tCancel)+ if shouldBlockImages {+ _ = setImageBlocking(tCtx, true)+ }+var url, title string_ = chromedp.Run(tCtx, chromedp.Location(&url))title = waitForTitle(tCtx, titleWait)@@ -238,6 +249,9 @@ func (b *Bridge) handleNavigate(w http.ResponseWriter, r *http.Request) {defer tCancel()go cancelOnClientDone(r.Context(), tCancel)+ // Apply image blocking before navigation.+ _ = setImageBlocking(tCtx, shouldBlockImages)+if err := navigatePage(tCtx, req.URL); err != nil {jsonErr(w, 500, fmt.Errorf("navigate: %w", err))return