Skip to content

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

refactor: reduce unnecessary comments in code

Marioddc4f669a9ef
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c509afb5..0aec0cde 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,11 @@
### Added
- **PDF export parameters** — `/pdf` API now supports full PrintToPDFParams: `paperWidth`, `paperHeight`, `marginTop`, `marginBottom`, `marginLeft`, `marginRight`, `pageRanges`, `displayHeaderFooter`, `headerTemplate`, `footerTemplate`, `generateTaggedPDF`, `generateDocumentOutline`, `preferCSSPageSize` (#45, PR #48)
- **Installer branding** — install.sh now uses yellow accent color (#fbbf24) and crab icon 🦀 for consistency (PR #48)
+- **Ad blocking** — New `blockAds` option blocks 100+ tracking/analytics domains for cleaner snapshots. Available via env var `BRIDGE_BLOCK_ADS=true`, CLI flag `--block-ads`, and API parameter (#50)
+
+### Changed
+- **Human package testability** — Added `Config` struct and `TypeWithConfig` function to inject custom random source for deterministic testing (#50)
+- **WebSocket proxy standards** — Improved HTTP header formatting using `fmt.Fprintf` and `textproto.CanonicalMIMEHeaderKey` (#50)
### Docs
- **Definition of Done** — Added DEFINITION_OF_DONE.md and GitHub PR template with streamlined, actionable checklist (PR #48)
diff --git a/TODO.md b/TODO.md
deleted file mode 100644
index 2647a963..00000000
--- a/TODO.md
+++ /dev/null
@@ -1,30 +0,0 @@
-# Pinchtab — TODO
-
-**Philosophy**: 12MB binary. HTTP API. Minimal deps. Internal tool, not a product.
-
----
-
-## Quality Improvements
-
-### Code Quality
-- [x] **proxy_ws.go proper HTTP** — ~~Replace raw `backend.Write` of HTTP headers with proper `http.Request` construction for better standards compliance.~~ ✅ Improved with `fmt.Fprintf` and `textproto.CanonicalMIMEHeaderKey` (PR #50)
-- [x] **humanType global rand** — ~~Accept `*rand.Rand` parameter instead of global variable for better testability and concurrency safety.~~ ✅ Added `Config` struct and `TypeWithConfig` function (PR #50)
-
-### Feature Enhancements
-- [x] **Ad blocking** — ~~Basic tracker blocking for cleaner snapshots (block common analytics/ad domains).~~ ✅ Blocks 100+ ad/tracking domains (PR #50)
-- [ ] **API Naming Consistency** — Clarify profile vs instance distinction:
- - Profile = Chrome profile directory (stable 12-char hex ID)
- - Instance = running Pinchtab process (composite ID like "name-port")
- - Option: Standardize on profile IDs throughout API
-
----
-
-## Known Limitations
-
-- **Canvas noise in headless** — `toDataURL()` returns identical data in headless Chrome. This is a Chrome limitation that only affects `full` stealth mode.
-
----
-
-## Not Doing
-Desktop app, plugin system, proxy rotation, SaaS, Selenium compat, MCP protocol,
-cloud anything, distributed clusters, workflow orchestration.
\ No newline at end of file
diff --git a/internal/bridge/adblock.go b/internal/bridge/adblock.go
index 42af46f3..c8609a31 100644
--- a/internal/bridge/adblock.go
+++ b/internal/bridge/adblock.go
@@ -1,33 +1,24 @@
package bridge
-// AdBlockPatterns contains patterns for common ad, tracking, and analytics domains
-// to provide cleaner snapshots for AI agents
+// AdBlockPatterns blocks ad, tracking, and analytics domains for cleaner snapshots
var AdBlockPatterns = []string{
- // Google Analytics & Tag Manager
+ // Analytics & tracking
"*google-analytics.com/*",
"*googletagmanager.com/*",
"*googletagservices.com/*",
"*googlesyndication.com/*",
"*googleadservices.com/*",
"*doubleclick.net/*",
-
- // Facebook/Meta tracking
"*facebook.com/tr/*",
"*facebook.com/plugins/*",
"*connect.facebook.net/*",
"*fbcdn.net/*/fbevents.js",
-
- // Twitter/X tracking
"*twitter.com/i/adsct",
"*analytics.twitter.com/*",
"*static.ads-twitter.com/*",
-
- // Amazon tracking
"*amazon-adsystem.com/*",
"*amazontrust.com/*",
"*adsafeprotected.com/*",
-
- // Common analytics services
"*segment.io/*",
"*segment.com/*",
"*mixpanel.com/*",
@@ -43,7 +34,7 @@ var AdBlockPatterns = []string{
"*pingdom.net/*",
"*newrelic.com/*",
"*nr-data.net/*",
-
+
// Ad networks
"*doubleclick.net/*",
"*googleadservices.com/*",
diff --git a/internal/bridge/tab_manager.go b/internal/bridge/tab_manager.go
index 73172137..bff836f0 100644
--- a/internal/bridge/tab_manager.go
+++ b/internal/bridge/tab_manager.go
@@ -146,19 +146,18 @@ func (tm *TabManager) CreateTab(url string) (string, context.Context, context.Ca
tm.onTabSetup(ctx)
}
- // Configure resource blocking based on settings
var blockPatterns []string
-
+
if tm.config.BlockAds {
blockPatterns = CombineBlockPatterns(blockPatterns, AdBlockPatterns)
}
-
+
if tm.config.BlockMedia {
blockPatterns = CombineBlockPatterns(blockPatterns, MediaBlockPatterns)
} else if tm.config.BlockImages {
blockPatterns = CombineBlockPatterns(blockPatterns, ImageBlockPatterns)
}
-
+
if len(blockPatterns) > 0 {
_ = SetResourceBlocking(ctx, blockPatterns)
}
diff --git a/internal/handlers/navigation.go b/internal/handlers/navigation.go
index 17e6cbd7..9c4267ca 100644
--- a/internal/handlers/navigation.go
+++ b/internal/handlers/navigation.go
@@ -51,10 +51,8 @@ func (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {
navTimeout = time.Duration(req.Timeout * float64(time.Second))
}
- // Build block patterns based on request and config
var blockPatterns []string
- // Handle explicit request overrides first
blockAds := h.Config.BlockAds
if req.BlockAds != nil {
blockAds = *req.BlockAds
@@ -70,7 +68,6 @@ func (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {
blockImages = *req.BlockImages
}
- // Combine patterns based on flags
if blockAds {
blockPatterns = bridge.CombineBlockPatterns(blockPatterns, bridge.AdBlockPatterns)
}
@@ -78,7 +75,6 @@ func (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {
if blockMedia {
blockPatterns = bridge.CombineBlockPatterns(blockPatterns, bridge.MediaBlockPatterns)
} else if blockImages {
- // Only block images if not already blocking all media
blockPatterns = bridge.CombineBlockPatterns(blockPatterns, bridge.ImageBlockPatterns)
}
diff --git a/internal/handlers/proxy_ws.go b/internal/handlers/proxy_ws.go
index 416df93f..68b1aefb 100644
--- a/internal/handlers/proxy_ws.go
+++ b/internal/handlers/proxy_ws.go
@@ -11,10 +11,8 @@ import (
"strings"
)
-// ProxyWebSocket does a raw TCP tunnel for WebSocket connections.
-// Uses proper HTTP request construction for standards compliance.
+// ProxyWebSocket tunnels WebSocket connections with proper HTTP headers
func ProxyWebSocket(w http.ResponseWriter, r *http.Request, targetURL string) {
- // Parse target URL
wsTarget := strings.TrimPrefix(targetURL, "http://")
wsTarget = strings.TrimPrefix(wsTarget, "https://")
@@ -25,7 +23,6 @@ func ProxyWebSocket(w http.ResponseWriter, r *http.Request, targetURL string) {
path = wsTarget[idx:]
}
- // Connect to backend
backend, err := net.Dial("tcp", host)
if err != nil {
http.Error(w, "backend unavailable", http.StatusBadGateway)
@@ -34,7 +31,6 @@ func ProxyWebSocket(w http.ResponseWriter, r *http.Request, targetURL string) {
}
defer func() { _ = backend.Close() }()
- // Hijack client connection
hj, ok := w.(http.Hijacker)
if !ok {
http.Error(w, "server doesn't support hijacking", http.StatusInternalServerError)
@@ -47,34 +43,25 @@ func ProxyWebSocket(w http.ResponseWriter, r *http.Request, targetURL string) {
}
defer func() { _ = client.Close() }()
- // Write properly formatted HTTP request to backend
writer := bufio.NewWriter(backend)
-
- // Request line
+
_, _ = fmt.Fprintf(writer, "%s %s HTTP/1.1\r\n", r.Method, path)
-
- // Host header (required for HTTP/1.1)
_, _ = fmt.Fprintf(writer, "Host: %s\r\n", host)
-
- // Copy other headers (using canonical header format)
+
for name, values := range r.Header {
- // textproto.CanonicalMIMEHeaderKey ensures proper header formatting
canonicalName := textproto.CanonicalMIMEHeaderKey(name)
for _, value := range values {
_, _ = fmt.Fprintf(writer, "%s: %s\r\n", canonicalName, value)
}
}
-
- // End of headers
+
_, _ = fmt.Fprintf(writer, "\r\n")
-
- // Flush the buffered request
+
if err := writer.Flush(); err != nil {
slog.Error("ws proxy: failed to write request", "err", err)
return
}
- // Bidirectional copy between client and backend
done := make(chan struct{}, 2)
go func() {
_, _ = io.Copy(client, backend)
@@ -84,7 +71,6 @@ func ProxyWebSocket(w http.ResponseWriter, r *http.Request, targetURL string) {
_, _ = io.Copy(backend, client)
done <- struct{}{}
}()
-
- // Wait for one direction to complete
+
<-done
}