@xbrowser/cli 1.29.0 → 1.30.1
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
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
resolveLaunchOpts,
|
|
21
21
|
saveSessionDiskMeta,
|
|
22
22
|
setActivePage
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-OSIDUT4H.js";
|
|
24
24
|
import {
|
|
25
25
|
rand,
|
|
26
26
|
sleep,
|
|
@@ -116,6 +116,7 @@ function registerCommand(def) {
|
|
|
116
116
|
parameters: def.parameters,
|
|
117
117
|
result: def.result,
|
|
118
118
|
selectorParams: def.selectorParams,
|
|
119
|
+
examples: def.examples,
|
|
119
120
|
handler: def.handler
|
|
120
121
|
};
|
|
121
122
|
registry.set(cmd.name, cmd);
|
|
@@ -350,14 +351,23 @@ var clickCommand = registerCommand({
|
|
|
350
351
|
clickCount: z2.number().optional(),
|
|
351
352
|
delay: z2.number().optional(),
|
|
352
353
|
waitCaptcha: z2.boolean().optional().default(false).describe("\u70B9\u51FB\u540E\u68C0\u6D4B captcha \u5E76\u7B49\u5F85\u89E3\u51B3"),
|
|
353
|
-
waitCaptchaTimeout: z2.number().int().optional().default(18e4).describe("Captcha \u7B49\u5F85\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09")
|
|
354
|
+
waitCaptchaTimeout: z2.number().int().optional().default(18e4).describe("Captcha \u7B49\u5F85\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09"),
|
|
355
|
+
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")
|
|
354
356
|
}),
|
|
355
357
|
result: z2.object({
|
|
356
358
|
selector: z2.string(),
|
|
357
359
|
newTab: z2.object({ url: z2.string(), title: z2.string() }).optional(),
|
|
358
|
-
captcha: z2.any().optional()
|
|
360
|
+
captcha: z2.any().optional(),
|
|
361
|
+
frame: z2.string().optional(),
|
|
362
|
+
x: z2.number().optional(),
|
|
363
|
+
y: z2.number().optional()
|
|
359
364
|
}),
|
|
360
365
|
handler: async (p, ctx) => {
|
|
366
|
+
const frameTarget = p.frame ?? ctx.frame;
|
|
367
|
+
if (frameTarget) {
|
|
368
|
+
const { x, y } = await ctx.page.clickInFrame(frameTarget, p.selector);
|
|
369
|
+
return ok2({ selector: p.selector, frame: frameTarget, x, y });
|
|
370
|
+
}
|
|
361
371
|
let detectedNewPage;
|
|
362
372
|
let cleanup;
|
|
363
373
|
if (ctx.browserContext?.on) {
|
|
@@ -448,15 +458,22 @@ var fillCommand = registerCommand({
|
|
|
448
458
|
parameters: z2.object({
|
|
449
459
|
selector: z2.string(),
|
|
450
460
|
value: z2.string(),
|
|
451
|
-
clear: z2.boolean().optional()
|
|
461
|
+
clear: z2.boolean().optional(),
|
|
462
|
+
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")
|
|
452
463
|
}),
|
|
453
464
|
result: z2.object({
|
|
454
465
|
selector: z2.string(),
|
|
455
466
|
value: z2.string(),
|
|
456
467
|
cleared: z2.boolean(),
|
|
457
|
-
reactMode: z2.boolean().optional()
|
|
468
|
+
reactMode: z2.boolean().optional(),
|
|
469
|
+
frame: z2.string().optional()
|
|
458
470
|
}),
|
|
459
471
|
handler: async (p, ctx) => {
|
|
472
|
+
const frameTarget = p.frame ?? ctx.frame;
|
|
473
|
+
if (frameTarget) {
|
|
474
|
+
const { value } = await ctx.page.fillInFrame(frameTarget, p.selector, p.value);
|
|
475
|
+
return ok2({ selector: p.selector, value, cleared: true, frame: frameTarget });
|
|
476
|
+
}
|
|
460
477
|
const page = ctx.page;
|
|
461
478
|
const shouldClear = p.clear !== false;
|
|
462
479
|
if (shouldClear) {
|
|
@@ -643,15 +660,22 @@ var textCommand = registerCommand({
|
|
|
643
660
|
scope: "page",
|
|
644
661
|
selectorParams: ["selector"],
|
|
645
662
|
parameters: z3.object({
|
|
646
|
-
selector: z3.string().optional()
|
|
663
|
+
selector: z3.string().optional(),
|
|
664
|
+
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")
|
|
647
665
|
}),
|
|
648
|
-
result: z3.object({ text: z3.string() }),
|
|
666
|
+
result: z3.object({ text: z3.string(), frame: z3.string().optional() }),
|
|
649
667
|
handler: async (p, ctx) => {
|
|
668
|
+
const frameTarget = p.frame ?? ctx.frame;
|
|
669
|
+
if (frameTarget) {
|
|
670
|
+
const expr = p.selector ? `(() => { const el = document.querySelector(${JSON.stringify(p.selector)}); return el ? (el.textContent ?? '').trim() : null; })()` : `(document.body?.innerText || '').trim()`;
|
|
671
|
+
const text2 = await ctx.page.evaluateInFrame(frameTarget, expr);
|
|
672
|
+
return ok3({ text: text2 || "", frame: frameTarget });
|
|
673
|
+
}
|
|
650
674
|
if (p.selector) {
|
|
651
675
|
const text2 = await ctx.page.textContent(p.selector);
|
|
652
676
|
return ok3({ text: text2 || "" });
|
|
653
677
|
}
|
|
654
|
-
const text = await ctx.page.evaluate(() => document.body?.innerText || "");
|
|
678
|
+
const text = await ctx.page.evaluate(() => (document.body?.innerText || "").trim());
|
|
655
679
|
return ok3({ text });
|
|
656
680
|
}
|
|
657
681
|
});
|
|
@@ -775,43 +799,64 @@ import { z as z6 } from "zod";
|
|
|
775
799
|
import { ok as ok6 } from "@dyyz1993/xcli-core";
|
|
776
800
|
var mouseCommand = registerCommand({
|
|
777
801
|
name: "mouse",
|
|
778
|
-
description: "Control the mouse (move, click, etc.)",
|
|
802
|
+
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)",
|
|
779
803
|
scope: "page",
|
|
780
804
|
parameters: z6.object({
|
|
781
|
-
action: z6.enum(["move", "down", "up", "click", "dblclick", "drag"]),
|
|
805
|
+
action: z6.enum(["move", "down", "up", "click", "dblclick", "drag", "wheel"]),
|
|
782
806
|
x: z6.coerce.number(),
|
|
783
807
|
y: z6.coerce.number(),
|
|
808
|
+
"delta-x": z6.coerce.number().optional().describe("wheel \u52A8\u4F5C\uFF1A\u6A2A\u5411\u6EDA\u52A8\u91CF\uFF08\u6B63\u503C\u5411\u53F3\uFF09"),
|
|
809
|
+
"delta-y": z6.coerce.number().optional().describe("wheel \u52A8\u4F5C\uFF1A\u7EB5\u5411\u6EDA\u52A8\u91CF\uFF08\u6B63\u503C\u5411\u4E0B\uFF09"),
|
|
784
810
|
button: z6.enum(["left", "right", "middle"]).optional(),
|
|
785
|
-
steps: z6.coerce.number().optional()
|
|
811
|
+
steps: z6.coerce.number().optional(),
|
|
812
|
+
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")
|
|
786
813
|
}),
|
|
787
814
|
result: z6.object({
|
|
788
|
-
action: z6.enum(["move", "down", "up", "click", "dblclick", "drag"]),
|
|
815
|
+
action: z6.enum(["move", "down", "up", "click", "dblclick", "drag", "wheel"]),
|
|
789
816
|
x: z6.number(),
|
|
790
817
|
y: z6.number()
|
|
791
818
|
}),
|
|
792
819
|
handler: async (p, ctx) => {
|
|
793
820
|
const button = p.button || "left";
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
821
|
+
const frame = p.frame ?? ctx.frame;
|
|
822
|
+
const dispatch = async (mouse) => {
|
|
823
|
+
switch (p.action) {
|
|
824
|
+
case "move":
|
|
825
|
+
await mouse.move(p.x, p.y, { steps: p.steps || 1 });
|
|
826
|
+
break;
|
|
827
|
+
case "down":
|
|
828
|
+
await mouse.move(p.x, p.y);
|
|
829
|
+
await mouse.down({ button });
|
|
830
|
+
break;
|
|
831
|
+
case "up":
|
|
832
|
+
await mouse.move(p.x, p.y);
|
|
833
|
+
await mouse.up({ button });
|
|
834
|
+
break;
|
|
835
|
+
case "click":
|
|
836
|
+
await mouse.click(p.x, p.y, { button });
|
|
837
|
+
break;
|
|
838
|
+
case "dblclick":
|
|
839
|
+
await mouse.dblclick(p.x, p.y, { button });
|
|
840
|
+
break;
|
|
841
|
+
case "drag":
|
|
842
|
+
await mouse.drag(p.x, p.y, p.steps ? { steps: p.steps } : {});
|
|
843
|
+
break;
|
|
844
|
+
case "wheel":
|
|
845
|
+
await mouse.wheelAt(p.x, p.y, Number(p["delta-x"] ?? 0), Number(p["delta-y"] ?? 0));
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
if (frame) {
|
|
850
|
+
try {
|
|
851
|
+
await ctx.page.runFrameMouse(frame, dispatch);
|
|
852
|
+
} catch (err) {
|
|
853
|
+
if (p.action === "drag" && /session/i.test(String(err))) {
|
|
854
|
+
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`);
|
|
855
|
+
}
|
|
856
|
+
throw err;
|
|
857
|
+
}
|
|
858
|
+
} else {
|
|
859
|
+
await dispatch(ctx.page.mouse);
|
|
815
860
|
}
|
|
816
861
|
return ok6({ action: p.action, x: p.x, y: p.y });
|
|
817
862
|
}
|
|
@@ -1253,7 +1298,8 @@ var evaluateCommand = registerCommand({
|
|
|
1253
1298
|
direction: "client\u2192browser"
|
|
1254
1299
|
});
|
|
1255
1300
|
engine.stop();
|
|
1256
|
-
const
|
|
1301
|
+
const frame = p.frame ?? ctx.frame;
|
|
1302
|
+
const result = frame ? await ctx.page.evaluateInFrame(frame, expression) : await ctx.page.evaluate(expression);
|
|
1257
1303
|
const response = ok9({ result });
|
|
1258
1304
|
if (decision && decision.severity === "danger") {
|
|
1259
1305
|
response.tips = normalizeTips2([`${decision.suggestion}`]);
|
|
@@ -1682,24 +1728,98 @@ import { z as z16 } from "zod";
|
|
|
1682
1728
|
import { ok as ok16, fail as fail7 } from "@dyyz1993/xcli-core";
|
|
1683
1729
|
var framesCommand = registerCommand({
|
|
1684
1730
|
name: "frames",
|
|
1685
|
-
description: "List all frames in the current page",
|
|
1731
|
+
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)",
|
|
1686
1732
|
scope: "page",
|
|
1687
1733
|
result: z16.object({
|
|
1688
1734
|
frames: z16.array(z16.object({
|
|
1689
1735
|
index: z16.number(),
|
|
1690
1736
|
name: z16.string().nullable(),
|
|
1691
|
-
url: z16.string()
|
|
1692
|
-
|
|
1737
|
+
url: z16.string(),
|
|
1738
|
+
oopif: z16.boolean().optional(),
|
|
1739
|
+
targetId: z16.string().optional(),
|
|
1740
|
+
parentUrl: z16.string().nullable().optional(),
|
|
1741
|
+
depth: z16.number().nullable().optional()
|
|
1742
|
+
})),
|
|
1743
|
+
warnings: z16.array(z16.string()).optional()
|
|
1693
1744
|
}),
|
|
1694
1745
|
handler: async (_p, ctx) => {
|
|
1695
1746
|
const discover = ctx.page.discoverFrames;
|
|
1696
1747
|
const rawFrames = discover ? await discover.call(ctx.page) : ctx.page.frames();
|
|
1748
|
+
const mainUrl = ctx.page.url();
|
|
1697
1749
|
const frameList = rawFrames.map((frame, index) => ({
|
|
1698
1750
|
index,
|
|
1699
1751
|
name: frame.name(),
|
|
1700
|
-
url: frame.url()
|
|
1752
|
+
url: frame.url(),
|
|
1753
|
+
parentUrl: null,
|
|
1754
|
+
depth: null
|
|
1701
1755
|
}));
|
|
1702
|
-
|
|
1756
|
+
const norm = (u) => u.replace(/\/+$/, "");
|
|
1757
|
+
for (const e of frameList) {
|
|
1758
|
+
if (norm(e.url) === norm(mainUrl)) {
|
|
1759
|
+
e.parentUrl = null;
|
|
1760
|
+
e.depth = 0;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
if (typeof ctx.page.listFrameTargets === "function") {
|
|
1764
|
+
const targets = await ctx.page.listFrameTargets();
|
|
1765
|
+
const knownUrls = new Set(frameList.map((f) => f.url));
|
|
1766
|
+
for (const t of targets) {
|
|
1767
|
+
if (knownUrls.has(t.url)) continue;
|
|
1768
|
+
frameList.push({ index: frameList.length, name: null, url: t.url, oopif: true, targetId: t.targetId, parentUrl: null, depth: null });
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
const warnings = [];
|
|
1772
|
+
try {
|
|
1773
|
+
const CHILDREN = `JSON.stringify([...document.querySelectorAll('iframe')].map(f=>({src:f.src||'',name:f.name||''})))`;
|
|
1774
|
+
const matchChild = (childSrc, frameUrl) => {
|
|
1775
|
+
const a = norm(childSrc);
|
|
1776
|
+
const b = norm(frameUrl);
|
|
1777
|
+
return Boolean(a && b && (a === b || a.includes(b) || b.includes(a)));
|
|
1778
|
+
};
|
|
1779
|
+
const childrenCache = /* @__PURE__ */ new Map();
|
|
1780
|
+
const childrenOf = async (url) => {
|
|
1781
|
+
const hit = childrenCache.get(url);
|
|
1782
|
+
if (hit) return hit;
|
|
1783
|
+
let out = [];
|
|
1784
|
+
try {
|
|
1785
|
+
const raw = norm(url) === norm(mainUrl) ? await ctx.page.evaluate(CHILDREN) : await ctx.page.evaluateInFrame(url, CHILDREN);
|
|
1786
|
+
out = JSON.parse(String(raw || "[]"));
|
|
1787
|
+
} catch {
|
|
1788
|
+
}
|
|
1789
|
+
childrenCache.set(url, out);
|
|
1790
|
+
return out;
|
|
1791
|
+
};
|
|
1792
|
+
let frontier = frameList.filter((e) => e.depth === 0).map((e) => ({ url: e.url, depth: 0 }));
|
|
1793
|
+
for (let depth = 0; frontier.length > 0 && frameList.some((e) => e.depth === null) && depth < 6; depth++) {
|
|
1794
|
+
const next = [];
|
|
1795
|
+
for (const node of frontier) {
|
|
1796
|
+
const kids = await childrenOf(node.url);
|
|
1797
|
+
if (kids.length === 0) continue;
|
|
1798
|
+
for (const e of frameList) {
|
|
1799
|
+
if (e.depth !== null) continue;
|
|
1800
|
+
if (kids.some((k) => matchChild(k.src, e.url))) {
|
|
1801
|
+
e.parentUrl = node.url;
|
|
1802
|
+
e.depth = node.depth + 1;
|
|
1803
|
+
next.push({ url: e.url, depth: e.depth });
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
frontier = next;
|
|
1808
|
+
}
|
|
1809
|
+
} catch {
|
|
1810
|
+
}
|
|
1811
|
+
const urls = frameList.map((e) => e.url);
|
|
1812
|
+
for (let i = 0; i < urls.length; i++) {
|
|
1813
|
+
for (let j = i + 1; j < urls.length; j++) {
|
|
1814
|
+
const a = urls[i];
|
|
1815
|
+
const b = urls[j];
|
|
1816
|
+
if (a && b && (a.includes(b) || b.includes(a))) {
|
|
1817
|
+
const shorter = a.includes(b) ? b : a;
|
|
1818
|
+
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`);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return ok16({ frames: frameList, warnings });
|
|
1703
1823
|
}
|
|
1704
1824
|
});
|
|
1705
1825
|
var frameCommand = registerCommand({
|
|
@@ -3258,8 +3378,26 @@ async function detectSpaRoutes(page, origin) {
|
|
|
3258
3378
|
}
|
|
3259
3379
|
} catch {
|
|
3260
3380
|
}
|
|
3381
|
+
try {
|
|
3382
|
+
const vueRoutes = await page.evaluate((evalOrigin) => {
|
|
3383
|
+
const win = window;
|
|
3384
|
+
const vue3App = win.__vue_app__;
|
|
3385
|
+
const globalProperties = vue3App?.config?.globalProperties;
|
|
3386
|
+
let router = globalProperties?.$router;
|
|
3387
|
+
if (!router) {
|
|
3388
|
+
const root = document.querySelector("#app");
|
|
3389
|
+
const vm = root ? root.__vue__ : void 0;
|
|
3390
|
+
const rootVm = vm?.$root;
|
|
3391
|
+
router = vm?.$router ?? rootVm?.$router;
|
|
3392
|
+
}
|
|
3393
|
+
const routeList = router?.options?.routes ?? [];
|
|
3394
|
+
return routeList.filter((route) => route.path && route.path !== "/" && !route.path.includes(":") && !route.path.includes("*")).map((route) => `${evalOrigin.replace(/\/$/, "")}/#${route.path}`);
|
|
3395
|
+
}, origin);
|
|
3396
|
+
for (const route of vueRoutes) routeSet.add(route);
|
|
3397
|
+
} catch {
|
|
3398
|
+
}
|
|
3261
3399
|
return Array.from(routeSet).map(
|
|
3262
|
-
(p) => `${origin.replace(/\/$/, "")}${p.startsWith("/") ? "" : "/"}${p}`
|
|
3400
|
+
(p) => p.startsWith("http") ? p : `${origin.replace(/\/$/, "")}${p.startsWith("/") ? "" : "/"}${p}`
|
|
3263
3401
|
);
|
|
3264
3402
|
}
|
|
3265
3403
|
function parseRobotsTxt(text) {
|
|
@@ -3452,7 +3590,14 @@ var crawlCommand = registerCommand({
|
|
|
3452
3590
|
results.push({ url: seedPage.url(), title, content });
|
|
3453
3591
|
const firstLinks = await extractLinks(seedPage, startUrl.origin);
|
|
3454
3592
|
if (options.enableSpa) {
|
|
3455
|
-
|
|
3593
|
+
let spaRoutes = [];
|
|
3594
|
+
try {
|
|
3595
|
+
spaRoutes = await detectSpaRoutes(seedPage, startUrl.origin);
|
|
3596
|
+
} catch (error) {
|
|
3597
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3598
|
+
process.stderr.write(`[SPA] Route detection failed: ${message}
|
|
3599
|
+
`);
|
|
3600
|
+
}
|
|
3456
3601
|
for (const route of spaRoutes) {
|
|
3457
3602
|
try {
|
|
3458
3603
|
const absNorm = normalizeUrl(stripHashAnchorQuery(route));
|
|
@@ -4601,25 +4746,6 @@ function getRefTarget(sessionKey2, ref) {
|
|
|
4601
4746
|
if (!session || !target) return null;
|
|
4602
4747
|
return { screenHash: session.screenHash, target };
|
|
4603
4748
|
}
|
|
4604
|
-
function inheritStableRefs(key, rawTargets) {
|
|
4605
|
-
const prev = sessions.get(key);
|
|
4606
|
-
if (!prev || prev.targets.size === 0) {
|
|
4607
|
-
return rawTargets.map((target, index) => ({ ...target, ref: `e${index + 1}` }));
|
|
4608
|
-
}
|
|
4609
|
-
const bySelector = /* @__PURE__ */ new Map();
|
|
4610
|
-
let maxId = 0;
|
|
4611
|
-
for (const [ref, target] of prev.targets) {
|
|
4612
|
-
bySelector.set(target.selector, ref);
|
|
4613
|
-
const id = Number(ref.slice(1));
|
|
4614
|
-
if (Number.isFinite(id) && id > maxId) maxId = id;
|
|
4615
|
-
}
|
|
4616
|
-
let next = maxId + 1;
|
|
4617
|
-
return rawTargets.map((target) => {
|
|
4618
|
-
const inherited = bySelector.get(target.selector);
|
|
4619
|
-
if (inherited) return { ...target, ref: inherited };
|
|
4620
|
-
return { ...target, ref: `e${next++}` };
|
|
4621
|
-
});
|
|
4622
|
-
}
|
|
4623
4749
|
|
|
4624
4750
|
// src/utils/resolve-selector.ts
|
|
4625
4751
|
function buildElementSelector(el) {
|
|
@@ -5182,14 +5308,6 @@ async function observePage(page, sessionId, options = {}) {
|
|
|
5182
5308
|
const direct = el.getAttribute("aria-label") || el.getAttribute("placeholder") || el.getAttribute("title") || input.value || el.textContent || "";
|
|
5183
5309
|
return direct.replace(/\s+/g, " ").trim().slice(0, 120);
|
|
5184
5310
|
}
|
|
5185
|
-
function actionsFor(role, editable) {
|
|
5186
|
-
const actions = [];
|
|
5187
|
-
if (editable) actions.push("fill", "type");
|
|
5188
|
-
if (role === "combobox") actions.push("select");
|
|
5189
|
-
if (role === "checkbox" || role === "radio") actions.push("check");
|
|
5190
|
-
actions.push("click", "hover");
|
|
5191
|
-
return Array.from(new Set(actions));
|
|
5192
|
-
}
|
|
5193
5311
|
const selector = [
|
|
5194
5312
|
"a[href]",
|
|
5195
5313
|
"button",
|
|
@@ -5200,7 +5318,14 @@ async function observePage(page, sessionId, options = {}) {
|
|
|
5200
5318
|
"label",
|
|
5201
5319
|
"[role]",
|
|
5202
5320
|
"[tabindex]",
|
|
5203
|
-
'[contenteditable="true"]'
|
|
5321
|
+
'[contenteditable="true"]',
|
|
5322
|
+
// 非标准可交互控件:内联事件属性(agent-browser 基于 aria tree 完全不覆盖这类)。
|
|
5323
|
+
// 仅抓 HTML 显式声明 onclick/onmousedown 等的元素;addEventListener 绑定的无法静态发现。
|
|
5324
|
+
"[onclick]",
|
|
5325
|
+
"[onmousedown]",
|
|
5326
|
+
"[onmouseup]",
|
|
5327
|
+
"[onmouseover]",
|
|
5328
|
+
"[onkeydown]"
|
|
5204
5329
|
].join(",");
|
|
5205
5330
|
const candidates = Array.from(document.querySelectorAll(selector));
|
|
5206
5331
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -5224,13 +5349,10 @@ async function observePage(page, sessionId, options = {}) {
|
|
|
5224
5349
|
role,
|
|
5225
5350
|
name: textName(el),
|
|
5226
5351
|
tag,
|
|
5227
|
-
visible,
|
|
5228
5352
|
enabled,
|
|
5229
5353
|
editable,
|
|
5230
5354
|
...checked !== void 0 ? { checked } : {},
|
|
5231
|
-
...editable && input.value ? { value: input.value.slice(0, 120) } : {}
|
|
5232
|
-
...visible ? { box: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) } } : {},
|
|
5233
|
-
actions: actionsFor(role, editable)
|
|
5355
|
+
...editable && input.value ? { value: input.value.slice(0, 120) } : {}
|
|
5234
5356
|
});
|
|
5235
5357
|
if (targets2.length >= limit) break;
|
|
5236
5358
|
}
|
|
@@ -5244,13 +5366,15 @@ async function observePage(page, sessionId, options = {}) {
|
|
|
5244
5366
|
{ includeHidden: !!options.includeHidden, limit: options.limit ?? 80 }
|
|
5245
5367
|
)
|
|
5246
5368
|
]);
|
|
5247
|
-
const targets =
|
|
5369
|
+
const targets = raw.targets.map((target, index) => ({
|
|
5370
|
+
ref: `e${index + 1}`,
|
|
5371
|
+
...target
|
|
5372
|
+
}));
|
|
5248
5373
|
replaceRefs(sessionKey(sessionId), raw.screenHash, targets);
|
|
5249
5374
|
return {
|
|
5250
5375
|
url: page.url(),
|
|
5251
5376
|
title,
|
|
5252
5377
|
screenHash: raw.screenHash,
|
|
5253
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5254
5378
|
targets
|
|
5255
5379
|
};
|
|
5256
5380
|
}
|
|
@@ -5435,23 +5559,8 @@ async function waitForPage(page, input) {
|
|
|
5435
5559
|
return { success: true, matched: "selector", timeout, elapsed: Date.now() - startedAt };
|
|
5436
5560
|
}
|
|
5437
5561
|
if (input.text) {
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
return page.evaluate((text) => {
|
|
5441
|
-
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
|
5442
|
-
while (walker.nextNode()) {
|
|
5443
|
-
if (walker.currentNode.textContent?.includes(text)) return true;
|
|
5444
|
-
}
|
|
5445
|
-
return false;
|
|
5446
|
-
}, textToFind);
|
|
5447
|
-
});
|
|
5448
|
-
return {
|
|
5449
|
-
success: matched,
|
|
5450
|
-
matched: "text",
|
|
5451
|
-
timeout,
|
|
5452
|
-
elapsed: Date.now() - startedAt,
|
|
5453
|
-
...matched ? {} : { message: `Timed out waiting for text: ${input.text}` }
|
|
5454
|
-
};
|
|
5562
|
+
await page.getByText(input.text).first().waitFor({ state: "visible", timeout });
|
|
5563
|
+
return { success: true, matched: "text", timeout, elapsed: Date.now() - startedAt };
|
|
5455
5564
|
}
|
|
5456
5565
|
if (input.url) {
|
|
5457
5566
|
const matched = await pollUntil(timeout, pollInterval, async () => matchUrlPattern(page.url(), input.url));
|
|
@@ -5507,20 +5616,48 @@ async function waitForPage(page, input) {
|
|
|
5507
5616
|
// src/commands/snapshot.ts
|
|
5508
5617
|
var snapshotCommand = registerCommand({
|
|
5509
5618
|
name: "snapshot",
|
|
5510
|
-
description: "
|
|
5619
|
+
description: "Get page state: interactive @refs to operate (default); --type aria=page outline; --type text=content; --type dom=debug DOM",
|
|
5511
5620
|
scope: "page",
|
|
5512
5621
|
selectorParams: ["selector"],
|
|
5622
|
+
examples: [
|
|
5623
|
+
{
|
|
5624
|
+
cmd: "xbrowser snapshot",
|
|
5625
|
+
description: "I want to OPERATE the page \u2192 returns clickable/fillable @refs (use click @e1, fill @e2)",
|
|
5626
|
+
output: '@e1 [button] "Submit"\n@e2 [textbox editable] "Email"'
|
|
5627
|
+
},
|
|
5628
|
+
{
|
|
5629
|
+
cmd: "xbrowser snapshot --type aria",
|
|
5630
|
+
description: "I want the page OUTLINE/skeleton (nav, heading hierarchy, regions)",
|
|
5631
|
+
output: 'banner:\n navigation:\n link "Home"\nmain:\n heading "Welcome"'
|
|
5632
|
+
},
|
|
5633
|
+
{
|
|
5634
|
+
cmd: "xbrowser snapshot --type text",
|
|
5635
|
+
description: "I want the page TEXT CONTENT (extract body copy/information)",
|
|
5636
|
+
output: "Welcome\nPlease enter your email\nSubmit"
|
|
5637
|
+
},
|
|
5638
|
+
{
|
|
5639
|
+
cmd: "xbrowser snapshot --type dom",
|
|
5640
|
+
description: "I want to DEBUG the DOM (tag names, attributes, nesting)"
|
|
5641
|
+
},
|
|
5642
|
+
{
|
|
5643
|
+
cmd: "xbrowser snapshot --selectors",
|
|
5644
|
+
description: "I want to operate AND need stable CSS selectors (reuse across sessions)",
|
|
5645
|
+
output: "e1: #submit | e2: #email"
|
|
5646
|
+
}
|
|
5647
|
+
],
|
|
5513
5648
|
parameters: z25.object({
|
|
5514
|
-
type: z25.enum(["aria", "text", "dom", "all"]).default("
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5649
|
+
type: z25.enum(["interactive", "aria", "text", "dom", "all"]).default("interactive").describe(
|
|
5650
|
+
"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"
|
|
5651
|
+
),
|
|
5652
|
+
selector: z25.string().optional().describe("\u9650\u5B9A\u5230\u67D0\u4E2A\u5143\u7D20\uFF08CSS \u9009\u62E9\u5668\uFF09\uFF0C\u53EA\u5FEB\u7167\u8BE5\u5B50\u6811"),
|
|
5653
|
+
depth: z25.number().optional().default(6).describe("aria/dom \u6811\u7684\u6700\u5927\u6DF1\u5EA6"),
|
|
5654
|
+
interactive: z25.boolean().optional().default(false).describe("\u5F3A\u5236 interactive \u6A21\u5F0F\uFF08\u7B49\u540C --type interactive\uFF0C\u517C\u5BB9 -i\uFF09"),
|
|
5655
|
+
interactiveOnly: z25.boolean().optional().default(false).describe("interactive \u7684\u522B\u540D"),
|
|
5656
|
+
i: z25.boolean().optional().default(false).describe("interactive \u7684\u77ED\u522B\u540D"),
|
|
5657
|
+
compact: z25.boolean().optional().default(false).describe("\u9644\u5E26\u7D27\u51D1\u6587\u672C\u5FEB\u7167\uFF08interactive \u6A21\u5F0F\u9ED8\u8BA4\u5DF2\u542B\uFF09"),
|
|
5658
|
+
c: z25.boolean().optional().default(false).describe("compact \u7684\u77ED\u522B\u540D"),
|
|
5659
|
+
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"),
|
|
5660
|
+
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")
|
|
5524
5661
|
}),
|
|
5525
5662
|
result: z25.object({
|
|
5526
5663
|
url: z25.string(),
|
|
@@ -5533,14 +5670,13 @@ var snapshotCommand = registerCommand({
|
|
|
5533
5670
|
const page = ctx.page;
|
|
5534
5671
|
const url = page.url();
|
|
5535
5672
|
const title = await page.title().catch(() => "");
|
|
5536
|
-
|
|
5673
|
+
const wantInteractive = p.type === "interactive" || p.interactive || p.interactiveOnly || p.i || p.compact || p.c || p.selectors;
|
|
5674
|
+
if (wantInteractive) {
|
|
5537
5675
|
const observation = await observePage(page, ctx.sessionId, {
|
|
5538
5676
|
includeHidden: p.all
|
|
5539
5677
|
});
|
|
5540
5678
|
if (p.selectors) observation.selectors = buildSelectorMap(observation);
|
|
5541
|
-
|
|
5542
|
-
observation.compact = formatObservationCompact(observation, { selectors: p.selectors });
|
|
5543
|
-
}
|
|
5679
|
+
observation.compact = formatObservationCompact(observation, { selectors: p.selectors });
|
|
5544
5680
|
return ok24(observation, normalizeTips3([
|
|
5545
5681
|
`refs refreshed for ${observation.targets.length} targets; use click @e1 or fill @e2 "text"`
|
|
5546
5682
|
]));
|
|
@@ -5560,14 +5696,20 @@ var snapshotCommand = registerCommand({
|
|
|
5560
5696
|
return ok24({ url, title, dom });
|
|
5561
5697
|
}
|
|
5562
5698
|
if (p.type === "all") {
|
|
5563
|
-
const [aria, text, dom] = await Promise.all([
|
|
5699
|
+
const [observation, aria, text, dom] = await Promise.all([
|
|
5700
|
+
observePage(page, ctx.sessionId, { includeHidden: p.all }),
|
|
5564
5701
|
captureAriaSnapshot(page, p.selector, p.depth),
|
|
5565
5702
|
captureTextSnapshot(page, p.selector),
|
|
5566
5703
|
captureDomSnapshot(page, p.selector, p.depth ?? 6)
|
|
5567
5704
|
]);
|
|
5705
|
+
observation.compact = formatObservationCompact(observation, { selectors: p.selectors });
|
|
5706
|
+
if (p.selectors) observation.selectors = buildSelectorMap(observation);
|
|
5568
5707
|
const tips = await buildRefTips(page, aria);
|
|
5569
5708
|
persistSemantics(url, aria);
|
|
5570
|
-
return ok24({
|
|
5709
|
+
return ok24({ ...observation, aria, text, dom }, normalizeTips3([
|
|
5710
|
+
...tips,
|
|
5711
|
+
`${observation.targets.length} interactive targets + aria + text + dom combined`
|
|
5712
|
+
]));
|
|
5571
5713
|
}
|
|
5572
5714
|
return fail11(`Unknown snapshot type: ${p.type}`);
|
|
5573
5715
|
}
|
|
@@ -5596,16 +5738,29 @@ async function buildRefTips(page, aria) {
|
|
|
5596
5738
|
}
|
|
5597
5739
|
}
|
|
5598
5740
|
async function captureAriaSnapshot(page, selector, _depth) {
|
|
5741
|
+
let raw;
|
|
5599
5742
|
try {
|
|
5600
5743
|
const locator = selector ? page.locator(selector).first() : page.locator("body");
|
|
5601
|
-
|
|
5744
|
+
raw = await locator.ariaSnapshot();
|
|
5602
5745
|
} catch {
|
|
5603
5746
|
try {
|
|
5604
|
-
|
|
5747
|
+
raw = await page.locator("body").ariaSnapshot();
|
|
5605
5748
|
} catch {
|
|
5606
5749
|
return "(aria snapshot not available)";
|
|
5607
5750
|
}
|
|
5608
5751
|
}
|
|
5752
|
+
return filterAriaNoise(raw);
|
|
5753
|
+
}
|
|
5754
|
+
function filterAriaNoise(raw) {
|
|
5755
|
+
return raw.split("\n").filter((line) => {
|
|
5756
|
+
const t = line.trim();
|
|
5757
|
+
if (!t) return false;
|
|
5758
|
+
if (t === "none:" || t.startsWith("none: ")) return false;
|
|
5759
|
+
if (t.includes("InlineTextBox")) return false;
|
|
5760
|
+
if (t.includes("ListMarker")) return false;
|
|
5761
|
+
if (/^[a-z]+$/.test(t) || /^[a-z]+:$/.test(t)) return false;
|
|
5762
|
+
return true;
|
|
5763
|
+
}).join("\n");
|
|
5609
5764
|
}
|
|
5610
5765
|
async function captureTextSnapshot(page, selector) {
|
|
5611
5766
|
if (selector) {
|
|
@@ -7444,6 +7599,9 @@ var TipGenerator = class {
|
|
|
7444
7599
|
categoryLabel(category) {
|
|
7445
7600
|
const labels = {
|
|
7446
7601
|
dialog: "Dialog",
|
|
7602
|
+
filechooser: "File Chooser",
|
|
7603
|
+
popup: "Popup",
|
|
7604
|
+
download: "Download",
|
|
7447
7605
|
modal: "Modal",
|
|
7448
7606
|
popover: "Popover",
|
|
7449
7607
|
notification: "\u901A\u77E5",
|
|
@@ -7508,8 +7666,62 @@ var TipsManager = class {
|
|
|
7508
7666
|
generator = new TipGenerator(this.contextTracker);
|
|
7509
7667
|
beforeSnapshot = null;
|
|
7510
7668
|
lastDetectionTime = 0;
|
|
7669
|
+
// CDP 弹窗事件检测(filechooser / dialog / popup)
|
|
7670
|
+
detectedEvents = [];
|
|
7671
|
+
eventListenersAttached = false;
|
|
7672
|
+
lastCommandName = "";
|
|
7511
7673
|
async beforeCommand(page, commandName, params) {
|
|
7512
7674
|
this.contextTracker.record(commandName, params);
|
|
7675
|
+
this.lastCommandName = commandName;
|
|
7676
|
+
if (!this.eventListenersAttached && typeof page.on === "function") {
|
|
7677
|
+
this.eventListenersAttached = true;
|
|
7678
|
+
page.on("dialog", (dialog) => {
|
|
7679
|
+
const d = dialog;
|
|
7680
|
+
try {
|
|
7681
|
+
this.detectedEvents.push({
|
|
7682
|
+
type: "dialog",
|
|
7683
|
+
message: `[${d.type()}] ${d.message().slice(0, 200)}`,
|
|
7684
|
+
commandName: this.lastCommandName
|
|
7685
|
+
});
|
|
7686
|
+
} catch {
|
|
7687
|
+
}
|
|
7688
|
+
});
|
|
7689
|
+
page.on("filechooser", (chooser) => {
|
|
7690
|
+
const c = chooser;
|
|
7691
|
+
try {
|
|
7692
|
+
this.detectedEvents.push({
|
|
7693
|
+
type: "filechooser",
|
|
7694
|
+
message: `\u6587\u4EF6\u9009\u62E9\u5F39\u7A97${c.isMultiple ? "\uFF08\u591A\u9009\uFF09" : ""}\uFF1Aselector=${c.selector || "input[type=file]"}`,
|
|
7695
|
+
selector: c.selector,
|
|
7696
|
+
commandName: this.lastCommandName
|
|
7697
|
+
});
|
|
7698
|
+
} catch {
|
|
7699
|
+
}
|
|
7700
|
+
});
|
|
7701
|
+
page.on("popup", (info) => {
|
|
7702
|
+
const p = info;
|
|
7703
|
+
try {
|
|
7704
|
+
this.detectedEvents.push({
|
|
7705
|
+
type: "popup",
|
|
7706
|
+
message: `\u65B0\u7A97\u53E3\u5F39\u7A97\uFF1Aurl=${p.url || "(unknown)"}${p.windowName ? ` name=${p.windowName}` : ""}`,
|
|
7707
|
+
commandName: this.lastCommandName
|
|
7708
|
+
});
|
|
7709
|
+
} catch {
|
|
7710
|
+
}
|
|
7711
|
+
});
|
|
7712
|
+
page.on("download", (info) => {
|
|
7713
|
+
const d = info;
|
|
7714
|
+
try {
|
|
7715
|
+
const stateLabel = d.state === "completed" ? "\u5B8C\u6210" : d.state === "canceled" ? "\u53D6\u6D88" : "\u5F00\u59CB";
|
|
7716
|
+
this.detectedEvents.push({
|
|
7717
|
+
type: "download",
|
|
7718
|
+
message: `\u6587\u4EF6\u4E0B\u8F7D${stateLabel}\uFF1A${d.filename || "unknown"}${d.url ? ` (${d.url.slice(0, 80)})` : ""}`,
|
|
7719
|
+
commandName: this.lastCommandName
|
|
7720
|
+
});
|
|
7721
|
+
} catch {
|
|
7722
|
+
}
|
|
7723
|
+
});
|
|
7724
|
+
}
|
|
7513
7725
|
if (!this.domWatcher) {
|
|
7514
7726
|
this.domWatcher = new DomWatcher(page);
|
|
7515
7727
|
}
|
|
@@ -7552,20 +7764,59 @@ var TipsManager = class {
|
|
|
7552
7764
|
}
|
|
7553
7765
|
}
|
|
7554
7766
|
async afterCommand() {
|
|
7555
|
-
if (!this.domWatcher || !this.beforeSnapshot)
|
|
7767
|
+
if (!this.domWatcher || !this.beforeSnapshot) {
|
|
7768
|
+
const cdpTips = this.collectCdpEventTips();
|
|
7769
|
+
this.detectedEvents = [];
|
|
7770
|
+
return cdpTips;
|
|
7771
|
+
}
|
|
7556
7772
|
await this.debounce();
|
|
7557
7773
|
try {
|
|
7558
7774
|
const currentElements = await this.domWatcher.scanOverlays();
|
|
7559
7775
|
const afterSnapshot = buildSnapshot(currentElements);
|
|
7560
7776
|
const newElements = this.generator.diff(this.beforeSnapshot, afterSnapshot, currentElements);
|
|
7561
7777
|
const tips = this.generator.generate(newElements);
|
|
7778
|
+
const cdpTips = this.collectCdpEventTips();
|
|
7779
|
+
tips.push(...cdpTips);
|
|
7562
7780
|
this.beforeSnapshot = null;
|
|
7781
|
+
this.detectedEvents = [];
|
|
7563
7782
|
return tips;
|
|
7564
7783
|
} catch {
|
|
7784
|
+
const cdpTips = this.collectCdpEventTips();
|
|
7565
7785
|
this.beforeSnapshot = null;
|
|
7566
|
-
|
|
7786
|
+
this.detectedEvents = [];
|
|
7787
|
+
return cdpTips;
|
|
7567
7788
|
}
|
|
7568
7789
|
}
|
|
7790
|
+
/**
|
|
7791
|
+
* 把检测到的 CDP 弹窗事件转成 SmartTip
|
|
7792
|
+
* 包括:dialog(alert/confirm/prompt)、filechooser(文件选择弹窗)、popup(新窗口)
|
|
7793
|
+
*/
|
|
7794
|
+
collectCdpEventTips() {
|
|
7795
|
+
if (this.detectedEvents.length === 0) return [];
|
|
7796
|
+
return this.detectedEvents.map((evt) => {
|
|
7797
|
+
const suggestions = [];
|
|
7798
|
+
if (evt.type === "dialog") {
|
|
7799
|
+
suggestions.push("\u6B64\u5F39\u7A97\u53EF\u80FD\u963B\u585E\u540E\u7EED\u64CD\u4F5C");
|
|
7800
|
+
suggestions.push('\u5982\u9700\u81EA\u52A8\u5904\u7406\uFF1A\u4F7F\u7528 page.on("dialog") \u62E6\u622A');
|
|
7801
|
+
} else if (evt.type === "filechooser") {
|
|
7802
|
+
suggestions.push("\u6B64\u5F39\u7A97\u7531\u9875\u9762\u64CD\u4F5C\u89E6\u53D1\uFF08\u5982\u70B9\u51FB\u4E0A\u4F20\u6309\u94AE\uFF09");
|
|
7803
|
+
suggestions.push("\u5982\u9700\u81EA\u52A8\u5904\u7406\uFF1A\u4F7F\u7528 --path/--paths \u53C2\u6570\u4E0A\u4F20\u6587\u4EF6");
|
|
7804
|
+
} else if (evt.type === "popup") {
|
|
7805
|
+
suggestions.push("\u9875\u9762\u5C1D\u8BD5\u6253\u5F00\u65B0\u7A97\u53E3\uFF08\u53EF\u80FD\u88AB\u6D4F\u89C8\u5668\u62E6\u622A\uFF09");
|
|
7806
|
+
suggestions.push('\u5982\u9700\u5904\u7406\uFF1A\u68C0\u67E5\u5F39\u7A97\u62E6\u622A\u8BBE\u7F6E\u6216\u4F7F\u7528 page.on("popup") \u76D1\u542C');
|
|
7807
|
+
} else if (evt.type === "download") {
|
|
7808
|
+
suggestions.push("\u9875\u9762\u89E6\u53D1\u4E86\u6587\u4EF6\u4E0B\u8F7D");
|
|
7809
|
+
suggestions.push("\u5982\u9700\u63A7\u5236\u8DEF\u5F84\uFF1Apage.setDownloadBehavior(path)");
|
|
7810
|
+
}
|
|
7811
|
+
return {
|
|
7812
|
+
category: evt.type,
|
|
7813
|
+
priority: "p1",
|
|
7814
|
+
message: `\u{1F514} [\u5F39\u7A97\u68C0\u6D4B] ${evt.message}\uFF08\u89E6\u53D1\u547D\u4EE4: ${evt.commandName || "\u672A\u77E5"}\uFF09`,
|
|
7815
|
+
selector: evt.selector,
|
|
7816
|
+
suggestions
|
|
7817
|
+
};
|
|
7818
|
+
});
|
|
7819
|
+
}
|
|
7569
7820
|
debounce() {
|
|
7570
7821
|
const ms = tipsDebounceMs();
|
|
7571
7822
|
if (ms <= 0) return Promise.resolve();
|
|
@@ -7586,6 +7837,9 @@ var TipsManager = class {
|
|
|
7586
7837
|
this.contextTracker.clear();
|
|
7587
7838
|
this.domWatcher = null;
|
|
7588
7839
|
this.lastDetectionTime = 0;
|
|
7840
|
+
this.detectedEvents = [];
|
|
7841
|
+
this.eventListenersAttached = false;
|
|
7842
|
+
this.lastCommandName = "";
|
|
7589
7843
|
}
|
|
7590
7844
|
};
|
|
7591
7845
|
var globalTipsManager = null;
|
|
@@ -8610,6 +8864,9 @@ async function executeChain(input, options, executeCommand2) {
|
|
|
8610
8864
|
continue;
|
|
8611
8865
|
}
|
|
8612
8866
|
const { params } = parseCommandArgs(cmdName, cmdArgs, unquote2);
|
|
8867
|
+
if (options?.frame && params._frame === void 0 && params.frame === void 0) {
|
|
8868
|
+
params._frame = options.frame;
|
|
8869
|
+
}
|
|
8613
8870
|
if (cmdName === "goto" && params.url) {
|
|
8614
8871
|
const existing = await findOrRestoreSession(sessionName, options?.cdpEndpoint);
|
|
8615
8872
|
if (!existing) {
|
|
@@ -8865,9 +9122,14 @@ async function executeCommand(commandName, params, sessionName = "default", extr
|
|
|
8865
9122
|
const { _tabIndex: _u, ...rest } = params;
|
|
8866
9123
|
params = rest;
|
|
8867
9124
|
}
|
|
9125
|
+
const _frame = params._frame;
|
|
9126
|
+
if (_frame) {
|
|
9127
|
+
const { _frame: _u, ...rest } = params;
|
|
9128
|
+
params = rest;
|
|
9129
|
+
}
|
|
8868
9130
|
let targetPageOverride = null;
|
|
8869
9131
|
if (_target && extraOpts?.cdpEndpoint) {
|
|
8870
|
-
const { findTargetPage } = await import("./browser-
|
|
9132
|
+
const { findTargetPage } = await import("./browser-I2NLJN2A.js");
|
|
8871
9133
|
targetPageOverride = await findTargetPage(extraOpts.cdpEndpoint, _target);
|
|
8872
9134
|
if (!targetPageOverride) {
|
|
8873
9135
|
return errorResult(`Target "${_target}" not found. Use 'xbrowser targets --cdp ${extraOpts.cdpEndpoint}' to list available pages.`);
|
|
@@ -8931,6 +9193,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
|
|
|
8931
9193
|
browserContext: session?.context,
|
|
8932
9194
|
sessionId: session?.id,
|
|
8933
9195
|
cdpEndpoint: session?.cdpEndpoint || extraOpts?.cdpEndpoint,
|
|
9196
|
+
frame: _frame,
|
|
8934
9197
|
args: [],
|
|
8935
9198
|
options: {},
|
|
8936
9199
|
cwd: process.cwd(),
|
|
@@ -9107,7 +9370,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
|
|
|
9107
9370
|
});
|
|
9108
9371
|
if (session?.page && process.env.XBROWSER_RECOVERY && !extraOpts?._recoveryAttempted) {
|
|
9109
9372
|
try {
|
|
9110
|
-
const { attemptRecovery } = await import("./recovery-
|
|
9373
|
+
const { attemptRecovery } = await import("./recovery-JFGV3DBX.js");
|
|
9111
9374
|
const recovery = await attemptRecovery(
|
|
9112
9375
|
session.page,
|
|
9113
9376
|
sessionName,
|