Skip to content

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

fix: only save tabs that were accessed during the session

Marioda3ff4acd07c
diff --git a/internal/bridge/bridge.go b/internal/bridge/bridge.go
index 2e68a176..d9af28af 100644
--- a/internal/bridge/bridge.go
+++ b/internal/bridge/bridge.go
@@ -12,8 +12,9 @@ import (
)
type TabEntry struct {
- Ctx context.Context
- Cancel context.CancelFunc
+ Ctx context.Context
+ Cancel context.CancelFunc
+ Accessed bool
}
type RefCache struct {
diff --git a/internal/bridge/state.go b/internal/bridge/state.go
index 41cb0a8b..8324bb6e 100644
--- a/internal/bridge/state.go
+++ b/internal/bridge/state.go
@@ -82,6 +82,7 @@ func (b *Bridge) SaveState() {
return
}
+ accessed := b.AccessedTabIDs()
tabs := make([]TabState, 0, len(targets))
seen := make(map[string]bool, len(targets))
for _, t := range targets {
@@ -91,6 +92,9 @@ func (b *Bridge) SaveState() {
if seen[t.URL] {
continue
}
+ if !accessed[string(t.TargetID)] {
+ continue
+ }
seen[t.URL] = true
tabs = append(tabs, TabState{
ID: string(t.TargetID),
diff --git a/internal/bridge/tab_manager.go b/internal/bridge/tab_manager.go
index 7176d6bc..838cf94b 100644
--- a/internal/bridge/tab_manager.go
+++ b/internal/bridge/tab_manager.go
@@ -19,6 +19,7 @@ type TabManager struct {
browserCtx context.Context
config *config.RuntimeConfig
tabs map[string]*TabEntry
+ accessed map[string]bool
snapshots map[string]*RefCache
onTabSetup TabSetupFunc
mu sync.RWMutex
@@ -29,11 +30,29 @@ func NewTabManager(browserCtx context.Context, cfg *config.RuntimeConfig, onTabS
browserCtx: browserCtx,
config: cfg,
tabs: make(map[string]*TabEntry),
+ accessed: make(map[string]bool),
snapshots: make(map[string]*RefCache),
onTabSetup: onTabSetup,
}
}
+func (tm *TabManager) markAccessed(tabID string) {
+ tm.mu.Lock()
+ tm.accessed[tabID] = true
+ tm.mu.Unlock()
+}
+
+// AccessedTabIDs returns the set of tab IDs that were accessed this session.
+func (tm *TabManager) AccessedTabIDs() map[string]bool {
+ tm.mu.RLock()
+ defer tm.mu.RUnlock()
+ out := make(map[string]bool, len(tm.accessed))
+ for k := range tm.accessed {
+ out[k] = true
+ }
+ return out
+}
+
func (tm *TabManager) TabContext(tabID string) (context.Context, string, error) {
if tabID == "" {
targets, err := tm.ListTargets()
@@ -49,6 +68,7 @@ func (tm *TabManager) TabContext(tabID string) (context.Context, string, error)
tm.mu.RLock()
if entry, ok := tm.tabs[tabID]; ok && entry.Ctx != nil {
tm.mu.RUnlock()
+ tm.markAccessed(tabID)
return entry.Ctx, tabID, nil
}
tm.mu.RUnlock()
@@ -57,6 +77,7 @@ func (tm *TabManager) TabContext(tabID string) (context.Context, string, error)
defer tm.mu.Unlock()
if entry, ok := tm.tabs[tabID]; ok && entry.Ctx != nil {
+ tm.accessed[tabID] = true
return entry.Ctx, tabID, nil
}
@@ -118,6 +139,7 @@ func (tm *TabManager) CreateTab(url string) (string, context.Context, context.Ca
newTargetID := string(chromedp.FromContext(ctx).Target.TargetID)
tm.mu.Lock()
tm.tabs[newTargetID] = &TabEntry{Ctx: ctx, Cancel: cancel}
+ tm.accessed[newTargetID] = true
tm.mu.Unlock()
return newTargetID, ctx, cancel, nil