@xbrowser/cli 1.29.0 → 1.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{browser-XD3IOU5I.js → browser-6PFTHZI3.js} +2 -2
- package/dist/{browser-2K3XYAKM.js → browser-I2NLJN2A.js} +1 -1
- package/dist/{browser-OTEMG5NL.js → browser-KOUA4ZDA.js} +2 -2
- package/dist/{cdp-driver-AAS55KT2.js → cdp-driver-3ETNFQA4.js} +1 -1
- package/dist/{cdp-driver-XTPY7EXP.js → cdp-driver-U7HDQMQ5.js} +257 -19
- package/dist/{cdp-driver-O5I7SJ24.js → cdp-driver-WBFJNOLD.js} +1 -1
- package/dist/{chunk-SCYBNSOG.js → chunk-3K57RYVC.js} +378 -115
- package/dist/{chunk-FNXA6FDM.js → chunk-BND5O5KC.js} +2 -1
- package/dist/{chunk-P33R7F2D.js → chunk-BOZTIIBT.js} +30 -45
- package/dist/{chunk-GDKKVT2P.js → chunk-KPTD3SNJ.js} +379 -116
- package/dist/{chunk-CO2ZVOVT.js → chunk-NINETOM4.js} +30 -45
- package/dist/{chunk-SOPN4XDK.js → chunk-O5PASNI7.js} +2 -1
- package/dist/{chunk-NQPXZ74W.js → chunk-OCECE22C.js} +257 -19
- package/dist/{chunk-LFSLNHW5.js → chunk-OSIDUT4H.js} +286 -63
- package/dist/{chunk-HBMEFSTB.js → chunk-QCV2PI7U.js} +2 -1
- package/dist/{chunk-UZ6XPUBD.js → chunk-RMYKVZIZ.js} +78 -0
- package/dist/{chunk-N5XTLNKS.js → chunk-SPNWUUHA.js} +257 -19
- package/dist/{chunk-PGKV24QN.js → chunk-TBJUSUKF.js} +1 -1
- package/dist/{chunk-FCPVQFTQ.js → chunk-VYTQLZAX.js} +78 -0
- package/dist/cli.js +45 -16
- package/dist/daemon-main.js +581 -157
- package/dist/{human-interaction-CTZ4IWXJ.js → human-interaction-ISMMOJOK.js} +2 -2
- package/dist/{human-interaction-HJCK45SL.js → human-interaction-STTZZZ5N.js} +1 -1
- package/dist/{human-interaction-V3VDGHHI.js → human-interaction-UXFYV7DU.js} +1 -1
- package/dist/index.d.ts +106 -12
- package/dist/index.js +195 -46
- package/dist/{recovery-EBKORYEU.js → recovery-JFGV3DBX.js} +1 -1
- package/dist/{recovery-5C4FBA5O.js → recovery-ORHJSBDN.js} +2 -2
- package/dist/{recovery-IMZUGWSS.js → recovery-XDKN63O5.js} +1 -1
- package/dist/{server-ZTI2K5YJ.js → server-TG47W7MV.js} +3 -3
- package/dist/{server-LNZTDAKT.js → server-U3YAX5MJ.js} +2 -2
- package/dist/{session-recorder-DF2YGH2E.js → session-recorder-N7VEKJVW.js} +1 -1
- package/dist/{session-recorder-R3GDGXLJ.js → session-recorder-RUNQOJ7T.js} +1 -1
- package/dist/{session-replayer-CLTZ2URU.js → session-replayer-XLWQ47BB.js} +1 -1
- package/package.json +4 -1
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
resolveLaunchOpts,
|
|
10
10
|
saveSessionDiskMeta,
|
|
11
11
|
setActivePage
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-BOZTIIBT.js";
|
|
13
13
|
import {
|
|
14
14
|
detectAntiBot,
|
|
15
15
|
formatDetectionMessage
|
|
@@ -42,6 +42,7 @@ function registerCommand(def) {
|
|
|
42
42
|
parameters: def.parameters,
|
|
43
43
|
result: def.result,
|
|
44
44
|
selectorParams: def.selectorParams,
|
|
45
|
+
examples: def.examples,
|
|
45
46
|
handler: def.handler
|
|
46
47
|
};
|
|
47
48
|
registry.set(cmd.name, cmd);
|
|
@@ -74,25 +75,6 @@ function getRefTarget(sessionKey2, ref) {
|
|
|
74
75
|
if (!session || !target) return null;
|
|
75
76
|
return { screenHash: session.screenHash, target };
|
|
76
77
|
}
|
|
77
|
-
function inheritStableRefs(key, rawTargets) {
|
|
78
|
-
const prev = sessions.get(key);
|
|
79
|
-
if (!prev || prev.targets.size === 0) {
|
|
80
|
-
return rawTargets.map((target, index) => ({ ...target, ref: `e${index + 1}` }));
|
|
81
|
-
}
|
|
82
|
-
const bySelector = /* @__PURE__ */ new Map();
|
|
83
|
-
let maxId = 0;
|
|
84
|
-
for (const [ref, target] of prev.targets) {
|
|
85
|
-
bySelector.set(target.selector, ref);
|
|
86
|
-
const id = Number(ref.slice(1));
|
|
87
|
-
if (Number.isFinite(id) && id > maxId) maxId = id;
|
|
88
|
-
}
|
|
89
|
-
let next = maxId + 1;
|
|
90
|
-
return rawTargets.map((target) => {
|
|
91
|
-
const inherited = bySelector.get(target.selector);
|
|
92
|
-
if (inherited) return { ...target, ref: inherited };
|
|
93
|
-
return { ...target, ref: `e${next++}` };
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
78
|
|
|
97
79
|
// src/runtime/agent-runtime.ts
|
|
98
80
|
function sessionKey(sessionId) {
|
|
@@ -182,14 +164,6 @@ async function observePage(page, sessionId, options = {}) {
|
|
|
182
164
|
const direct = el.getAttribute("aria-label") || el.getAttribute("placeholder") || el.getAttribute("title") || input.value || el.textContent || "";
|
|
183
165
|
return direct.replace(/\s+/g, " ").trim().slice(0, 120);
|
|
184
166
|
}
|
|
185
|
-
function actionsFor(role, editable) {
|
|
186
|
-
const actions = [];
|
|
187
|
-
if (editable) actions.push("fill", "type");
|
|
188
|
-
if (role === "combobox") actions.push("select");
|
|
189
|
-
if (role === "checkbox" || role === "radio") actions.push("check");
|
|
190
|
-
actions.push("click", "hover");
|
|
191
|
-
return Array.from(new Set(actions));
|
|
192
|
-
}
|
|
193
167
|
const selector = [
|
|
194
168
|
"a[href]",
|
|
195
169
|
"button",
|
|
@@ -200,7 +174,14 @@ async function observePage(page, sessionId, options = {}) {
|
|
|
200
174
|
"label",
|
|
201
175
|
"[role]",
|
|
202
176
|
"[tabindex]",
|
|
203
|
-
'[contenteditable="true"]'
|
|
177
|
+
'[contenteditable="true"]',
|
|
178
|
+
// 非标准可交互控件:内联事件属性(agent-browser 基于 aria tree 完全不覆盖这类)。
|
|
179
|
+
// 仅抓 HTML 显式声明 onclick/onmousedown 等的元素;addEventListener 绑定的无法静态发现。
|
|
180
|
+
"[onclick]",
|
|
181
|
+
"[onmousedown]",
|
|
182
|
+
"[onmouseup]",
|
|
183
|
+
"[onmouseover]",
|
|
184
|
+
"[onkeydown]"
|
|
204
185
|
].join(",");
|
|
205
186
|
const candidates = Array.from(document.querySelectorAll(selector));
|
|
206
187
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -224,13 +205,10 @@ async function observePage(page, sessionId, options = {}) {
|
|
|
224
205
|
role,
|
|
225
206
|
name: textName(el),
|
|
226
207
|
tag,
|
|
227
|
-
visible,
|
|
228
208
|
enabled,
|
|
229
209
|
editable,
|
|
230
210
|
...checked !== void 0 ? { checked } : {},
|
|
231
|
-
...editable && input.value ? { value: input.value.slice(0, 120) } : {}
|
|
232
|
-
...visible ? { box: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) } } : {},
|
|
233
|
-
actions: actionsFor(role, editable)
|
|
211
|
+
...editable && input.value ? { value: input.value.slice(0, 120) } : {}
|
|
234
212
|
});
|
|
235
213
|
if (targets2.length >= limit) break;
|
|
236
214
|
}
|
|
@@ -244,13 +222,15 @@ async function observePage(page, sessionId, options = {}) {
|
|
|
244
222
|
{ includeHidden: !!options.includeHidden, limit: options.limit ?? 80 }
|
|
245
223
|
)
|
|
246
224
|
]);
|
|
247
|
-
const targets =
|
|
225
|
+
const targets = raw.targets.map((target, index) => ({
|
|
226
|
+
ref: `e${index + 1}`,
|
|
227
|
+
...target
|
|
228
|
+
}));
|
|
248
229
|
replaceRefs(sessionKey(sessionId), raw.screenHash, targets);
|
|
249
230
|
return {
|
|
250
231
|
url: page.url(),
|
|
251
232
|
title,
|
|
252
233
|
screenHash: raw.screenHash,
|
|
253
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
254
234
|
targets
|
|
255
235
|
};
|
|
256
236
|
}
|
|
@@ -435,23 +415,8 @@ async function waitForPage(page, input) {
|
|
|
435
415
|
return { success: true, matched: "selector", timeout, elapsed: Date.now() - startedAt };
|
|
436
416
|
}
|
|
437
417
|
if (input.text) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
return page.evaluate((text) => {
|
|
441
|
-
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
|
442
|
-
while (walker.nextNode()) {
|
|
443
|
-
if (walker.currentNode.textContent?.includes(text)) return true;
|
|
444
|
-
}
|
|
445
|
-
return false;
|
|
446
|
-
}, textToFind);
|
|
447
|
-
});
|
|
448
|
-
return {
|
|
449
|
-
success: matched,
|
|
450
|
-
matched: "text",
|
|
451
|
-
timeout,
|
|
452
|
-
elapsed: Date.now() - startedAt,
|
|
453
|
-
...matched ? {} : { message: `Timed out waiting for text: ${input.text}` }
|
|
454
|
-
};
|
|
418
|
+
await page.getByText(input.text).first().waitFor({ state: "visible", timeout });
|
|
419
|
+
return { success: true, matched: "text", timeout, elapsed: Date.now() - startedAt };
|
|
455
420
|
}
|
|
456
421
|
if (input.url) {
|
|
457
422
|
const matched = await pollUntil(timeout, pollInterval, async () => matchUrlPattern(page.url(), input.url));
|
|
@@ -864,14 +829,23 @@ var clickCommand = registerCommand({
|
|
|
864
829
|
clickCount: z2.number().optional(),
|
|
865
830
|
delay: z2.number().optional(),
|
|
866
831
|
waitCaptcha: z2.boolean().optional().default(false).describe("\u70B9\u51FB\u540E\u68C0\u6D4B captcha \u5E76\u7B49\u5F85\u89E3\u51B3"),
|
|
867
|
-
waitCaptchaTimeout: z2.number().int().optional().default(18e4).describe("Captcha \u7B49\u5F85\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09")
|
|
832
|
+
waitCaptchaTimeout: z2.number().int().optional().default(18e4).describe("Captcha \u7B49\u5F85\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09"),
|
|
833
|
+
frame: z2.string().optional().describe("URL \u542B\u6B64\u5B50\u4E32\u7684 OOPIF\u2014\u2014\u9009\u62E9\u5668\u5728\u8DE8\u57DF iframe \u7684 DOM \u5185\u89E3\u6790\u5E76\u70B9\u51FB\uFF08\u8FDB\u7A0B\u9694\u79BB\u4E0B\u552F\u4E00\u53EF\u4FE1\u901A\u9053\uFF09")
|
|
868
834
|
}),
|
|
869
835
|
result: z2.object({
|
|
870
836
|
selector: z2.string(),
|
|
871
837
|
newTab: z2.object({ url: z2.string(), title: z2.string() }).optional(),
|
|
872
|
-
captcha: z2.any().optional()
|
|
838
|
+
captcha: z2.any().optional(),
|
|
839
|
+
frame: z2.string().optional(),
|
|
840
|
+
x: z2.number().optional(),
|
|
841
|
+
y: z2.number().optional()
|
|
873
842
|
}),
|
|
874
843
|
handler: async (p, ctx) => {
|
|
844
|
+
const frameTarget = p.frame ?? ctx.frame;
|
|
845
|
+
if (frameTarget) {
|
|
846
|
+
const { x, y } = await ctx.page.clickInFrame(frameTarget, p.selector);
|
|
847
|
+
return ok2({ selector: p.selector, frame: frameTarget, x, y });
|
|
848
|
+
}
|
|
875
849
|
let detectedNewPage;
|
|
876
850
|
let cleanup;
|
|
877
851
|
if (ctx.browserContext?.on) {
|
|
@@ -962,15 +936,22 @@ var fillCommand = registerCommand({
|
|
|
962
936
|
parameters: z2.object({
|
|
963
937
|
selector: z2.string(),
|
|
964
938
|
value: z2.string(),
|
|
965
|
-
clear: z2.boolean().optional()
|
|
939
|
+
clear: z2.boolean().optional(),
|
|
940
|
+
frame: z2.string().optional().describe("URL \u542B\u6B64\u5B50\u4E32\u7684 OOPIF\u2014\u2014\u5728\u8DE8\u57DF iframe \u5185\u586B\u5165\uFF08\u805A\u7126\u70B9\u51FB + insertText + \u56DE\u8BFB\uFF09")
|
|
966
941
|
}),
|
|
967
942
|
result: z2.object({
|
|
968
943
|
selector: z2.string(),
|
|
969
944
|
value: z2.string(),
|
|
970
945
|
cleared: z2.boolean(),
|
|
971
|
-
reactMode: z2.boolean().optional()
|
|
946
|
+
reactMode: z2.boolean().optional(),
|
|
947
|
+
frame: z2.string().optional()
|
|
972
948
|
}),
|
|
973
949
|
handler: async (p, ctx) => {
|
|
950
|
+
const frameTarget = p.frame ?? ctx.frame;
|
|
951
|
+
if (frameTarget) {
|
|
952
|
+
const { value } = await ctx.page.fillInFrame(frameTarget, p.selector, p.value);
|
|
953
|
+
return ok2({ selector: p.selector, value, cleared: true, frame: frameTarget });
|
|
954
|
+
}
|
|
974
955
|
const page = ctx.page;
|
|
975
956
|
const shouldClear = p.clear !== false;
|
|
976
957
|
if (shouldClear) {
|
|
@@ -1157,15 +1138,22 @@ var textCommand = registerCommand({
|
|
|
1157
1138
|
scope: "page",
|
|
1158
1139
|
selectorParams: ["selector"],
|
|
1159
1140
|
parameters: z3.object({
|
|
1160
|
-
selector: z3.string().optional()
|
|
1141
|
+
selector: z3.string().optional(),
|
|
1142
|
+
frame: z3.string().optional().describe("URL \u542B\u6B64\u5B50\u4E32\u7684 OOPIF\u2014\u2014\u5728\u8DE8\u57DF iframe \u7684 DOM \u5185\u8BFB\u53D6\u6587\u672C")
|
|
1161
1143
|
}),
|
|
1162
|
-
result: z3.object({ text: z3.string() }),
|
|
1144
|
+
result: z3.object({ text: z3.string(), frame: z3.string().optional() }),
|
|
1163
1145
|
handler: async (p, ctx) => {
|
|
1146
|
+
const frameTarget = p.frame ?? ctx.frame;
|
|
1147
|
+
if (frameTarget) {
|
|
1148
|
+
const expr = p.selector ? `(() => { const el = document.querySelector(${JSON.stringify(p.selector)}); return el ? (el.textContent ?? '').trim() : null; })()` : `(document.body?.innerText || '').trim()`;
|
|
1149
|
+
const text2 = await ctx.page.evaluateInFrame(frameTarget, expr);
|
|
1150
|
+
return ok3({ text: text2 || "", frame: frameTarget });
|
|
1151
|
+
}
|
|
1164
1152
|
if (p.selector) {
|
|
1165
1153
|
const text2 = await ctx.page.textContent(p.selector);
|
|
1166
1154
|
return ok3({ text: text2 || "" });
|
|
1167
1155
|
}
|
|
1168
|
-
const text = await ctx.page.evaluate(() => document.body?.innerText || "");
|
|
1156
|
+
const text = await ctx.page.evaluate(() => (document.body?.innerText || "").trim());
|
|
1169
1157
|
return ok3({ text });
|
|
1170
1158
|
}
|
|
1171
1159
|
});
|
|
@@ -1289,43 +1277,64 @@ import { z as z6 } from "zod";
|
|
|
1289
1277
|
import { ok as ok6 } from "@dyyz1993/xcli-core";
|
|
1290
1278
|
var mouseCommand = registerCommand({
|
|
1291
1279
|
name: "mouse",
|
|
1292
|
-
description: "Control the mouse (move, click, etc.)",
|
|
1280
|
+
description: "Control the mouse (move, click, wheel, etc.) (--frame <url-substring> \u65F6\u5728\u8DE8\u57DF iframe \u5185\u64CD\u4F5C\uFF0C\u5750\u6807\u4E3A iframe \u5C40\u90E8\u5750\u6807)",
|
|
1293
1281
|
scope: "page",
|
|
1294
1282
|
parameters: z6.object({
|
|
1295
|
-
action: z6.enum(["move", "down", "up", "click", "dblclick", "drag"]),
|
|
1283
|
+
action: z6.enum(["move", "down", "up", "click", "dblclick", "drag", "wheel"]),
|
|
1296
1284
|
x: z6.coerce.number(),
|
|
1297
1285
|
y: z6.coerce.number(),
|
|
1286
|
+
"delta-x": z6.coerce.number().optional().describe("wheel \u52A8\u4F5C\uFF1A\u6A2A\u5411\u6EDA\u52A8\u91CF\uFF08\u6B63\u503C\u5411\u53F3\uFF09"),
|
|
1287
|
+
"delta-y": z6.coerce.number().optional().describe("wheel \u52A8\u4F5C\uFF1A\u7EB5\u5411\u6EDA\u52A8\u91CF\uFF08\u6B63\u503C\u5411\u4E0B\uFF09"),
|
|
1298
1288
|
button: z6.enum(["left", "right", "middle"]).optional(),
|
|
1299
|
-
steps: z6.coerce.number().optional()
|
|
1289
|
+
steps: z6.coerce.number().optional(),
|
|
1290
|
+
frame: z6.string().optional().describe("URL \u542B\u6B64\u5B50\u4E32\u7684 OOPIF\u2014\u2014\u8F93\u5165\u6D3E\u53D1\u5230 iframe \u81EA\u5DF1\u7684 session\uFF08\u8DE8\u57DF iframe \u552F\u4E00\u53EF\u4FE1\u901A\u9053\uFF09\uFF0C\u5750\u6807\u7528 iframe \u5C40\u90E8\u5750\u6807\u7CFB")
|
|
1300
1291
|
}),
|
|
1301
1292
|
result: z6.object({
|
|
1302
|
-
action: z6.enum(["move", "down", "up", "click", "dblclick", "drag"]),
|
|
1293
|
+
action: z6.enum(["move", "down", "up", "click", "dblclick", "drag", "wheel"]),
|
|
1303
1294
|
x: z6.number(),
|
|
1304
1295
|
y: z6.number()
|
|
1305
1296
|
}),
|
|
1306
1297
|
handler: async (p, ctx) => {
|
|
1307
1298
|
const button = p.button || "left";
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1299
|
+
const frame = p.frame ?? ctx.frame;
|
|
1300
|
+
const dispatch = async (mouse) => {
|
|
1301
|
+
switch (p.action) {
|
|
1302
|
+
case "move":
|
|
1303
|
+
await mouse.move(p.x, p.y, { steps: p.steps || 1 });
|
|
1304
|
+
break;
|
|
1305
|
+
case "down":
|
|
1306
|
+
await mouse.move(p.x, p.y);
|
|
1307
|
+
await mouse.down({ button });
|
|
1308
|
+
break;
|
|
1309
|
+
case "up":
|
|
1310
|
+
await mouse.move(p.x, p.y);
|
|
1311
|
+
await mouse.up({ button });
|
|
1312
|
+
break;
|
|
1313
|
+
case "click":
|
|
1314
|
+
await mouse.click(p.x, p.y, { button });
|
|
1315
|
+
break;
|
|
1316
|
+
case "dblclick":
|
|
1317
|
+
await mouse.dblclick(p.x, p.y, { button });
|
|
1318
|
+
break;
|
|
1319
|
+
case "drag":
|
|
1320
|
+
await mouse.drag(p.x, p.y, p.steps ? { steps: p.steps } : {});
|
|
1321
|
+
break;
|
|
1322
|
+
case "wheel":
|
|
1323
|
+
await mouse.wheelAt(p.x, p.y, Number(p["delta-x"] ?? 0), Number(p["delta-y"] ?? 0));
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
if (frame) {
|
|
1328
|
+
try {
|
|
1329
|
+
await ctx.page.runFrameMouse(frame, dispatch);
|
|
1330
|
+
} catch (err) {
|
|
1331
|
+
if (p.action === "drag" && /session/i.test(String(err))) {
|
|
1332
|
+
throw new Error(`frame session \u5728\u62D6\u52A8\u4E2D\u5931\u6548\uFF08iframe \u53EF\u80FD\u5DF2\u91CD\u5EFA\uFF09\u2014\u2014\u91CD\u65B0\u7528 eval --frame \u8BFB\u53D6\u76EE\u6807\u5750\u6807\u540E\u518D\u62D6`);
|
|
1333
|
+
}
|
|
1334
|
+
throw err;
|
|
1335
|
+
}
|
|
1336
|
+
} else {
|
|
1337
|
+
await dispatch(ctx.page.mouse);
|
|
1329
1338
|
}
|
|
1330
1339
|
return ok6({ action: p.action, x: p.x, y: p.y });
|
|
1331
1340
|
}
|
|
@@ -1767,7 +1776,8 @@ var evaluateCommand = registerCommand({
|
|
|
1767
1776
|
direction: "client\u2192browser"
|
|
1768
1777
|
});
|
|
1769
1778
|
engine.stop();
|
|
1770
|
-
const
|
|
1779
|
+
const frame = p.frame ?? ctx.frame;
|
|
1780
|
+
const result = frame ? await ctx.page.evaluateInFrame(frame, expression) : await ctx.page.evaluate(expression);
|
|
1771
1781
|
const response = ok9({ result });
|
|
1772
1782
|
if (decision && decision.severity === "danger") {
|
|
1773
1783
|
response.tips = normalizeTips2([`${decision.suggestion}`]);
|
|
@@ -2196,24 +2206,98 @@ import { z as z16 } from "zod";
|
|
|
2196
2206
|
import { ok as ok16, fail as fail7 } from "@dyyz1993/xcli-core";
|
|
2197
2207
|
var framesCommand = registerCommand({
|
|
2198
2208
|
name: "frames",
|
|
2199
|
-
description: "List all frames in the current page",
|
|
2209
|
+
description: "List all frames in the current page (\u542B\u8DE8\u57DF OOPIF\u2014\u2014\u5B83\u4EEC\u53EA\u5728\u6D4F\u89C8\u5668\u7EA7 target \u5217\u8868\u53EF\u89C1\uFF1B\u9644 parentUrl/depth \u5C42\u7EA7)",
|
|
2200
2210
|
scope: "page",
|
|
2201
2211
|
result: z16.object({
|
|
2202
2212
|
frames: z16.array(z16.object({
|
|
2203
2213
|
index: z16.number(),
|
|
2204
2214
|
name: z16.string().nullable(),
|
|
2205
|
-
url: z16.string()
|
|
2206
|
-
|
|
2215
|
+
url: z16.string(),
|
|
2216
|
+
oopif: z16.boolean().optional(),
|
|
2217
|
+
targetId: z16.string().optional(),
|
|
2218
|
+
parentUrl: z16.string().nullable().optional(),
|
|
2219
|
+
depth: z16.number().nullable().optional()
|
|
2220
|
+
})),
|
|
2221
|
+
warnings: z16.array(z16.string()).optional()
|
|
2207
2222
|
}),
|
|
2208
2223
|
handler: async (_p, ctx) => {
|
|
2209
2224
|
const discover = ctx.page.discoverFrames;
|
|
2210
2225
|
const rawFrames = discover ? await discover.call(ctx.page) : ctx.page.frames();
|
|
2226
|
+
const mainUrl = ctx.page.url();
|
|
2211
2227
|
const frameList = rawFrames.map((frame, index) => ({
|
|
2212
2228
|
index,
|
|
2213
2229
|
name: frame.name(),
|
|
2214
|
-
url: frame.url()
|
|
2230
|
+
url: frame.url(),
|
|
2231
|
+
parentUrl: null,
|
|
2232
|
+
depth: null
|
|
2215
2233
|
}));
|
|
2216
|
-
|
|
2234
|
+
const norm = (u) => u.replace(/\/+$/, "");
|
|
2235
|
+
for (const e of frameList) {
|
|
2236
|
+
if (norm(e.url) === norm(mainUrl)) {
|
|
2237
|
+
e.parentUrl = null;
|
|
2238
|
+
e.depth = 0;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
if (typeof ctx.page.listFrameTargets === "function") {
|
|
2242
|
+
const targets = await ctx.page.listFrameTargets();
|
|
2243
|
+
const knownUrls = new Set(frameList.map((f) => f.url));
|
|
2244
|
+
for (const t of targets) {
|
|
2245
|
+
if (knownUrls.has(t.url)) continue;
|
|
2246
|
+
frameList.push({ index: frameList.length, name: null, url: t.url, oopif: true, targetId: t.targetId, parentUrl: null, depth: null });
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
const warnings = [];
|
|
2250
|
+
try {
|
|
2251
|
+
const CHILDREN = `JSON.stringify([...document.querySelectorAll('iframe')].map(f=>({src:f.src||'',name:f.name||''})))`;
|
|
2252
|
+
const matchChild = (childSrc, frameUrl) => {
|
|
2253
|
+
const a = norm(childSrc);
|
|
2254
|
+
const b = norm(frameUrl);
|
|
2255
|
+
return Boolean(a && b && (a === b || a.includes(b) || b.includes(a)));
|
|
2256
|
+
};
|
|
2257
|
+
const childrenCache = /* @__PURE__ */ new Map();
|
|
2258
|
+
const childrenOf = async (url) => {
|
|
2259
|
+
const hit = childrenCache.get(url);
|
|
2260
|
+
if (hit) return hit;
|
|
2261
|
+
let out = [];
|
|
2262
|
+
try {
|
|
2263
|
+
const raw = norm(url) === norm(mainUrl) ? await ctx.page.evaluate(CHILDREN) : await ctx.page.evaluateInFrame(url, CHILDREN);
|
|
2264
|
+
out = JSON.parse(String(raw || "[]"));
|
|
2265
|
+
} catch {
|
|
2266
|
+
}
|
|
2267
|
+
childrenCache.set(url, out);
|
|
2268
|
+
return out;
|
|
2269
|
+
};
|
|
2270
|
+
let frontier = frameList.filter((e) => e.depth === 0).map((e) => ({ url: e.url, depth: 0 }));
|
|
2271
|
+
for (let depth = 0; frontier.length > 0 && frameList.some((e) => e.depth === null) && depth < 6; depth++) {
|
|
2272
|
+
const next = [];
|
|
2273
|
+
for (const node of frontier) {
|
|
2274
|
+
const kids = await childrenOf(node.url);
|
|
2275
|
+
if (kids.length === 0) continue;
|
|
2276
|
+
for (const e of frameList) {
|
|
2277
|
+
if (e.depth !== null) continue;
|
|
2278
|
+
if (kids.some((k) => matchChild(k.src, e.url))) {
|
|
2279
|
+
e.parentUrl = node.url;
|
|
2280
|
+
e.depth = node.depth + 1;
|
|
2281
|
+
next.push({ url: e.url, depth: e.depth });
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
frontier = next;
|
|
2286
|
+
}
|
|
2287
|
+
} catch {
|
|
2288
|
+
}
|
|
2289
|
+
const urls = frameList.map((e) => e.url);
|
|
2290
|
+
for (let i = 0; i < urls.length; i++) {
|
|
2291
|
+
for (let j = i + 1; j < urls.length; j++) {
|
|
2292
|
+
const a = urls[i];
|
|
2293
|
+
const b = urls[j];
|
|
2294
|
+
if (a && b && (a.includes(b) || b.includes(a))) {
|
|
2295
|
+
const shorter = a.includes(b) ? b : a;
|
|
2296
|
+
warnings.push(`URL \u5B50\u4E32\u6B67\u4E49\uFF1A"${shorter}" \u540C\u65F6\u547D\u4E2D ${a} \u548C ${b}\u2014\u2014--frame \u8BF7\u5199\u66F4\u957F/\u66F4\u7CBE\u786E\u7684\u5B50\u4E32`);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
return ok16({ frames: frameList, warnings });
|
|
2217
2301
|
}
|
|
2218
2302
|
});
|
|
2219
2303
|
var frameCommand = registerCommand({
|
|
@@ -3772,8 +3856,26 @@ async function detectSpaRoutes(page, origin) {
|
|
|
3772
3856
|
}
|
|
3773
3857
|
} catch {
|
|
3774
3858
|
}
|
|
3859
|
+
try {
|
|
3860
|
+
const vueRoutes = await page.evaluate((evalOrigin) => {
|
|
3861
|
+
const win = window;
|
|
3862
|
+
const vue3App = win.__vue_app__;
|
|
3863
|
+
const globalProperties = vue3App?.config?.globalProperties;
|
|
3864
|
+
let router = globalProperties?.$router;
|
|
3865
|
+
if (!router) {
|
|
3866
|
+
const root = document.querySelector("#app");
|
|
3867
|
+
const vm = root ? root.__vue__ : void 0;
|
|
3868
|
+
const rootVm = vm?.$root;
|
|
3869
|
+
router = vm?.$router ?? rootVm?.$router;
|
|
3870
|
+
}
|
|
3871
|
+
const routeList = router?.options?.routes ?? [];
|
|
3872
|
+
return routeList.filter((route) => route.path && route.path !== "/" && !route.path.includes(":") && !route.path.includes("*")).map((route) => `${evalOrigin.replace(/\/$/, "")}/#${route.path}`);
|
|
3873
|
+
}, origin);
|
|
3874
|
+
for (const route of vueRoutes) routeSet.add(route);
|
|
3875
|
+
} catch {
|
|
3876
|
+
}
|
|
3775
3877
|
return Array.from(routeSet).map(
|
|
3776
|
-
(p) => `${origin.replace(/\/$/, "")}${p.startsWith("/") ? "" : "/"}${p}`
|
|
3878
|
+
(p) => p.startsWith("http") ? p : `${origin.replace(/\/$/, "")}${p.startsWith("/") ? "" : "/"}${p}`
|
|
3777
3879
|
);
|
|
3778
3880
|
}
|
|
3779
3881
|
function parseRobotsTxt(text) {
|
|
@@ -3966,7 +4068,14 @@ var crawlCommand = registerCommand({
|
|
|
3966
4068
|
results.push({ url: seedPage.url(), title, content });
|
|
3967
4069
|
const firstLinks = await extractLinks(seedPage, startUrl.origin);
|
|
3968
4070
|
if (options.enableSpa) {
|
|
3969
|
-
|
|
4071
|
+
let spaRoutes = [];
|
|
4072
|
+
try {
|
|
4073
|
+
spaRoutes = await detectSpaRoutes(seedPage, startUrl.origin);
|
|
4074
|
+
} catch (error) {
|
|
4075
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4076
|
+
process.stderr.write(`[SPA] Route detection failed: ${message}
|
|
4077
|
+
`);
|
|
4078
|
+
}
|
|
3970
4079
|
for (const route of spaRoutes) {
|
|
3971
4080
|
try {
|
|
3972
4081
|
const absNorm = normalizeUrl(stripHashAnchorQuery(route));
|
|
@@ -5851,20 +5960,48 @@ async function enhanceSemanticsWithLLM(url, ariaSnapshot, ruleBasedElements) {
|
|
|
5851
5960
|
// src/commands/snapshot.ts
|
|
5852
5961
|
var snapshotCommand = registerCommand({
|
|
5853
5962
|
name: "snapshot",
|
|
5854
|
-
description: "
|
|
5963
|
+
description: "Get page state: interactive @refs to operate (default); --type aria=page outline; --type text=content; --type dom=debug DOM",
|
|
5855
5964
|
scope: "page",
|
|
5856
5965
|
selectorParams: ["selector"],
|
|
5966
|
+
examples: [
|
|
5967
|
+
{
|
|
5968
|
+
cmd: "xbrowser snapshot",
|
|
5969
|
+
description: "I want to OPERATE the page \u2192 returns clickable/fillable @refs (use click @e1, fill @e2)",
|
|
5970
|
+
output: '@e1 [button] "Submit"\n@e2 [textbox editable] "Email"'
|
|
5971
|
+
},
|
|
5972
|
+
{
|
|
5973
|
+
cmd: "xbrowser snapshot --type aria",
|
|
5974
|
+
description: "I want the page OUTLINE/skeleton (nav, heading hierarchy, regions)",
|
|
5975
|
+
output: 'banner:\n navigation:\n link "Home"\nmain:\n heading "Welcome"'
|
|
5976
|
+
},
|
|
5977
|
+
{
|
|
5978
|
+
cmd: "xbrowser snapshot --type text",
|
|
5979
|
+
description: "I want the page TEXT CONTENT (extract body copy/information)",
|
|
5980
|
+
output: "Welcome\nPlease enter your email\nSubmit"
|
|
5981
|
+
},
|
|
5982
|
+
{
|
|
5983
|
+
cmd: "xbrowser snapshot --type dom",
|
|
5984
|
+
description: "I want to DEBUG the DOM (tag names, attributes, nesting)"
|
|
5985
|
+
},
|
|
5986
|
+
{
|
|
5987
|
+
cmd: "xbrowser snapshot --selectors",
|
|
5988
|
+
description: "I want to operate AND need stable CSS selectors (reuse across sessions)",
|
|
5989
|
+
output: "e1: #submit | e2: #email"
|
|
5990
|
+
}
|
|
5991
|
+
],
|
|
5857
5992
|
parameters: z25.object({
|
|
5858
|
-
type: z25.enum(["aria", "text", "dom", "all"]).default("
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5993
|
+
type: z25.enum(["interactive", "aria", "text", "dom", "all"]).default("interactive").describe(
|
|
5994
|
+
"Choose by intent: interactive(default)=operate page, get @refs of clickable/fillable elements; aria=page outline (nav/headings/regions); text=page text content; dom=debug DOM tags/attrs; all=everything"
|
|
5995
|
+
),
|
|
5996
|
+
selector: z25.string().optional().describe("\u9650\u5B9A\u5230\u67D0\u4E2A\u5143\u7D20\uFF08CSS \u9009\u62E9\u5668\uFF09\uFF0C\u53EA\u5FEB\u7167\u8BE5\u5B50\u6811"),
|
|
5997
|
+
depth: z25.number().optional().default(6).describe("aria/dom \u6811\u7684\u6700\u5927\u6DF1\u5EA6"),
|
|
5998
|
+
interactive: z25.boolean().optional().default(false).describe("\u5F3A\u5236 interactive \u6A21\u5F0F\uFF08\u7B49\u540C --type interactive\uFF0C\u517C\u5BB9 -i\uFF09"),
|
|
5999
|
+
interactiveOnly: z25.boolean().optional().default(false).describe("interactive \u7684\u522B\u540D"),
|
|
6000
|
+
i: z25.boolean().optional().default(false).describe("interactive \u7684\u77ED\u522B\u540D"),
|
|
6001
|
+
compact: z25.boolean().optional().default(false).describe("\u9644\u5E26\u7D27\u51D1\u6587\u672C\u5FEB\u7167\uFF08interactive \u6A21\u5F0F\u9ED8\u8BA4\u5DF2\u542B\uFF09"),
|
|
6002
|
+
c: z25.boolean().optional().default(false).describe("compact \u7684\u77ED\u522B\u540D"),
|
|
6003
|
+
selectors: z25.boolean().optional().describe("\u9644\u5E26 ref \u2192 CSS \u9009\u62E9\u5668\u6620\u5C04\uFF08\u9700\u8981\u7A33\u5B9A\u9009\u62E9\u5668\u65F6\u5F00\uFF09"),
|
|
6004
|
+
all: z25.boolean().optional().default(false).describe("interactive \u6A21\u5F0F\u4E0B\u8FDE\u9690\u85CF\u5143\u7D20\u4E00\u8D77\u91C7\u96C6\uFF08\u6CE8\u610F\uFF1A\u8FD9\u662F\u91C7\u96C6\u8303\u56F4\uFF0C\u4E0D\u662F --type all \u7684\u5408\u5E76\u5FEB\u7167\uFF09")
|
|
5868
6005
|
}),
|
|
5869
6006
|
result: z25.object({
|
|
5870
6007
|
url: z25.string(),
|
|
@@ -5877,14 +6014,13 @@ var snapshotCommand = registerCommand({
|
|
|
5877
6014
|
const page = ctx.page;
|
|
5878
6015
|
const url = page.url();
|
|
5879
6016
|
const title = await page.title().catch(() => "");
|
|
5880
|
-
|
|
6017
|
+
const wantInteractive = p.type === "interactive" || p.interactive || p.interactiveOnly || p.i || p.compact || p.c || p.selectors;
|
|
6018
|
+
if (wantInteractive) {
|
|
5881
6019
|
const observation = await observePage(page, ctx.sessionId, {
|
|
5882
6020
|
includeHidden: p.all
|
|
5883
6021
|
});
|
|
5884
6022
|
if (p.selectors) observation.selectors = buildSelectorMap(observation);
|
|
5885
|
-
|
|
5886
|
-
observation.compact = formatObservationCompact(observation, { selectors: p.selectors });
|
|
5887
|
-
}
|
|
6023
|
+
observation.compact = formatObservationCompact(observation, { selectors: p.selectors });
|
|
5888
6024
|
return ok24(observation, normalizeTips3([
|
|
5889
6025
|
`refs refreshed for ${observation.targets.length} targets; use click @e1 or fill @e2 "text"`
|
|
5890
6026
|
]));
|
|
@@ -5904,14 +6040,20 @@ var snapshotCommand = registerCommand({
|
|
|
5904
6040
|
return ok24({ url, title, dom });
|
|
5905
6041
|
}
|
|
5906
6042
|
if (p.type === "all") {
|
|
5907
|
-
const [aria, text, dom] = await Promise.all([
|
|
6043
|
+
const [observation, aria, text, dom] = await Promise.all([
|
|
6044
|
+
observePage(page, ctx.sessionId, { includeHidden: p.all }),
|
|
5908
6045
|
captureAriaSnapshot(page, p.selector, p.depth),
|
|
5909
6046
|
captureTextSnapshot(page, p.selector),
|
|
5910
6047
|
captureDomSnapshot(page, p.selector, p.depth ?? 6)
|
|
5911
6048
|
]);
|
|
6049
|
+
observation.compact = formatObservationCompact(observation, { selectors: p.selectors });
|
|
6050
|
+
if (p.selectors) observation.selectors = buildSelectorMap(observation);
|
|
5912
6051
|
const tips = await buildRefTips(page, aria);
|
|
5913
6052
|
persistSemantics(url, aria);
|
|
5914
|
-
return ok24({
|
|
6053
|
+
return ok24({ ...observation, aria, text, dom }, normalizeTips3([
|
|
6054
|
+
...tips,
|
|
6055
|
+
`${observation.targets.length} interactive targets + aria + text + dom combined`
|
|
6056
|
+
]));
|
|
5915
6057
|
}
|
|
5916
6058
|
return fail11(`Unknown snapshot type: ${p.type}`);
|
|
5917
6059
|
}
|
|
@@ -5940,16 +6082,29 @@ async function buildRefTips(page, aria) {
|
|
|
5940
6082
|
}
|
|
5941
6083
|
}
|
|
5942
6084
|
async function captureAriaSnapshot(page, selector, _depth) {
|
|
6085
|
+
let raw;
|
|
5943
6086
|
try {
|
|
5944
6087
|
const locator = selector ? page.locator(selector).first() : page.locator("body");
|
|
5945
|
-
|
|
6088
|
+
raw = await locator.ariaSnapshot();
|
|
5946
6089
|
} catch {
|
|
5947
6090
|
try {
|
|
5948
|
-
|
|
6091
|
+
raw = await page.locator("body").ariaSnapshot();
|
|
5949
6092
|
} catch {
|
|
5950
6093
|
return "(aria snapshot not available)";
|
|
5951
6094
|
}
|
|
5952
6095
|
}
|
|
6096
|
+
return filterAriaNoise(raw);
|
|
6097
|
+
}
|
|
6098
|
+
function filterAriaNoise(raw) {
|
|
6099
|
+
return raw.split("\n").filter((line) => {
|
|
6100
|
+
const t = line.trim();
|
|
6101
|
+
if (!t) return false;
|
|
6102
|
+
if (t === "none:" || t.startsWith("none: ")) return false;
|
|
6103
|
+
if (t.includes("InlineTextBox")) return false;
|
|
6104
|
+
if (t.includes("ListMarker")) return false;
|
|
6105
|
+
if (/^[a-z]+$/.test(t) || /^[a-z]+:$/.test(t)) return false;
|
|
6106
|
+
return true;
|
|
6107
|
+
}).join("\n");
|
|
5953
6108
|
}
|
|
5954
6109
|
async function captureTextSnapshot(page, selector) {
|
|
5955
6110
|
if (selector) {
|
|
@@ -7408,7 +7563,7 @@ function attachWaitForHuman(ctx, getOrCreateWSServer) {
|
|
|
7408
7563
|
if (!ctx.page) {
|
|
7409
7564
|
throw new Error("waitForHuman requires an active page");
|
|
7410
7565
|
}
|
|
7411
|
-
const { HumanInteractionManager } = await import("./human-interaction-
|
|
7566
|
+
const { HumanInteractionManager } = await import("./human-interaction-STTZZZ5N.js");
|
|
7412
7567
|
const wsServer2 = await getOrCreateWSServer(ctx.browserContext);
|
|
7413
7568
|
const manager = new HumanInteractionManager(wsServer2, ctx.page);
|
|
7414
7569
|
return manager.waitForHuman(options);
|
|
@@ -8360,6 +8515,9 @@ var TipGenerator = class {
|
|
|
8360
8515
|
categoryLabel(category) {
|
|
8361
8516
|
const labels = {
|
|
8362
8517
|
dialog: "Dialog",
|
|
8518
|
+
filechooser: "File Chooser",
|
|
8519
|
+
popup: "Popup",
|
|
8520
|
+
download: "Download",
|
|
8363
8521
|
modal: "Modal",
|
|
8364
8522
|
popover: "Popover",
|
|
8365
8523
|
notification: "\u901A\u77E5",
|
|
@@ -8424,8 +8582,62 @@ var TipsManager = class {
|
|
|
8424
8582
|
generator = new TipGenerator(this.contextTracker);
|
|
8425
8583
|
beforeSnapshot = null;
|
|
8426
8584
|
lastDetectionTime = 0;
|
|
8585
|
+
// CDP 弹窗事件检测(filechooser / dialog / popup)
|
|
8586
|
+
detectedEvents = [];
|
|
8587
|
+
eventListenersAttached = false;
|
|
8588
|
+
lastCommandName = "";
|
|
8427
8589
|
async beforeCommand(page, commandName, params) {
|
|
8428
8590
|
this.contextTracker.record(commandName, params);
|
|
8591
|
+
this.lastCommandName = commandName;
|
|
8592
|
+
if (!this.eventListenersAttached && typeof page.on === "function") {
|
|
8593
|
+
this.eventListenersAttached = true;
|
|
8594
|
+
page.on("dialog", (dialog) => {
|
|
8595
|
+
const d = dialog;
|
|
8596
|
+
try {
|
|
8597
|
+
this.detectedEvents.push({
|
|
8598
|
+
type: "dialog",
|
|
8599
|
+
message: `[${d.type()}] ${d.message().slice(0, 200)}`,
|
|
8600
|
+
commandName: this.lastCommandName
|
|
8601
|
+
});
|
|
8602
|
+
} catch {
|
|
8603
|
+
}
|
|
8604
|
+
});
|
|
8605
|
+
page.on("filechooser", (chooser) => {
|
|
8606
|
+
const c = chooser;
|
|
8607
|
+
try {
|
|
8608
|
+
this.detectedEvents.push({
|
|
8609
|
+
type: "filechooser",
|
|
8610
|
+
message: `\u6587\u4EF6\u9009\u62E9\u5F39\u7A97${c.isMultiple ? "\uFF08\u591A\u9009\uFF09" : ""}\uFF1Aselector=${c.selector || "input[type=file]"}`,
|
|
8611
|
+
selector: c.selector,
|
|
8612
|
+
commandName: this.lastCommandName
|
|
8613
|
+
});
|
|
8614
|
+
} catch {
|
|
8615
|
+
}
|
|
8616
|
+
});
|
|
8617
|
+
page.on("popup", (info) => {
|
|
8618
|
+
const p = info;
|
|
8619
|
+
try {
|
|
8620
|
+
this.detectedEvents.push({
|
|
8621
|
+
type: "popup",
|
|
8622
|
+
message: `\u65B0\u7A97\u53E3\u5F39\u7A97\uFF1Aurl=${p.url || "(unknown)"}${p.windowName ? ` name=${p.windowName}` : ""}`,
|
|
8623
|
+
commandName: this.lastCommandName
|
|
8624
|
+
});
|
|
8625
|
+
} catch {
|
|
8626
|
+
}
|
|
8627
|
+
});
|
|
8628
|
+
page.on("download", (info) => {
|
|
8629
|
+
const d = info;
|
|
8630
|
+
try {
|
|
8631
|
+
const stateLabel = d.state === "completed" ? "\u5B8C\u6210" : d.state === "canceled" ? "\u53D6\u6D88" : "\u5F00\u59CB";
|
|
8632
|
+
this.detectedEvents.push({
|
|
8633
|
+
type: "download",
|
|
8634
|
+
message: `\u6587\u4EF6\u4E0B\u8F7D${stateLabel}\uFF1A${d.filename || "unknown"}${d.url ? ` (${d.url.slice(0, 80)})` : ""}`,
|
|
8635
|
+
commandName: this.lastCommandName
|
|
8636
|
+
});
|
|
8637
|
+
} catch {
|
|
8638
|
+
}
|
|
8639
|
+
});
|
|
8640
|
+
}
|
|
8429
8641
|
if (!this.domWatcher) {
|
|
8430
8642
|
this.domWatcher = new DomWatcher(page);
|
|
8431
8643
|
}
|
|
@@ -8468,20 +8680,59 @@ var TipsManager = class {
|
|
|
8468
8680
|
}
|
|
8469
8681
|
}
|
|
8470
8682
|
async afterCommand() {
|
|
8471
|
-
if (!this.domWatcher || !this.beforeSnapshot)
|
|
8683
|
+
if (!this.domWatcher || !this.beforeSnapshot) {
|
|
8684
|
+
const cdpTips = this.collectCdpEventTips();
|
|
8685
|
+
this.detectedEvents = [];
|
|
8686
|
+
return cdpTips;
|
|
8687
|
+
}
|
|
8472
8688
|
await this.debounce();
|
|
8473
8689
|
try {
|
|
8474
8690
|
const currentElements = await this.domWatcher.scanOverlays();
|
|
8475
8691
|
const afterSnapshot = buildSnapshot(currentElements);
|
|
8476
8692
|
const newElements = this.generator.diff(this.beforeSnapshot, afterSnapshot, currentElements);
|
|
8477
8693
|
const tips = this.generator.generate(newElements);
|
|
8694
|
+
const cdpTips = this.collectCdpEventTips();
|
|
8695
|
+
tips.push(...cdpTips);
|
|
8478
8696
|
this.beforeSnapshot = null;
|
|
8697
|
+
this.detectedEvents = [];
|
|
8479
8698
|
return tips;
|
|
8480
8699
|
} catch {
|
|
8700
|
+
const cdpTips = this.collectCdpEventTips();
|
|
8481
8701
|
this.beforeSnapshot = null;
|
|
8482
|
-
|
|
8702
|
+
this.detectedEvents = [];
|
|
8703
|
+
return cdpTips;
|
|
8483
8704
|
}
|
|
8484
8705
|
}
|
|
8706
|
+
/**
|
|
8707
|
+
* 把检测到的 CDP 弹窗事件转成 SmartTip
|
|
8708
|
+
* 包括:dialog(alert/confirm/prompt)、filechooser(文件选择弹窗)、popup(新窗口)
|
|
8709
|
+
*/
|
|
8710
|
+
collectCdpEventTips() {
|
|
8711
|
+
if (this.detectedEvents.length === 0) return [];
|
|
8712
|
+
return this.detectedEvents.map((evt) => {
|
|
8713
|
+
const suggestions = [];
|
|
8714
|
+
if (evt.type === "dialog") {
|
|
8715
|
+
suggestions.push("\u6B64\u5F39\u7A97\u53EF\u80FD\u963B\u585E\u540E\u7EED\u64CD\u4F5C");
|
|
8716
|
+
suggestions.push('\u5982\u9700\u81EA\u52A8\u5904\u7406\uFF1A\u4F7F\u7528 page.on("dialog") \u62E6\u622A');
|
|
8717
|
+
} else if (evt.type === "filechooser") {
|
|
8718
|
+
suggestions.push("\u6B64\u5F39\u7A97\u7531\u9875\u9762\u64CD\u4F5C\u89E6\u53D1\uFF08\u5982\u70B9\u51FB\u4E0A\u4F20\u6309\u94AE\uFF09");
|
|
8719
|
+
suggestions.push("\u5982\u9700\u81EA\u52A8\u5904\u7406\uFF1A\u4F7F\u7528 --path/--paths \u53C2\u6570\u4E0A\u4F20\u6587\u4EF6");
|
|
8720
|
+
} else if (evt.type === "popup") {
|
|
8721
|
+
suggestions.push("\u9875\u9762\u5C1D\u8BD5\u6253\u5F00\u65B0\u7A97\u53E3\uFF08\u53EF\u80FD\u88AB\u6D4F\u89C8\u5668\u62E6\u622A\uFF09");
|
|
8722
|
+
suggestions.push('\u5982\u9700\u5904\u7406\uFF1A\u68C0\u67E5\u5F39\u7A97\u62E6\u622A\u8BBE\u7F6E\u6216\u4F7F\u7528 page.on("popup") \u76D1\u542C');
|
|
8723
|
+
} else if (evt.type === "download") {
|
|
8724
|
+
suggestions.push("\u9875\u9762\u89E6\u53D1\u4E86\u6587\u4EF6\u4E0B\u8F7D");
|
|
8725
|
+
suggestions.push("\u5982\u9700\u63A7\u5236\u8DEF\u5F84\uFF1Apage.setDownloadBehavior(path)");
|
|
8726
|
+
}
|
|
8727
|
+
return {
|
|
8728
|
+
category: evt.type,
|
|
8729
|
+
priority: "p1",
|
|
8730
|
+
message: `\u{1F514} [\u5F39\u7A97\u68C0\u6D4B] ${evt.message}\uFF08\u89E6\u53D1\u547D\u4EE4: ${evt.commandName || "\u672A\u77E5"}\uFF09`,
|
|
8731
|
+
selector: evt.selector,
|
|
8732
|
+
suggestions
|
|
8733
|
+
};
|
|
8734
|
+
});
|
|
8735
|
+
}
|
|
8485
8736
|
debounce() {
|
|
8486
8737
|
const ms = tipsDebounceMs();
|
|
8487
8738
|
if (ms <= 0) return Promise.resolve();
|
|
@@ -8502,6 +8753,9 @@ var TipsManager = class {
|
|
|
8502
8753
|
this.contextTracker.clear();
|
|
8503
8754
|
this.domWatcher = null;
|
|
8504
8755
|
this.lastDetectionTime = 0;
|
|
8756
|
+
this.detectedEvents = [];
|
|
8757
|
+
this.eventListenersAttached = false;
|
|
8758
|
+
this.lastCommandName = "";
|
|
8505
8759
|
}
|
|
8506
8760
|
};
|
|
8507
8761
|
var globalTipsManager = null;
|
|
@@ -8927,6 +9181,9 @@ async function executeChain(input, options, executeCommand2) {
|
|
|
8927
9181
|
continue;
|
|
8928
9182
|
}
|
|
8929
9183
|
const { params } = parseCommandArgs(cmdName, cmdArgs, unquote2);
|
|
9184
|
+
if (options?.frame && params._frame === void 0 && params.frame === void 0) {
|
|
9185
|
+
params._frame = options.frame;
|
|
9186
|
+
}
|
|
8930
9187
|
if (cmdName === "goto" && params.url) {
|
|
8931
9188
|
const existing = await findOrRestoreSession(sessionName, options?.cdpEndpoint);
|
|
8932
9189
|
if (!existing) {
|
|
@@ -9182,9 +9439,14 @@ async function executeCommand(commandName, params, sessionName = "default", extr
|
|
|
9182
9439
|
const { _tabIndex: _u, ...rest } = params;
|
|
9183
9440
|
params = rest;
|
|
9184
9441
|
}
|
|
9442
|
+
const _frame = params._frame;
|
|
9443
|
+
if (_frame) {
|
|
9444
|
+
const { _frame: _u, ...rest } = params;
|
|
9445
|
+
params = rest;
|
|
9446
|
+
}
|
|
9185
9447
|
let targetPageOverride = null;
|
|
9186
9448
|
if (_target && extraOpts?.cdpEndpoint) {
|
|
9187
|
-
const { findTargetPage } = await import("./browser-
|
|
9449
|
+
const { findTargetPage } = await import("./browser-6PFTHZI3.js");
|
|
9188
9450
|
targetPageOverride = await findTargetPage(extraOpts.cdpEndpoint, _target);
|
|
9189
9451
|
if (!targetPageOverride) {
|
|
9190
9452
|
return errorResult(`Target "${_target}" not found. Use 'xbrowser targets --cdp ${extraOpts.cdpEndpoint}' to list available pages.`);
|
|
@@ -9248,6 +9510,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
|
|
|
9248
9510
|
browserContext: session?.context,
|
|
9249
9511
|
sessionId: session?.id,
|
|
9250
9512
|
cdpEndpoint: session?.cdpEndpoint || extraOpts?.cdpEndpoint,
|
|
9513
|
+
frame: _frame,
|
|
9251
9514
|
args: [],
|
|
9252
9515
|
options: {},
|
|
9253
9516
|
cwd: process.cwd(),
|
|
@@ -9424,7 +9687,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
|
|
|
9424
9687
|
});
|
|
9425
9688
|
if (session?.page && process.env.XBROWSER_RECOVERY && !extraOpts?._recoveryAttempted) {
|
|
9426
9689
|
try {
|
|
9427
|
-
const { attemptRecovery } = await import("./recovery-
|
|
9690
|
+
const { attemptRecovery } = await import("./recovery-XDKN63O5.js");
|
|
9428
9691
|
const recovery = await attemptRecovery(
|
|
9429
9692
|
session.page,
|
|
9430
9693
|
sessionName,
|