@xbrowser/cli 0.14.3 → 0.15.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 +63 -1
- package/dist/cli.js +126 -99
- package/dist/daemon-main.js +67 -34
- package/dist/index.d.ts +2026 -5
- package/dist/index.js +124 -97
- package/package.json +19 -3
package/dist/daemon-main.js
CHANGED
|
@@ -24,13 +24,13 @@ import {
|
|
|
24
24
|
} from "./chunk-F3ZWFCJJ.js";
|
|
25
25
|
|
|
26
26
|
// src/daemon/daemon-main.ts
|
|
27
|
-
import { writeFileSync as
|
|
27
|
+
import { writeFileSync as writeFileSync8, mkdirSync as mkdirSync6, appendFileSync } from "fs";
|
|
28
28
|
import { join as join6 } from "path";
|
|
29
29
|
import { homedir as homedir6 } from "os";
|
|
30
30
|
import { startHttpServer } from "@dyyz1993/xcli-core";
|
|
31
31
|
|
|
32
32
|
// src/daemon/rpc-handlers.ts
|
|
33
|
-
import { writeFileSync as
|
|
33
|
+
import { writeFileSync as writeFileSync7, mkdirSync as mkdirSync5 } from "fs";
|
|
34
34
|
import { join as join5 } from "path";
|
|
35
35
|
import { homedir as homedir5 } from "os";
|
|
36
36
|
import {
|
|
@@ -129,7 +129,18 @@ function parsePluginParams(args, schema, base = {}) {
|
|
|
129
129
|
if (value === "true") params[key] = true;
|
|
130
130
|
else if (value === "false") params[key] = false;
|
|
131
131
|
else if (/^\d+$/.test(value)) params[key] = parseInt(value, 10);
|
|
132
|
-
else
|
|
132
|
+
else {
|
|
133
|
+
try {
|
|
134
|
+
const parsed = JSON.parse(value);
|
|
135
|
+
if (Array.isArray(parsed) || typeof parsed === "object" && parsed !== null) {
|
|
136
|
+
params[key] = parsed;
|
|
137
|
+
} else {
|
|
138
|
+
params[key] = value;
|
|
139
|
+
}
|
|
140
|
+
} catch {
|
|
141
|
+
params[key] = value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
133
144
|
i++;
|
|
134
145
|
} else {
|
|
135
146
|
params[key] = true;
|
|
@@ -6206,8 +6217,48 @@ async function loadHooks() {
|
|
|
6206
6217
|
// src/executor.ts
|
|
6207
6218
|
import { homedir as homedir3 } from "os";
|
|
6208
6219
|
import { join as join3 } from "path";
|
|
6220
|
+
import { existsSync as existsSync6, readFileSync as readFileSync10, writeFileSync as writeFileSync5, mkdirSync as mkdirSync3 } from "fs";
|
|
6209
6221
|
var NAVIGATION_COMMANDS = /* @__PURE__ */ new Set(["goto", "back", "forward", "refresh"]);
|
|
6210
6222
|
var snapshotHintShown = /* @__PURE__ */ new WeakSet();
|
|
6223
|
+
var STORAGE_DIR = join3(homedir3(), ".xbrowser", "storage");
|
|
6224
|
+
var storageCache = /* @__PURE__ */ new Map();
|
|
6225
|
+
function getPluginStorage(pluginName) {
|
|
6226
|
+
if (!storageCache.has(pluginName)) {
|
|
6227
|
+
const filePath = join3(STORAGE_DIR, `${pluginName}.json`);
|
|
6228
|
+
let data = {};
|
|
6229
|
+
const load3 = () => {
|
|
6230
|
+
if (existsSync6(filePath)) {
|
|
6231
|
+
try {
|
|
6232
|
+
data = JSON.parse(readFileSync10(filePath, "utf-8"));
|
|
6233
|
+
} catch {
|
|
6234
|
+
data = {};
|
|
6235
|
+
}
|
|
6236
|
+
}
|
|
6237
|
+
};
|
|
6238
|
+
const save = () => {
|
|
6239
|
+
mkdirSync3(STORAGE_DIR, { recursive: true });
|
|
6240
|
+
writeFileSync5(filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
6241
|
+
};
|
|
6242
|
+
load3();
|
|
6243
|
+
storageCache.set(pluginName, {
|
|
6244
|
+
get: async (key) => data[key] ?? null,
|
|
6245
|
+
set: async (key, value) => {
|
|
6246
|
+
data[key] = value;
|
|
6247
|
+
save();
|
|
6248
|
+
},
|
|
6249
|
+
delete: async (key) => {
|
|
6250
|
+
delete data[key];
|
|
6251
|
+
save();
|
|
6252
|
+
},
|
|
6253
|
+
clear: async () => {
|
|
6254
|
+
data = {};
|
|
6255
|
+
save();
|
|
6256
|
+
},
|
|
6257
|
+
keys: async () => Object.keys(data)
|
|
6258
|
+
});
|
|
6259
|
+
}
|
|
6260
|
+
return storageCache.get(pluginName);
|
|
6261
|
+
}
|
|
6211
6262
|
var archiveInitialized = false;
|
|
6212
6263
|
function ensureArchiveInit() {
|
|
6213
6264
|
if (!archiveInitialized) {
|
|
@@ -6315,16 +6366,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
|
|
|
6315
6366
|
args: [],
|
|
6316
6367
|
options: {},
|
|
6317
6368
|
cwd: process.cwd(),
|
|
6318
|
-
storage:
|
|
6319
|
-
get: async () => null,
|
|
6320
|
-
set: async () => {
|
|
6321
|
-
},
|
|
6322
|
-
delete: async () => {
|
|
6323
|
-
},
|
|
6324
|
-
clear: async () => {
|
|
6325
|
-
},
|
|
6326
|
-
keys: async () => []
|
|
6327
|
-
},
|
|
6369
|
+
storage: getPluginStorage(commandName),
|
|
6328
6370
|
output: {
|
|
6329
6371
|
mode: "text",
|
|
6330
6372
|
showTips: false,
|
|
@@ -6547,16 +6589,7 @@ async function executeChain(input, options) {
|
|
|
6547
6589
|
browser: session.context.browser(),
|
|
6548
6590
|
browserContext: session.context,
|
|
6549
6591
|
sessionId: session.id,
|
|
6550
|
-
storage:
|
|
6551
|
-
get: async (_key) => null,
|
|
6552
|
-
set: async (_key, _value) => {
|
|
6553
|
-
},
|
|
6554
|
-
delete: async (_key) => {
|
|
6555
|
-
},
|
|
6556
|
-
clear: async () => {
|
|
6557
|
-
},
|
|
6558
|
-
keys: async () => []
|
|
6559
|
-
},
|
|
6592
|
+
storage: getPluginStorage(cmdName),
|
|
6560
6593
|
output: { mode: "text", showTips: false, color: false, emoji: false },
|
|
6561
6594
|
error: (msg) => {
|
|
6562
6595
|
throw new Error(msg);
|
|
@@ -6578,7 +6611,7 @@ async function executeChain(input, options) {
|
|
|
6578
6611
|
const outputs = [];
|
|
6579
6612
|
for (const h of hooks) {
|
|
6580
6613
|
const output = await h.onAfterCommand?.({ page: session.page, command: `${cmdName} ${subCommand}`, params: pluginParams, result: raw, duration: duration2 });
|
|
6581
|
-
if (output) outputs.push(output);
|
|
6614
|
+
if (output) outputs.push({ _hook: h.name, ...output });
|
|
6582
6615
|
}
|
|
6583
6616
|
if (outputs.length > 0) hookOutputs = outputs;
|
|
6584
6617
|
}
|
|
@@ -6927,7 +6960,7 @@ async function replayEntry(entry, options = {}) {
|
|
|
6927
6960
|
}
|
|
6928
6961
|
|
|
6929
6962
|
// src/daemon/feedback-store.ts
|
|
6930
|
-
import { readFileSync as
|
|
6963
|
+
import { readFileSync as readFileSync11, writeFileSync as writeFileSync6, mkdirSync as mkdirSync4 } from "fs";
|
|
6931
6964
|
import { join as join4 } from "path";
|
|
6932
6965
|
import { homedir as homedir4 } from "os";
|
|
6933
6966
|
var FEEDBACK_FILE = join4(homedir4(), ".xbrowser", "feedback.json");
|
|
@@ -6938,7 +6971,7 @@ var FeedbackStore = class {
|
|
|
6938
6971
|
}
|
|
6939
6972
|
load() {
|
|
6940
6973
|
try {
|
|
6941
|
-
const data =
|
|
6974
|
+
const data = readFileSync11(FEEDBACK_FILE, "utf8");
|
|
6942
6975
|
this.entries = JSON.parse(data);
|
|
6943
6976
|
} catch {
|
|
6944
6977
|
this.entries = [];
|
|
@@ -6946,8 +6979,8 @@ var FeedbackStore = class {
|
|
|
6946
6979
|
}
|
|
6947
6980
|
save() {
|
|
6948
6981
|
try {
|
|
6949
|
-
|
|
6950
|
-
|
|
6982
|
+
mkdirSync4(join4(homedir4(), ".xbrowser"), { recursive: true });
|
|
6983
|
+
writeFileSync6(FEEDBACK_FILE, JSON.stringify(this.entries, null, 2));
|
|
6951
6984
|
} catch {
|
|
6952
6985
|
}
|
|
6953
6986
|
}
|
|
@@ -7618,9 +7651,9 @@ function createRPCHandler() {
|
|
|
7618
7651
|
try {
|
|
7619
7652
|
const events = await sess.page.evaluate(() => window.__xb_evts || []);
|
|
7620
7653
|
const recordingsDir = join5(CONFIG_DIR, "recordings");
|
|
7621
|
-
|
|
7654
|
+
mkdirSync5(recordingsDir, { recursive: true });
|
|
7622
7655
|
const outPath = params.path || join5(recordingsDir, `recording-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.json`);
|
|
7623
|
-
|
|
7656
|
+
writeFileSync7(outPath, JSON.stringify({
|
|
7624
7657
|
startUrl: sess.page.url(),
|
|
7625
7658
|
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7626
7659
|
events
|
|
@@ -8673,10 +8706,10 @@ var WSServer = class extends EventEmitter {
|
|
|
8673
8706
|
}
|
|
8674
8707
|
case "file_download": {
|
|
8675
8708
|
try {
|
|
8676
|
-
const { readFileSync:
|
|
8709
|
+
const { readFileSync: readFileSync13 } = await import("fs");
|
|
8677
8710
|
const { resolve: resolve9, basename } = await import("path");
|
|
8678
8711
|
const targetPath = resolve9(msg.path);
|
|
8679
|
-
const data =
|
|
8712
|
+
const data = readFileSync13(targetPath);
|
|
8680
8713
|
const base64 = data.toString("base64");
|
|
8681
8714
|
const ext = targetPath.split(".").pop()?.toLowerCase() || "";
|
|
8682
8715
|
const mimeMap = {
|
|
@@ -9975,8 +10008,8 @@ async function main() {
|
|
|
9975
10008
|
rpcHandler.setPreviewWS(previewWS);
|
|
9976
10009
|
previewWS.on("screencast-started", (sid) => log(`Preview screencast started: ${sid}`));
|
|
9977
10010
|
previewWS.on("screencast-stopped", (sid) => log(`Preview screencast stopped: ${sid}`));
|
|
9978
|
-
|
|
9979
|
-
|
|
10011
|
+
mkdirSync6(CONFIG_DIR2, { recursive: true });
|
|
10012
|
+
writeFileSync8(join6(CONFIG_DIR2, "daemon.json"), JSON.stringify({
|
|
9980
10013
|
port: daemonPort,
|
|
9981
10014
|
pid: process.pid,
|
|
9982
10015
|
startedAt: Date.now()
|