refactor(skill): 主技能 subskill 目录更名 subskills(09-02 用户要求)
- V1.0/subskill/ → V1.0/subskills/(browser-harness/mcn-dou-analysis/mcn-script-review/mcn-video-prompt,git 识别 R100 纯重命名保留历史) - 路径说明同步:V1.0/SKILL.md(96/105行)、Lite1.0/SKILL.md(66行)、mcn-dou-analysis/SKILL.md 红线行、操作规范.md 159/175行、mcn-work-shop app.js SKILL_HINT_ACCOUNT - 用户环境 ~/.workbuddy/skills/短视频脚本创作/ 与源仓库 V1.0 同 inode(junction),自动同步无需单独改 - mcn-dou-analysis 内部 subskills/nuwa-skill-main 为正常结构不受影响
This commit is contained in:
1 parent
19bf4949a9
commit
f1f6288b7b
520 files changed
+14
-9
No files matched your search
@@ -0,0 +1,64 @@
|
||||
# Dialogs
|
||||
|
||||
Browser dialogs (`alert`, `confirm`, `prompt`, `beforeunload`) freeze the JS thread. Two approaches depending on timing.
|
||||
|
||||
## Detection
|
||||
|
||||
`page_info()` auto-surfaces any open dialog: if one is pending it returns `{"dialog": {"type", "message", ...}}` instead of the usual viewport dict (because the page's JS is frozen anyway). So if you call `page_info()` after an action and see a `dialog` key, handle it before doing anything else.
|
||||
|
||||
## Reactive: dismiss via CDP (preferred)
|
||||
|
||||
Works even when JS is frozen. Handles all dialog types including `beforeunload`.
|
||||
|
||||
```python
|
||||
# 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.
|
||||
|
||||
```python
|
||||
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||'';};
|
||||
""")
|
||||
# ... do actions that trigger dialogs ...
|
||||
msgs = js("window.__dialogs__||[]")
|
||||
```
|
||||
|
||||
Tradeoffs:
|
||||
- Stubs are lost on page navigation -- must re-run the snippet
|
||||
- `confirm()` always returns `true` (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.
|
||||
|
||||
```python
|
||||
# Option A: dismiss after navigating (CDP-level, safe)
|
||||
goto_url("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_url("https://new-url.com")
|
||||
```
|
||||
Reference in new issue
Block a user