Skip to content

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

feat: implement hash-based tab IDs in handlers (Phase 6 complete!)

Mario2986e42d9f29
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index c393fa30..62e44cb3 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -7,6 +7,7 @@ import (
"github.com/pinchtab/pinchtab/internal/bridge"
"github.com/pinchtab/pinchtab/internal/config"
"github.com/pinchtab/pinchtab/internal/dashboard"
+ "github.com/pinchtab/pinchtab/internal/idutil"
)
type Handlers struct {
@@ -15,6 +16,7 @@ type Handlers struct {
Profiles bridge.ProfileService
Dashboard *dashboard.Dashboard
Orchestrator bridge.OrchestratorService
+ IdMgr *idutil.Manager
}
func New(b bridge.BridgeAPI, cfg *config.RuntimeConfig, p bridge.ProfileService, d *dashboard.Dashboard, o bridge.OrchestratorService) *Handlers {
@@ -24,6 +26,7 @@ func New(b bridge.BridgeAPI, cfg *config.RuntimeConfig, p bridge.ProfileService,
Profiles: p,
Dashboard: d,
Orchestrator: o,
+ IdMgr: idutil.NewManager(),
}
}
diff --git a/internal/handlers/navigation.go b/internal/handlers/navigation.go
index 0593e1df..4ce20022 100644
--- a/internal/handlers/navigation.go
+++ b/internal/handlers/navigation.go
@@ -116,7 +116,10 @@ func (h *Handlers) HandleNavigate(w http.ResponseWriter, r *http.Request) {
targetID = newTargetID
}
- web.JSON(w, 200, map[string]any{"tabId": targetID, "url": url, "title": title})
+ // Convert CDP target ID to hash-based tab ID
+ hashTabID := h.IdMgr.TabIDFromCDPTarget(targetID)
+
+ web.JSON(w, 200, map[string]any{"tabId": hashTabID, "url": url, "title": title})
return
}
@@ -215,7 +218,11 @@ func (h *Handlers) HandleTab(w http.ResponseWriter, r *http.Request) {
var curURL, title string
_ = chromedp.Run(ctx, chromedp.Location(&curURL), chromedp.Title(&title))
- web.JSON(w, 200, map[string]any{"tabId": newTargetID, "url": curURL, "title": title})
+
+ // Convert CDP target ID to hash-based tab ID
+ hashTabID := h.IdMgr.TabIDFromCDPTarget(newTargetID)
+
+ web.JSON(w, 200, map[string]any{"tabId": hashTabID, "url": curURL, "title": title})
case tabActionClose:
if req.TabID == "" {
diff --git a/internal/idutil/idutil.go b/internal/idutil/idutil.go
index 63b8502b..508643b4 100644
--- a/internal/idutil/idutil.go
+++ b/internal/idutil/idutil.go
@@ -37,6 +37,14 @@ func (m *Manager) TabID(instanceID string, tabIndex int) string {
return hashID("tab", data)
}
+// TabIDFromCDPTarget converts a CDP target ID to a hash-based tab ID
+// Used when creating tabs dynamically via CDP
+// Format: tab_XXXXXXXX (12 chars total)
+func (m *Manager) TabIDFromCDPTarget(cdpTargetID string) string {
+ // Hash the CDP target ID to create a stable, shorter tab ID
+ return hashID("tab", cdpTargetID)
+}
+
// hashID creates a short hash-based ID with the given prefix
// Format: {prefix}_{first 8 hex chars of SHA256}
func hashID(prefix, data string) string {