High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(activity): enrich navigate URL and action details in all proxy paths
Boschec437c9ab5b4
diff --git a/internal/activity/context.go b/internal/activity/context.goindex da2a39ef..984ee07b 100644--- a/internal/activity/context.go+++ b/internal/activity/context.go@@ -1,7 +1,10 @@package activityimport (+ "bytes""context"+ "encoding/json"+ "io""net/http""strings""sync"@@ -268,3 +271,46 @@ func initialURL(r *http.Request) string {}return ""}++// EnrichRouteActivity peeks at the request body for action and navigate+// requests to extract kind, ref, and url for the activity stream. The body+// is restored for the downstream proxy handler.+func EnrichRouteActivity(r *http.Request) {+ if r == nil || r.Body == nil || r.Method != http.MethodPost {+ return+ }+ path := r.URL.Path+ isAction := path == "/action" || strings.HasSuffix(path, "/action")+ isNavigate := path == "/navigate" || strings.HasSuffix(path, "/navigate")+ if !isAction && !isNavigate {+ return+ }++ body, err := io.ReadAll(io.LimitReader(r.Body, 8<<10))+ if err != nil || len(body) == 0 {+ return+ }+ r.Body = io.NopCloser(bytes.NewReader(body))++ var peek struct {+ Kind string `json:"kind"`+ Ref string `json:"ref"`+ URL string `json:"url"`+ }+ if json.Unmarshal(body, &peek) != nil {+ return+ }++ update := Update{}+ if isAction && peek.Kind != "" {+ update.Action = peek.Kind+ update.Ref = peek.Ref+ }+ if isNavigate && peek.URL != "" {+ update.Action = "navigate"+ update.URL = peek.URL+ }+ if update.Action != "" {+ EnrichRequest(r, update)+ }+}diff --git a/internal/orchestrator/proxy.go b/internal/orchestrator/proxy.goindex 6d754405..87c3536c 100644--- a/internal/orchestrator/proxy.go+++ b/internal/orchestrator/proxy.go@@ -1,10 +1,7 @@package orchestratorimport (- "bytes"- "encoding/json""fmt"- "io""net/http""net/url""strings"@@ -30,7 +27,7 @@ func (o *Orchestrator) proxyTabRequest(w http.ResponseWriter, r *http.Request) {// Enrich activity with action/navigate details from the request body// before proxying, so the dashboard stream shows meaningful labels.- enrichRouteActivity(r)+ activity.EnrichRouteActivity(r)proxyToInstance := func(inst *bridge.Instance) {activity.EnrichRequest(r, activity.Update{@@ -326,52 +323,6 @@ func classifyLaunchError(err error) int {return 500 // Internal Server Error}-// enrichRouteActivity peeks at the request body to extract action/navigate-// details for the activity stream. This is necessary because the orchestrator-// proxies requests without parsing them, so activity would otherwise lack-// action, ref, and URL fields. The body is restored for the downstream handler.-func enrichRouteActivity(r *http.Request) {- if r.Body == nil || r.Method != http.MethodPost {- return- }- path := r.URL.Path- isAction := strings.HasSuffix(path, "/action")- isNavigate := strings.HasSuffix(path, "/navigate")- if !isAction && !isNavigate {- return- }-- body, err := io.ReadAll(io.LimitReader(r.Body, 8<<10))- if err != nil || len(body) == 0 {- return- }- // Restore the body for the downstream proxy- r.Body = io.NopCloser(bytes.NewReader(body))-- var peek struct {- Kind string `json:"kind"`- Ref string `json:"ref"`- URL string `json:"url"`- Text string `json:"text"`- }- if json.Unmarshal(body, &peek) != nil {- return- }-- update := activity.Update{}- if isAction && peek.Kind != "" {- update.Action = peek.Kind- update.Ref = peek.Ref- }- if isNavigate && peek.URL != "" {- update.Action = "navigate"- update.URL = peek.URL- }- if update.Action != "" {- activity.EnrichRequest(r, update)- }-}-func (o *Orchestrator) singleRunningInstance() *InstanceInternal {o.mu.RLock()defer o.mu.RUnlock()diff --git a/internal/strategy/autorestart/autorestart.go b/internal/strategy/autorestart/autorestart.goindex 4778f945..4ae75224 100644--- a/internal/strategy/autorestart/autorestart.go+++ b/internal/strategy/autorestart/autorestart.go@@ -20,6 +20,7 @@ import ("github.com/pinchtab/pinchtab/internal/config""github.com/pinchtab/pinchtab/internal/httpx""github.com/pinchtab/pinchtab/internal/orchestrator"+ "github.com/pinchtab/pinchtab/internal/activity""github.com/pinchtab/pinchtab/internal/strategy")@@ -418,6 +419,7 @@ func (s *Strategy) proxyToManaged(w http.ResponseWriter, r *http.Request) {httpx.Error(w, 503, err)return}+ activity.EnrichRouteActivity(r)strategy.EnrichForTarget(r, s.orch, target)s.orch.ProxyToTarget(w, r, target+r.URL.Path)}diff --git a/internal/strategy/explicit/explicit.go b/internal/strategy/explicit/explicit.goindex 900a8a5e..82639cbd 100644--- a/internal/strategy/explicit/explicit.go+++ b/internal/strategy/explicit/explicit.go@@ -11,6 +11,7 @@ import ("github.com/pinchtab/pinchtab/internal/httpx""github.com/pinchtab/pinchtab/internal/orchestrator"+ "github.com/pinchtab/pinchtab/internal/activity""github.com/pinchtab/pinchtab/internal/strategy")@@ -48,6 +49,7 @@ func (s *Strategy) proxyToFirst(w http.ResponseWriter, r *http.Request) {httpx.Error(w, 503, fmt.Errorf("no running instances — launch one from the Profiles tab"))return}+ activity.EnrichRouteActivity(r)strategy.EnrichForTarget(r, s.orch, target)s.orch.ProxyToTarget(w, r, target+r.URL.Path)}diff --git a/internal/strategy/noinstance/noinstance.go b/internal/strategy/noinstance/noinstance.goindex cbf4b958..2defdade 100644--- a/internal/strategy/noinstance/noinstance.go+++ b/internal/strategy/noinstance/noinstance.go@@ -10,6 +10,7 @@ import ("github.com/pinchtab/pinchtab/internal/httpx""github.com/pinchtab/pinchtab/internal/orchestrator"+ "github.com/pinchtab/pinchtab/internal/activity""github.com/pinchtab/pinchtab/internal/strategy")@@ -45,6 +46,7 @@ func (s *Strategy) proxyToFirst(w http.ResponseWriter, r *http.Request) {httpx.Error(w, 503, fmt.Errorf("no remote instances connected — attach a bridge first"))return}+ activity.EnrichRouteActivity(r)strategy.EnrichForTarget(r, s.orch, target)s.orch.ProxyToTarget(w, r, target+r.URL.Path)}diff --git a/internal/strategy/simple/simple.go b/internal/strategy/simple/simple.goindex e2738209..b81149c9 100644--- a/internal/strategy/simple/simple.go+++ b/internal/strategy/simple/simple.go@@ -17,6 +17,7 @@ import ("github.com/pinchtab/pinchtab/internal/httpx""github.com/pinchtab/pinchtab/internal/orchestrator"+ "github.com/pinchtab/pinchtab/internal/activity""github.com/pinchtab/pinchtab/internal/strategy")@@ -56,6 +57,7 @@ func (s *Strategy) proxyToFirst(w http.ResponseWriter, r *http.Request) {httpx.Error(w, 503, err)return}+ activity.EnrichRouteActivity(r)strategy.EnrichForTarget(r, s.orch, target)s.orch.ProxyToTarget(w, r, target+r.URL.Path)}