@xbrowser/cli 0.16.0 → 1.0.2
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 +17 -26
- package/dist/{browser-R7B255ML.js → browser-GITRHHFO.js} +4 -1
- package/dist/{browser-GWBH6OJK.js → browser-R56O3CW6.js} +3 -1
- package/dist/{browser-I2HJZ7IP.js → browser-ZJOZB5CR.js} +4 -2
- package/dist/cdp-driver-BE3FOMRN.js +2803 -0
- package/dist/cdp-driver-TOPYJIFL.js +47 -0
- package/dist/chunk-2SVQTI2O.js +2794 -0
- package/dist/{chunk-KDYXFLAC.js → chunk-ACFE6PKF.js} +1015 -121
- package/dist/chunk-BBMRDUYQ.js +260 -0
- package/dist/chunk-CAFNSGYM.js +4834 -0
- package/dist/{chunk-DTJRVA76.js → chunk-ETCO4SNK.js} +2 -2
- package/dist/{chunk-RS6YYWTK.js → chunk-JPA2ZT2R.js} +140 -72
- package/dist/chunk-JPHCY4TC.js +260 -0
- package/dist/chunk-KFQGP6VL.js +33 -0
- package/dist/{chunk-ITKPSIP7.js → chunk-MDAPTB7C.js} +6 -25
- package/dist/chunk-OZKD3W4X.js +417 -0
- package/dist/chunk-PPG4D2EW.js +2796 -0
- package/dist/{chunk-ATFTAKMN.js → chunk-Q4IGYTKR.js} +39 -7
- package/dist/{chunk-F3ZWFCJJ.js → chunk-QIK2I3VQ.js} +141 -72
- package/dist/chunk-WJRE55TN.js +83 -0
- package/dist/cli.js +2358 -1086
- package/dist/{convert-4DUWZIKH.js → convert-LB3GJTLR.js} +4 -2
- package/dist/{convert-EKQVHKB4.js → convert-R3XXYKC6.js} +2 -2
- package/dist/{daemon-client-GX2UYIW4.js → daemon-client-DRCUMNHK.js} +45 -72
- package/dist/{daemon-client-XWSSQBEA.js → daemon-client-UZZEHHIV.js} +8 -1
- package/dist/daemon-main.js +3067 -1688
- package/dist/{extract-JUOQQX4V.js → extract-2ZFW2MX7.js} +1 -1
- package/dist/{extract-EGRXZSSK.js → extract-BSYBM4MR.js} +2 -0
- package/dist/{filter-OLAE26HN.js → filter-KCFO4RSV.js} +2 -0
- package/dist/{filter-VID2GGZ7.js → filter-T7DSZ2X7.js} +1 -1
- package/dist/{human-interaction-W753RVJB.js → human-interaction-UKAS5ZXV.js} +2 -2
- package/dist/index.d.ts +745 -148
- package/dist/index.js +3488 -1719
- package/dist/launcher-QUJ4M2VS.js +19 -0
- package/dist/launcher-YARP45UY.js +19 -0
- package/dist/{network-store-YAF5OIBH.js → network-store-XGZ25FFC.js} +1 -0
- package/dist/{network-store-BN6QEZ7R.js → network-store-YVDNUREI.js} +1 -1
- package/dist/{parse-action-dsl-T3DYC33D.js → parse-action-dsl-UM333TL2.js} +1 -1
- package/dist/{proxy-WKGUCH2C.js → proxy-LV4BJ5RC.js} +1 -1
- package/dist/session-recorder-RTDGURIJ.js +8 -0
- package/dist/session-recorder-YI7YYM36.js +7 -0
- package/dist/session-replayer-GLTUICSD.js +276 -0
- package/dist/site-knowledge-SYC6VCDB.js +23 -0
- package/package.json +6 -6
- package/dist/chunk-2ONMTDLK.js +0 -2050
- package/dist/daemon-client-3IJD6X4B.js +0 -59
- package/dist/network-store-2S5HATEV.js +0 -194
- package/dist/parse-action-dsl-DRSPBALP.js +0 -72
- package/dist/screenshot-CWAWMXVA.js +0 -28
- package/dist/screenshot-MB6R7RSS.js +0 -26
- package/dist/session-recorder-ILSSV2UC.js +0 -6
- package/dist/session-recorder-XET3DNML.js +0 -7
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import "./chunk-KFQGP6VL.js";
|
|
2
|
+
|
|
1
3
|
// src/commands/convert.ts
|
|
2
4
|
function escapeString(str) {
|
|
3
5
|
return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
|
|
@@ -9,12 +11,12 @@ function generateJSScript(recording) {
|
|
|
9
11
|
// Start URL: ${recording.startUrl}
|
|
10
12
|
// Events: ${events.length}
|
|
11
13
|
|
|
12
|
-
import {
|
|
14
|
+
import { launch } from '@xbrowser/cli';
|
|
13
15
|
|
|
14
16
|
const START_URL = '${escapeString(recording.startUrl)}';
|
|
15
17
|
|
|
16
18
|
async function main() {
|
|
17
|
-
const browser = await
|
|
19
|
+
const { browser } = await launch({ headless: true });
|
|
18
20
|
const context = await browser.newContext();
|
|
19
21
|
const page = await context.newPage();
|
|
20
22
|
|
|
@@ -1,66 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
import { stopDaemon as xcliStopDaemon, isDaemonRunning, getDaemonStatus, killAllDaemon } from "@dyyz1993/xcli-core";
|
|
7
|
-
var CONFIG_DIR = join(homedir(), ".xbrowser");
|
|
8
|
-
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
var WORKER_PATH = join(__dirname, "daemon-main.js");
|
|
10
|
-
function getDaemonConfig() {
|
|
11
|
-
return {
|
|
12
|
-
configDir: CONFIG_DIR,
|
|
13
|
-
workerEntryPath: WORKER_PATH,
|
|
14
|
-
basePort: 9224
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
async function startDaemonProcess(port = 9224) {
|
|
18
|
-
const config = getDaemonConfig();
|
|
19
|
-
if (isDaemonRunning(config)) {
|
|
20
|
-
const status = getDaemonStatus(config);
|
|
21
|
-
if (status.port === port && status.pid) {
|
|
22
|
-
return { pid: status.pid, port: status.port, startedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
23
|
-
}
|
|
24
|
-
await xcliStopDaemon(config);
|
|
25
|
-
}
|
|
26
|
-
const child = spawn("node", [WORKER_PATH], {
|
|
27
|
-
detached: true,
|
|
28
|
-
stdio: "ignore",
|
|
29
|
-
env: {
|
|
30
|
-
...process.env,
|
|
31
|
-
XBROWSER_DAEMON_PORT: String(port)
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
child.unref();
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
let resolved = false;
|
|
37
|
-
const timeout = setTimeout(() => {
|
|
38
|
-
if (!resolved) {
|
|
39
|
-
resolved = true;
|
|
40
|
-
reject(new Error("Daemon start timeout after 15s"));
|
|
41
|
-
}
|
|
42
|
-
}, 15e3);
|
|
43
|
-
const checkInterval = setInterval(() => {
|
|
44
|
-
if (isDaemonRunning(config)) {
|
|
45
|
-
const s = getDaemonStatus(config);
|
|
46
|
-
if (s.port === port && s.pid) {
|
|
47
|
-
resolved = true;
|
|
48
|
-
clearTimeout(timeout);
|
|
49
|
-
clearInterval(checkInterval);
|
|
50
|
-
resolve({ pid: s.pid, port: s.port, startedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}, 200);
|
|
54
|
-
child.on("error", (err) => {
|
|
55
|
-
if (!resolved) {
|
|
56
|
-
resolved = true;
|
|
57
|
-
clearTimeout(timeout);
|
|
58
|
-
clearInterval(checkInterval);
|
|
59
|
-
reject(err);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
startDaemonProcess
|
|
3
|
+
} from "./chunk-WJRE55TN.js";
|
|
4
|
+
import "./chunk-KFQGP6VL.js";
|
|
64
5
|
|
|
65
6
|
// src/client/daemon-client.ts
|
|
66
7
|
var DAEMON_PORT = 9224;
|
|
@@ -90,6 +31,12 @@ async function ensureDaemonRunning() {
|
|
|
90
31
|
_ensurePromise = null;
|
|
91
32
|
throw new Error("Daemon not available");
|
|
92
33
|
}
|
|
34
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
35
|
+
const ready = await fetch(`${DAEMON_BASE}/health`, { signal: AbortSignal.timeout(1e3) }).then((r) => r.ok ? r.json() : null).then((d) => d?.status === "ok").catch(() => false);
|
|
36
|
+
if (ready) return;
|
|
37
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
38
|
+
}
|
|
39
|
+
throw new Error("Daemon HTTP server not ready after 4s");
|
|
93
40
|
}
|
|
94
41
|
async function rpcCall(method, params = {}, timeoutMs = 1e4) {
|
|
95
42
|
await ensureDaemonRunning();
|
|
@@ -100,11 +47,17 @@ async function rpcCall(method, params = {}, timeoutMs = 1e4) {
|
|
|
100
47
|
signal: AbortSignal.timeout(timeoutMs)
|
|
101
48
|
});
|
|
102
49
|
if (!resp.ok) {
|
|
103
|
-
|
|
50
|
+
let detail = resp.statusText;
|
|
51
|
+
try {
|
|
52
|
+
const body = await resp.json();
|
|
53
|
+
if (body?.error) detail = body.error;
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`Daemon error: ${detail}`);
|
|
104
57
|
}
|
|
105
58
|
return resp.json();
|
|
106
59
|
}
|
|
107
|
-
async function
|
|
60
|
+
async function isDaemonRunning() {
|
|
108
61
|
try {
|
|
109
62
|
const resp = await fetch(`${DAEMON_BASE}/health`, { signal: AbortSignal.timeout(2e3) });
|
|
110
63
|
if (!resp.ok) return false;
|
|
@@ -137,8 +90,8 @@ async function forwardExec(command, params, session = "default", cdpEndpoint, ti
|
|
|
137
90
|
if (cdpEndpoint) rpcParams.cdpEndpoint = cdpEndpoint;
|
|
138
91
|
try {
|
|
139
92
|
return await rpcCall("exec", rpcParams, timeoutMs);
|
|
140
|
-
} catch {
|
|
141
|
-
return { success: false, data: null, message:
|
|
93
|
+
} catch (e) {
|
|
94
|
+
return { success: false, data: null, message: e.message, duration: 0 };
|
|
142
95
|
}
|
|
143
96
|
}
|
|
144
97
|
async function forwardChain(input, session = "default", cdpEndpoint) {
|
|
@@ -146,10 +99,27 @@ async function forwardChain(input, session = "default", cdpEndpoint) {
|
|
|
146
99
|
if (cdpEndpoint) params.cdpEndpoint = cdpEndpoint;
|
|
147
100
|
try {
|
|
148
101
|
return await rpcCall("chain", params, 12e4);
|
|
149
|
-
} catch {
|
|
150
|
-
return { success: false, steps: [], totalDuration: 0, stoppedReason:
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return { success: false, steps: [], totalDuration: 0, stoppedReason: e.message };
|
|
151
104
|
}
|
|
152
105
|
}
|
|
106
|
+
async function forwardAgentObserve(session = "default", options) {
|
|
107
|
+
const params = { session };
|
|
108
|
+
if (options?.cdpEndpoint) params.cdpEndpoint = options.cdpEndpoint;
|
|
109
|
+
if (options?.includeHidden !== void 0) params.includeHidden = options.includeHidden;
|
|
110
|
+
if (options?.limit !== void 0) params.limit = options.limit;
|
|
111
|
+
return rpcCall("agent:observe", params, 3e4);
|
|
112
|
+
}
|
|
113
|
+
async function forwardAgentAct(session = "default", params, cdpEndpoint) {
|
|
114
|
+
const rpcParams = { ...params, session };
|
|
115
|
+
if (cdpEndpoint) rpcParams.cdpEndpoint = cdpEndpoint;
|
|
116
|
+
return rpcCall("agent:act", rpcParams, 3e4);
|
|
117
|
+
}
|
|
118
|
+
async function forwardAgentWait(session = "default", params, cdpEndpoint, timeoutMs = 3e4) {
|
|
119
|
+
const rpcParams = { ...params, session };
|
|
120
|
+
if (cdpEndpoint) rpcParams.cdpEndpoint = cdpEndpoint;
|
|
121
|
+
return rpcCall("agent:wait", rpcParams, timeoutMs + 5e3);
|
|
122
|
+
}
|
|
153
123
|
async function forwardNetworkList(sessionName, options) {
|
|
154
124
|
return rpcCall("network:list", { session: sessionName, ...options }, 3e4);
|
|
155
125
|
}
|
|
@@ -186,8 +156,8 @@ async function forwardNetworkExport(sessionName, id, lang) {
|
|
|
186
156
|
async function forwardNetworkInspect(sessionName, id) {
|
|
187
157
|
return rpcCall("network:inspect", { session: sessionName, id }, 1e4);
|
|
188
158
|
}
|
|
189
|
-
async function forwardRecordStart(session, url) {
|
|
190
|
-
return rpcCall("record:start", { session, url }, 15e3);
|
|
159
|
+
async function forwardRecordStart(session, url, cdpEndpoint) {
|
|
160
|
+
return rpcCall("record:start", { session, url, cdpEndpoint }, 15e3);
|
|
191
161
|
}
|
|
192
162
|
async function forwardRecordStop(session) {
|
|
193
163
|
return rpcCall("record:stop", { session }, 1e4);
|
|
@@ -212,6 +182,9 @@ async function forwardViewerCheckSelector(name, selector) {
|
|
|
212
182
|
}
|
|
213
183
|
export {
|
|
214
184
|
daemonPing,
|
|
185
|
+
forwardAgentAct,
|
|
186
|
+
forwardAgentObserve,
|
|
187
|
+
forwardAgentWait,
|
|
215
188
|
forwardChain,
|
|
216
189
|
forwardCommandLog,
|
|
217
190
|
forwardExec,
|
|
@@ -237,5 +210,5 @@ export {
|
|
|
237
210
|
forwardSessionCreate,
|
|
238
211
|
forwardSessionList,
|
|
239
212
|
forwardViewerCheckSelector,
|
|
240
|
-
|
|
213
|
+
isDaemonRunning
|
|
241
214
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
daemonPing,
|
|
3
|
+
forwardAgentAct,
|
|
4
|
+
forwardAgentObserve,
|
|
5
|
+
forwardAgentWait,
|
|
3
6
|
forwardChain,
|
|
4
7
|
forwardCommandLog,
|
|
5
8
|
forwardExec,
|
|
@@ -26,9 +29,13 @@ import {
|
|
|
26
29
|
forwardSessionList,
|
|
27
30
|
forwardViewerCheckSelector,
|
|
28
31
|
isDaemonRunning
|
|
29
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-Q4IGYTKR.js";
|
|
33
|
+
import "./chunk-KFQGP6VL.js";
|
|
30
34
|
export {
|
|
31
35
|
daemonPing,
|
|
36
|
+
forwardAgentAct,
|
|
37
|
+
forwardAgentObserve,
|
|
38
|
+
forwardAgentWait,
|
|
32
39
|
forwardChain,
|
|
33
40
|
forwardCommandLog,
|
|
34
41
|
forwardExec,
|