High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: dialog action and action hover
Bosch4da303a316e3
diff --git a/internal/bridge/action_pointer.go b/internal/bridge/action_pointer.goindex 674c7aa3..37b8a426 100644--- a/internal/bridge/action_pointer.go+++ b/internal/bridge/action_pointer.go@@ -67,6 +67,15 @@ func submitFormIfButton(ctx context.Context, selector string) (bool, error) {}func (b *Bridge) actionClick(ctx context.Context, req ActionRequest) (map[string]any, error) {+ // Arm a one-shot dialog auto-handler if the caller expects the click+ // to open a native JS dialog. Without this, the click would hang+ // waiting for the dialog to be handled from a separate request.+ if req.DialogAction != "" && req.TabID != "" {+ if dm := b.GetDialogManager(); dm != nil {+ dm.ArmAutoHandler(req.TabID, req.DialogAction, req.DialogText)+ }+ }+var err errorif req.Selector != "" {// For submit buttons, use requestSubmit() to fire constraint validation,@@ -120,9 +129,11 @@ func (b *Bridge) actionHover(ctx context.Context, req ActionRequest) (map[stringreturn map[string]any{"hovered": true}, HoverByNodeID(ctx, req.NodeID)}if req.Selector != "" {- return map[string]any{"hovered": true}, chromedp.Run(ctx,- chromedp.Evaluate(fmt.Sprintf(`document.querySelector(%q)?.dispatchEvent(new MouseEvent('mouseover', {bubbles:true}))`, req.Selector), nil),- )+ node, err := firstNodeBySelector(ctx, req.Selector)+ if err != nil {+ return nil, err+ }+ return map[string]any{"hovered": true}, HoverByNodeID(ctx, int64(node.BackendNodeID))}if req.HasXY {return map[string]any{"hovered": true}, HoverByCoordinate(ctx, req.X, req.Y)diff --git a/internal/bridge/bridge.go b/internal/bridge/bridge.goindex 1ed0d35d..03db9d10 100644--- a/internal/bridge/bridge.go+++ b/internal/bridge/bridge.go@@ -87,6 +87,7 @@ func New(allocCtx, browserCtx context.Context, cfg *config.RuntimeConfig) *BridgstealthLaunchMode: stealth.LaunchModeUninitialized,}b.ensureStealthBundle()+ b.Dialogs = NewDialogManager()// Only initialize TabManager if browserCtx is provided (not lazy-init case)if cfg != nil && browserCtx != nil {b.TabManager = NewTabManager(browserCtx, cfg, idMgr, logStore, b.tabSetup)@@ -97,7 +98,6 @@ func New(allocCtx, browserCtx context.Context, cfg *config.RuntimeConfig) *Bridg}}b.Locks = NewLockManager()- b.Dialogs = NewDialogManager()b.InitActionRegistry()return b}@@ -628,6 +628,15 @@ type ActionRequest struct {WaitNav bool `json:"waitNav"`Fast bool `json:"fast"`Owner string `json:"owner"`++ // DialogAction arms a one-shot dialog auto-handler before the action+ // executes. Used when clicking a button/link that opens a JS dialog+ // (alert/confirm/prompt). Values: "accept" or "dismiss". When set, the+ // dialog is handled automatically without a second HTTP call.+ DialogAction string `json:"dialogAction,omitempty"`+ // DialogText is the optional prompt text used when DialogAction is+ // "accept" on a prompt() dialog.+ DialogText string `json:"dialogText,omitempty"`}// NormalizeSelector merges legacy Ref and Selector (CSS) fields into thediff --git a/internal/bridge/tab_manager.go b/internal/bridge/tab_manager.goindex 187bbae3..7aab0e95 100644--- a/internal/bridge/tab_manager.go+++ b/internal/bridge/tab_manager.go@@ -209,6 +209,13 @@ func (tm *TabManager) TabContext(tabID string) (context.Context, string, error)slog.Warn("eager network capture failed", "tab", tabID, "err", err)}}+ if tm.dialogMgr != nil {+ autoAccept := tm.config != nil && tm.config.DialogAutoAccept+ ListenDialogEvents(ctx, tabID, tm.dialogMgr, autoAccept)+ if err := EnableDialogEvents(ctx); err != nil {+ slog.Warn("enable dialog events failed", "tabId", tabID, "err", err)+ }+ }tm.RegisterTabWithCancel(tabID, raw, ctx, cancel)tm.mu.RLock()@@ -375,6 +382,11 @@ func (tm *TabManager) CreateTab(url string) (string, context.Context, context.Caif tm.dialogMgr != nil {autoAccept := tm.config != nil && tm.config.DialogAutoAcceptListenDialogEvents(ctx, tabID, tm.dialogMgr, autoAccept)+ // Page domain must be enabled for Page.javascriptDialogOpening events+ // to be delivered to ListenTarget callbacks.+ if err := EnableDialogEvents(ctx); err != nil {+ slog.Warn("enable dialog events failed", "tabId", tabID, "err", err)+ }}if tm.shouldEagerlyCaptureConsole() {diff --git a/internal/bridge/tabs/dialog.go b/internal/bridge/tabs/dialog.goindex cc79817e..454b1588 100644--- a/internal/bridge/tabs/dialog.go+++ b/internal/bridge/tabs/dialog.go@@ -25,14 +25,40 @@ type DialogState struct {type DialogManager struct {mu sync.RWMutexpending map[string]*DialogState+ armed map[string]*ArmedDialogHandler+}++// ArmedDialogHandler is a one-shot auto-handler for the next dialog on a tab.+type ArmedDialogHandler struct {+ Action string // "accept" or "dismiss"+ Text string // optional prompt text}func NewDialogManager() *DialogManager {return &DialogManager{pending: make(map[string]*DialogState),+ armed: make(map[string]*ArmedDialogHandler),}}+// ArmAutoHandler sets a one-shot auto-handler for the next dialog on the+// given tab. The handler is consumed when the dialog fires, or remains armed+// if no dialog appears.+func (dm *DialogManager) ArmAutoHandler(tabID, action, text string) {+ dm.mu.Lock()+ defer dm.mu.Unlock()+ dm.armed[tabID] = &ArmedDialogHandler{Action: action, Text: text}+}++// TakeAutoHandler retrieves and removes the armed auto-handler for a tab.+func (dm *DialogManager) TakeAutoHandler(tabID string) *ArmedDialogHandler {+ dm.mu.Lock()+ defer dm.mu.Unlock()+ h := dm.armed[tabID]+ delete(dm.armed, tabID)+ return h+}+func (dm *DialogManager) SetPending(tabID string, state *DialogState) {dm.mu.Lock()defer dm.mu.Unlock()@@ -76,14 +102,40 @@ func ListenDialogEvents(ctx context.Context, tabID string, dm *DialogManager, au})slog.Debug("dialog opened", "tabId", tabID, "type", e.Type)+ // Check for a one-shot armed handler first (set via ArmAutoHandler+ // before a click that is expected to open a dialog).+ if armed := dm.TakeAutoHandler(tabID); armed != nil {+ accept := armed.Action == "accept"+ promptText := armed.Text+ if promptText == "" {+ promptText = e.DefaultPrompt+ }+ state.HasBrowserHandler = true+ // Dispatch in a goroutine because HandleDialog sends a CDP+ // command, and the enclosing ListenTarget callback runs on+ // the CDP event loop — doing CDP work here would deadlock.+ go func() {+ if err := HandleDialog(ctx, accept, promptText); err != nil {+ slog.Warn("armed dialog handler failed", "tabId", tabID, "err", err)+ dm.SetPending(tabID, state)+ } else {+ slog.Debug("dialog auto-handled", "tabId", tabID, "type", e.Type, "action", armed.Action)+ }+ }()+ return+ }+if autoAccept {state.HasBrowserHandler = true- if err := HandleDialog(ctx, true, e.DefaultPrompt); err != nil {- slog.Warn("auto-accept dialog failed", "tabId", tabID, "err", err)- dm.SetPending(tabID, state)- } else {- slog.Debug("dialog auto-accepted", "tabId", tabID, "type", e.Type)- }+ // Same reasoning as above — dispatch in a goroutine.+ go func() {+ if err := HandleDialog(ctx, true, e.DefaultPrompt); err != nil {+ slog.Warn("auto-accept dialog failed", "tabId", tabID, "err", err)+ dm.SetPending(tabID, state)+ } else {+ slog.Debug("dialog auto-accepted", "tabId", tabID, "type", e.Type)+ }+ }()} else {dm.SetPending(tabID, state)}diff --git a/skills/pinchtab/SKILL.md b/skills/pinchtab/SKILL.mdindex 3c38525f..edb1d5d2 100644--- a/skills/pinchtab/SKILL.md+++ b/skills/pinchtab/SKILL.md@@ -223,6 +223,7 @@ Rules:- Prefer `click --wait-nav` when a click is expected to navigate.- Re-snapshot immediately after `click`, `press Enter`, `select`, or `scroll` if the UI can change.- To discover valid dropdown values, snapshot with `filter=interactive` first — the output shows `<option>` elements with their `value` attributes. Then use `select` with the exact value.+- If a click opens a JS dialog (`alert`, `confirm`, `prompt`), pass `"dialogAction": "accept"` or `"dialogAction": "dismiss"` on the click action body. The dialog is auto-handled in a single call. Without this, the click hangs until `/tabs/TAB_ID/dialog` is called from a parallel request, and a pending dialog wedges subsequent `/snapshot` and `/text` calls.### Export, debug, and verification