Replace JS dialog stubs with CDP-level dismiss_dialog()#2
Closed
MagMueller wants to merge 3 commits intomainfrom
Closed
Replace JS dialog stubs with CDP-level dismiss_dialog()#2MagMueller wants to merge 3 commits intomainfrom
MagMueller wants to merge 3 commits intomainfrom
Conversation
capture_dialogs()/dialogs() required calling before the dialog fired, couldn't handle beforeunload, and broke when the JS thread was frozen. dismiss_dialog() uses Page.handleJavaScriptDialog via CDP which works on all dialog types even when JS is blocked. Also makes goto() auto-clear window.onbeforeunload to prevent the most common source of stuck automation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
They solve different problems: capture_dialogs() is proactive (auto-approve confirms, swallow multiple alerts without blocking), dismiss_dialog() is reactive (beforeunload, frozen pages, unexpected dialogs). Updated docstrings to clarify when to use each. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="helpers.py">
<violation number="1" location="helpers.py:277">
P2: `capture_dialogs()` prompt stub drops valid falsy default values by using `d||''`; use a null/undefined check so `0`/`false` are preserved.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
| Call BEFORE the action that triggers the dialog; read with dialogs(). | ||
| Good for known flows with multiple alerts or confirm() calls that should auto-approve. | ||
| For beforeunload or already-frozen pages, use dismiss_dialog() instead.""" | ||
| js("window.__dialogs__=[];window.alert=m=>window.__dialogs__.push(String(m));window.confirm=m=>{window.__dialogs__.push(String(m));return true;};window.prompt=(m,d)=>{window.__dialogs__.push(String(m));return d||'';}") |
Contributor
There was a problem hiding this comment.
P2: capture_dialogs() prompt stub drops valid falsy default values by using d||''; use a null/undefined check so 0/false are preserved.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At helpers.py, line 277:
<comment>`capture_dialogs()` prompt stub drops valid falsy default values by using `d||''`; use a null/undefined check so `0`/`false` are preserved.</comment>
<file context>
@@ -267,6 +269,18 @@ def dismiss_dialog(accept=True):
+ Call BEFORE the action that triggers the dialog; read with dialogs().
+ Good for known flows with multiple alerts or confirm() calls that should auto-approve.
+ For beforeunload or already-frozen pages, use dismiss_dialog() instead."""
+ js("window.__dialogs__=[];window.alert=m=>window.__dialogs__.push(String(m));window.confirm=m=>{window.__dialogs__.push(String(m));return true;};window.prompt=(m,d)=>{window.__dialogs__.push(String(m));return d||'';}")
+
+def dialogs():
</file context>
Suggested change
| js("window.__dialogs__=[];window.alert=m=>window.__dialogs__.push(String(m));window.confirm=m=>{window.__dialogs__.push(String(m));return true;};window.prompt=(m,d)=>{window.__dialogs__.push(String(m));return d||'';}") | |
| js("window.__dialogs__=[];window.alert=m=>window.__dialogs__.push(String(m));window.confirm=m=>{window.__dialogs__.push(String(m));return true;};window.prompt=(m,d)=>{window.__dialogs__.push(String(m));return d==null?'':String(d);}") |
- goto(): no longer injects JS to clear onbeforeunload. Instead,
navigates first then auto-dismisses any beforeunload dialog via
CDP. Zero page JS touched, undetectable by antibot.
- dismiss_dialog(): now returns {type, message, url} so the agent
can read what the dialog says and decide how to respond.
- SKILL.md: document antibot tradeoff between capture_dialogs()
(JS injection, detectable) vs dismiss_dialog() (CDP-level, safe).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dismiss_dialog(accept=True)replacescapture_dialogs()/dialogs()— usesPage.handleJavaScriptDialogvia CDP, works on all dialog types (alert,confirm,prompt,beforeunload) even when the JS thread is frozengoto()auto-clearswindow.onbeforeunloadbefore navigating, preventing the most common source of stuck automationWhy
The JS-level stubs had three failure modes we hit in production:
beforeunloaddialogs aren't interceptable via JS stubscapture_dialogs(), the nextalert()freezes the sessionCDP's
Page.handleJavaScriptDialogoperates at the browser level and handles all three cases.Test plan
dismiss_dialog()dismissesbeforeunloaddialogs on TikTok Studiogoto()navigates cleanly without triggeringbeforeunloadblockingdismiss_dialog()returns the dialog message from CDP events🤖 Generated with Claude Code
Summary by cubic
Replaced JS-based dialog handling with a CDP-level
dismiss_dialog()and updatedgoto()to auto-dismissbeforeunloadvia CDP, avoiding JS injection and antibot flags. Keptcapture_dialogs()for proactive flows.dismiss_dialog(accept=True)usingPage.handleJavaScriptDialog; works foralert,confirm,prompt, andbeforeunload, returns{type, message, url}, can be called after the dialog appears, and is antibot-safe.capture_dialogs()/dialogs()with clearer docs: use for known flows to auto-approve or swallow multiple alerts; note this injects JS and can be detected. Usedismiss_dialog()forbeforeunload, frozen pages, or unexpected dialogs.goto()now navigates first, then auto-dismisses anybeforeunloaddialog via CDP (no page JS touched, undetectable). SKILL.md updated to document this tradeoff.Written for commit 7ee18cd. Summary will update on new commits.