Skip to content

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

fix(dialog): a fixed-duration wait refuses a dialog-blocked tab with 409 dialog_blocked like every other wait form (PIN-425)

Luigi Agosti4bbea7787706
diff --git a/internal/handlers/tab_guards_test.go b/internal/handlers/tab_guards_test.go
index a9365f7e..8d253547 100644
--- a/internal/handlers/tab_guards_test.go
+++ b/internal/handlers/tab_guards_test.go
@@ -517,6 +517,44 @@ func TestRootStorageRefusesADialogBlockedTabForEveryMethod(t *testing.T) {
}
}
+func TestFixedDurationWaitRefusesADialogBlockedTab(t *testing.T) {
+ for _, target := range []string{"/wait", "/tabs/tab1/wait"} {
+ t.Run(target, func(t *testing.T) {
+ b := &guardProbeBridge{currentURL: "https://allowed.example/", dialogs: pendingDialogManager()}
+ h := New(b, allCapabilities(t, t.TempDir()), nil, nil, nil)
+ mux := http.NewServeMux()
+ h.RegisterRoutes(mux, nil)
+
+ req := httptest.NewRequest(http.MethodPost, target, strings.NewReader(`{"tabId":"tab1","ms":50}`))
+ req.Header.Set("Content-Type", "application/json")
+ w := httptest.NewRecorder()
+ mux.ServeHTTP(w, req)
+
+ var resp struct {
+ Code string `json:"code"`
+ }
+ _ = json.Unmarshal(w.Body.Bytes(), &resp)
+ if resp.Code != dialogBlockedCode {
+ t.Fatalf("POST %s {ms} on a dialog-blocked tab answered %d %s, want %s", target, w.Code, w.Body.String(), dialogBlockedCode)
+ }
+ })
+ }
+}
+
+func TestFixedDurationWaitStillSleepsWithoutAPendingDialog(t *testing.T) {
+ b := &guardProbeBridge{currentURL: "https://allowed.example/"}
+ h := New(b, allCapabilities(t, t.TempDir()), nil, nil, nil)
+
+ req := httptest.NewRequest(http.MethodPost, "/wait", strings.NewReader(`{"tabId":"tab1","ms":1}`))
+ req.Header.Set("Content-Type", "application/json")
+ w := httptest.NewRecorder()
+ h.HandleWait(w, req)
+
+ if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), `"waited":true`) {
+ t.Fatalf("POST /wait {ms} without a dialog answered %d %s, want 200 waited", w.Code, w.Body.String())
+ }
+}
+
var mustDeclareDialogGuard = []string{
"POST /navigate", "POST /back", "POST /forward", "POST /reload",
"GET /snapshot", "GET /screenshot", "GET /annotate", "GET /capture", "GET /text", "GET /title", "GET /url", "GET /html", "GET /styles",
diff --git a/internal/handlers/wait.go b/internal/handlers/wait.go
index 85a9d1c8..6f16360d 100644
--- a/internal/handlers/wait.go
+++ b/internal/handlers/wait.go
@@ -147,8 +147,10 @@ func (h *Handlers) handleWaitCore(w http.ResponseWriter, r *http.Request, req wa
return
}
- // Fixed duration wait doesn't need a browser tab.
if mode == "ms" {
+ if _, tabID, err := h.tabContext(r, req.TabID); err == nil && h.refuseIfDialogBlocked(w, tabID) {
+ return
+ }
ms := *req.Ms
if ms < 0 {
ms = 0