@xbrowser/cli 1.0.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-GURRY444.js → browser-GITRHHFO.js} +4 -3
- package/dist/{browser-DSVV4GHS.js → browser-R56O3CW6.js} +3 -3
- package/dist/{browser-53KUFEEM.js → browser-ZJOZB5CR.js} +4 -4
- package/dist/{cdp-driver-MNPR3HZH.js → cdp-driver-BE3FOMRN.js} +324 -58
- package/dist/{cdp-driver-SSXUGXP6.js → cdp-driver-TOPYJIFL.js} +3 -3
- package/dist/chunk-2SVQTI2O.js +2794 -0
- package/dist/{chunk-2MFXKN32.js → chunk-ACFE6PKF.js} +1013 -119
- package/dist/chunk-BBMRDUYQ.js +260 -0
- package/dist/{chunk-E4O5ZU3H.js → chunk-CAFNSGYM.js} +393 -95
- package/dist/{chunk-DTJRVA76.js → chunk-ETCO4SNK.js} +2 -2
- package/dist/{chunk-YKOHDEFV.js → chunk-JPA2ZT2R.js} +69 -36
- package/dist/{chunk-T4J4C2NZ.js → chunk-JPHCY4TC.js} +12 -2
- 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-42RPMJ76.js → chunk-PPG4D2EW.js} +325 -59
- package/dist/{chunk-IDVD44ED.js → chunk-Q4IGYTKR.js} +19 -7
- package/dist/{chunk-2BQZIT3S.js → chunk-QIK2I3VQ.js} +86 -2501
- package/dist/chunk-WJRE55TN.js +83 -0
- package/dist/cli.js +1435 -1077
- package/dist/{convert-EGFYNICZ.js → convert-LB3GJTLR.js} +3 -3
- package/dist/{convert-EKQVHKB4.js → convert-R3XXYKC6.js} +2 -2
- package/dist/{daemon-client-3VM7VU7O.js → daemon-client-DRCUMNHK.js} +25 -74
- package/dist/{daemon-client-YAVQ343A.js → daemon-client-UZZEHHIV.js} +2 -2
- package/dist/daemon-main.js +2200 -1691
- package/dist/{extract-JUOQQX4V.js → extract-2ZFW2MX7.js} +1 -1
- package/dist/{extract-L2IW3IUB.js → extract-BSYBM4MR.js} +1 -1
- package/dist/{filter-HC4RA7JY.js → filter-KCFO4RSV.js} +1 -1
- 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 +165 -108
- package/dist/index.js +2531 -1680
- package/dist/launcher-QUJ4M2VS.js +19 -0
- package/dist/{launcher-KA7J32K5.js → launcher-YARP45UY.js} +1 -1
- package/dist/{network-store-66A2RATI.js → network-store-XGZ25FFC.js} +1 -1
- 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 +5 -4
- package/dist/screenshot-CWAWMXVA.js +0 -28
- package/dist/session-recorder-MA75PKTQ.js +0 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./chunk-
|
|
1
|
+
import "./chunk-KFQGP6VL.js";
|
|
2
2
|
|
|
3
3
|
// src/commands/convert.ts
|
|
4
4
|
function escapeString(str) {
|
|
@@ -11,12 +11,12 @@ function generateJSScript(recording) {
|
|
|
11
11
|
// Start URL: ${recording.startUrl}
|
|
12
12
|
// Events: ${events.length}
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { launch } from '@xbrowser/cli';
|
|
15
15
|
|
|
16
16
|
const START_URL = '${escapeString(recording.startUrl)}';
|
|
17
17
|
|
|
18
18
|
async function main() {
|
|
19
|
-
const browser = await
|
|
19
|
+
const { browser } = await launch({ headless: true });
|
|
20
20
|
const context = await browser.newContext();
|
|
21
21
|
const page = await context.newPage();
|
|
22
22
|
|
|
@@ -1,68 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import { join, dirname } from "path";
|
|
6
|
-
import { homedir } from "os";
|
|
7
|
-
import { fileURLToPath } from "url";
|
|
8
|
-
import { stopDaemon as xcliStopDaemon, isDaemonRunning, getDaemonStatus, killAllDaemon } from "@dyyz1993/xcli-core";
|
|
9
|
-
var CONFIG_DIR = join(homedir(), ".xbrowser");
|
|
10
|
-
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
var WORKER_PATH = join(__dirname, "daemon-main.js");
|
|
12
|
-
function getDaemonConfig() {
|
|
13
|
-
return {
|
|
14
|
-
configDir: CONFIG_DIR,
|
|
15
|
-
workerEntryPath: WORKER_PATH,
|
|
16
|
-
basePort: 9224
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
async function startDaemonProcess(port = 9224) {
|
|
20
|
-
const config = getDaemonConfig();
|
|
21
|
-
if (isDaemonRunning(config)) {
|
|
22
|
-
const status = getDaemonStatus(config);
|
|
23
|
-
if (status.port === port && status.pid) {
|
|
24
|
-
return { pid: status.pid, port: status.port, startedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
25
|
-
}
|
|
26
|
-
await xcliStopDaemon(config);
|
|
27
|
-
}
|
|
28
|
-
const child = spawn("node", [WORKER_PATH], {
|
|
29
|
-
detached: true,
|
|
30
|
-
stdio: "ignore",
|
|
31
|
-
env: {
|
|
32
|
-
...process.env,
|
|
33
|
-
XBROWSER_DAEMON_PORT: String(port)
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
child.unref();
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
let resolved = false;
|
|
39
|
-
const timeout = setTimeout(() => {
|
|
40
|
-
if (!resolved) {
|
|
41
|
-
resolved = true;
|
|
42
|
-
reject(new Error("Daemon start timeout after 15s"));
|
|
43
|
-
}
|
|
44
|
-
}, 15e3);
|
|
45
|
-
const checkInterval = setInterval(() => {
|
|
46
|
-
if (isDaemonRunning(config)) {
|
|
47
|
-
const s = getDaemonStatus(config);
|
|
48
|
-
if (s.port === port && s.pid) {
|
|
49
|
-
resolved = true;
|
|
50
|
-
clearTimeout(timeout);
|
|
51
|
-
clearInterval(checkInterval);
|
|
52
|
-
resolve({ pid: s.pid, port: s.port, startedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}, 200);
|
|
56
|
-
child.on("error", (err) => {
|
|
57
|
-
if (!resolved) {
|
|
58
|
-
resolved = true;
|
|
59
|
-
clearTimeout(timeout);
|
|
60
|
-
clearInterval(checkInterval);
|
|
61
|
-
reject(err);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
startDaemonProcess
|
|
3
|
+
} from "./chunk-WJRE55TN.js";
|
|
4
|
+
import "./chunk-KFQGP6VL.js";
|
|
66
5
|
|
|
67
6
|
// src/client/daemon-client.ts
|
|
68
7
|
var DAEMON_PORT = 9224;
|
|
@@ -92,6 +31,12 @@ async function ensureDaemonRunning() {
|
|
|
92
31
|
_ensurePromise = null;
|
|
93
32
|
throw new Error("Daemon not available");
|
|
94
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");
|
|
95
40
|
}
|
|
96
41
|
async function rpcCall(method, params = {}, timeoutMs = 1e4) {
|
|
97
42
|
await ensureDaemonRunning();
|
|
@@ -102,11 +47,17 @@ async function rpcCall(method, params = {}, timeoutMs = 1e4) {
|
|
|
102
47
|
signal: AbortSignal.timeout(timeoutMs)
|
|
103
48
|
});
|
|
104
49
|
if (!resp.ok) {
|
|
105
|
-
|
|
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}`);
|
|
106
57
|
}
|
|
107
58
|
return resp.json();
|
|
108
59
|
}
|
|
109
|
-
async function
|
|
60
|
+
async function isDaemonRunning() {
|
|
110
61
|
try {
|
|
111
62
|
const resp = await fetch(`${DAEMON_BASE}/health`, { signal: AbortSignal.timeout(2e3) });
|
|
112
63
|
if (!resp.ok) return false;
|
|
@@ -139,8 +90,8 @@ async function forwardExec(command, params, session = "default", cdpEndpoint, ti
|
|
|
139
90
|
if (cdpEndpoint) rpcParams.cdpEndpoint = cdpEndpoint;
|
|
140
91
|
try {
|
|
141
92
|
return await rpcCall("exec", rpcParams, timeoutMs);
|
|
142
|
-
} catch {
|
|
143
|
-
return { success: false, data: null, message:
|
|
93
|
+
} catch (e) {
|
|
94
|
+
return { success: false, data: null, message: e.message, duration: 0 };
|
|
144
95
|
}
|
|
145
96
|
}
|
|
146
97
|
async function forwardChain(input, session = "default", cdpEndpoint) {
|
|
@@ -148,8 +99,8 @@ async function forwardChain(input, session = "default", cdpEndpoint) {
|
|
|
148
99
|
if (cdpEndpoint) params.cdpEndpoint = cdpEndpoint;
|
|
149
100
|
try {
|
|
150
101
|
return await rpcCall("chain", params, 12e4);
|
|
151
|
-
} catch {
|
|
152
|
-
return { success: false, steps: [], totalDuration: 0, stoppedReason:
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return { success: false, steps: [], totalDuration: 0, stoppedReason: e.message };
|
|
153
104
|
}
|
|
154
105
|
}
|
|
155
106
|
async function forwardAgentObserve(session = "default", options) {
|
|
@@ -205,8 +156,8 @@ async function forwardNetworkExport(sessionName, id, lang) {
|
|
|
205
156
|
async function forwardNetworkInspect(sessionName, id) {
|
|
206
157
|
return rpcCall("network:inspect", { session: sessionName, id }, 1e4);
|
|
207
158
|
}
|
|
208
|
-
async function forwardRecordStart(session, url) {
|
|
209
|
-
return rpcCall("record:start", { session, url }, 15e3);
|
|
159
|
+
async function forwardRecordStart(session, url, cdpEndpoint) {
|
|
160
|
+
return rpcCall("record:start", { session, url, cdpEndpoint }, 15e3);
|
|
210
161
|
}
|
|
211
162
|
async function forwardRecordStop(session) {
|
|
212
163
|
return rpcCall("record:stop", { session }, 1e4);
|
|
@@ -259,5 +210,5 @@ export {
|
|
|
259
210
|
forwardSessionCreate,
|
|
260
211
|
forwardSessionList,
|
|
261
212
|
forwardViewerCheckSelector,
|
|
262
|
-
|
|
213
|
+
isDaemonRunning
|
|
263
214
|
};
|
|
@@ -29,8 +29,8 @@ import {
|
|
|
29
29
|
forwardSessionList,
|
|
30
30
|
forwardViewerCheckSelector,
|
|
31
31
|
isDaemonRunning
|
|
32
|
-
} from "./chunk-
|
|
33
|
-
import "./chunk-
|
|
32
|
+
} from "./chunk-Q4IGYTKR.js";
|
|
33
|
+
import "./chunk-KFQGP6VL.js";
|
|
34
34
|
export {
|
|
35
35
|
daemonPing,
|
|
36
36
|
forwardAgentAct,
|