browser-use--browser-harness
d6942b61fe
Two skill categories, pure markdown, no Python files: - interaction-skills/ — generic browser patterns (dialogs, inputs, etc.) Flat .md files. Agent reads the relevant one before a task. - domain-skills/ — per-site playbooks (tiktok/, linkedin/, etc.) Flat .md files per action (upload, schedule, post). Subfolders for large domains when needed. Starting with: - interaction-skills/dialogs.md — CDP vs JS dialog handling - domain-skills/tiktok/upload.md — full upload flow with gotchas - Placeholder folders for linkedin, spreadshirt, salesforce Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1.8 KiB
1.8 KiB
Dialogs
Browser dialogs (alert, confirm, prompt, beforeunload) freeze the JS thread. Two approaches depending on timing.
Reactive: dismiss via CDP (preferred)
Works even when JS is frozen. Handles all dialog types including beforeunload.
# Dismiss and read the message
cdp("Page.handleJavaScriptDialog", accept=True) # accept / click OK
cdp("Page.handleJavaScriptDialog", accept=False) # cancel / click Cancel
# Read what the dialog said (from buffered CDP events)
events = drain_events()
for e in events:
if e["method"] == "Page.javascriptDialogOpening":
print(e["params"]["type"]) # "alert", "confirm", "prompt", "beforeunload"
print(e["params"]["message"]) # the dialog text
Undetectable by antibot — no JS injected into the page.
Proactive: stub via JS
Prevents dialogs from ever appearing. Good when you expect multiple alert()/confirm() calls in sequence.
capture_dialogs() # replaces window.alert/confirm/prompt with stubs
# ... do actions that trigger dialogs ...
msgs = dialogs() # read captured messages
Tradeoffs:
- Stubs are lost on page navigation — must re-call
capture_dialogs() confirm()always returnstrue(auto-approves)- Detectable by antibot (
window.alert.toString()reveals non-native code) - Does NOT handle
beforeunload
beforeunload specifically
Fires when navigating away from a page with unsaved changes (forms, editors, upload pages). The page freezes until the user clicks Leave/Stay.
# Option A: dismiss after navigating (CDP-level, safe)
goto("https://new-url.com")
try:
cdp("Page.handleJavaScriptDialog", accept=True) # click "Leave"
except:
pass # no dialog — normal
# Option B: prevent before navigating (JS injection, detectable)
js("window.onbeforeunload=null")
goto("https://new-url.com")