@ricsam/browser-mcp 0.3.13 → 0.3.14
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.
|
@@ -22,12 +22,13 @@ async function readCapability(path) {
|
|
|
22
22
|
}
|
|
23
23
|
const cap = JSON.parse(text);
|
|
24
24
|
const u = new URL(cap.url);
|
|
25
|
-
|
|
25
|
+
const link = cap.method === "GET" && /^\/api\/native-data\/[a-zA-Z0-9-]+\/download\/[A-Za-z0-9_-]{43}$/.test(u.pathname);
|
|
26
|
+
if (u.protocol !== "https:" || u.username || u.password || u.search || u.hash || !link && !/^\/api\/native-data\/[a-zA-Z0-9-]+$/.test(u.pathname) || !["GET", "PUT"].includes(cap.method) || !link && !/^Bearer [A-Za-z0-9_-]{43}$/.test(cap.headers?.Authorization ?? "") || !Number.isFinite(cap.expiresAt) || cap.expiresAt <= Date.now() || cap.limits.maxAttempts !== 1 || cap.limits.resumable !== false || cap.size !== undefined && (!Number.isSafeInteger(cap.size) || cap.size !== cap.limits.maxBytes) || cap.sha256 !== undefined && !/^[a-f0-9]{64}$/.test(cap.sha256) || !Number.isSafeInteger(cap.limits.maxBytes) || cap.limits.maxBytes < 0 || cap.limits.maxBytes > 256 * 1024 * 1024)
|
|
26
27
|
throw new Error("Invalid capability");
|
|
27
28
|
return cap;
|
|
28
29
|
}
|
|
29
30
|
async function capabilityFetch(cap, body) {
|
|
30
|
-
const response = await fetch(cap.url, { method: cap.method, headers: { Authorization: cap.headers.Authorization }, body: body ? Readable.toWeb(body) : undefined, duplex: "half", redirect: "error", signal: AbortSignal.timeout(120000) });
|
|
31
|
+
const response = await fetch(cap.url, { method: cap.method, headers: cap.url.includes("/download/") ? {} : { Authorization: cap.headers.Authorization }, body: body ? Readable.toWeb(body) : undefined, duplex: "half", redirect: "error", signal: AbortSignal.timeout(120000) });
|
|
31
32
|
if (!response.ok)
|
|
32
33
|
throw new Error("Capability transfer failed; do not automatically retry");
|
|
33
34
|
return response;
|
|
@@ -54,7 +54,7 @@ function onceAsync(action) {
|
|
|
54
54
|
// cli/src/browser/owned-chrome.ts
|
|
55
55
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
56
56
|
// cli/package.json
|
|
57
|
-
var version = "0.3.
|
|
57
|
+
var version = "0.3.14";
|
|
58
58
|
|
|
59
59
|
// cli/src/browser/chrome-diagnostics.ts
|
|
60
60
|
import { constants } from "node:fs";
|
|
@@ -2856,15 +2856,18 @@ class BrowserPageEvents {
|
|
|
2856
2856
|
this.pending = pending;
|
|
2857
2857
|
return await Promise.race([work, interrupted]);
|
|
2858
2858
|
}
|
|
2859
|
-
startDownload(download) {
|
|
2859
|
+
startDownload(download, downloadId) {
|
|
2860
2860
|
const event = this.record("download", {
|
|
2861
2861
|
state: "started",
|
|
2862
|
+
downloadId,
|
|
2863
|
+
resourceId: downloadId,
|
|
2864
|
+
readiness: "pending",
|
|
2862
2865
|
filename: download.suggestedFilename().slice(0, 255),
|
|
2863
2866
|
url: diagnosticUrl(download.url())
|
|
2864
2867
|
});
|
|
2865
2868
|
this.downloads.set(event.eventId, download);
|
|
2866
2869
|
return (data) => {
|
|
2867
|
-
this.record("download", { ...data, transferId: event.eventId, actionId: event.actionId, filename: event.filename });
|
|
2870
|
+
this.record("download", { ...data, downloadId, resourceId: downloadId, transferId: event.eventId, actionId: event.actionId, filename: event.filename });
|
|
2868
2871
|
this.downloads.delete(event.eventId);
|
|
2869
2872
|
};
|
|
2870
2873
|
}
|
|
@@ -3506,17 +3509,17 @@ class BrowserRuntime {
|
|
|
3506
3509
|
await this.setViewport(page, state.tabId, state.viewport);
|
|
3507
3510
|
}).catch(() => {}));
|
|
3508
3511
|
page.on("download", (download) => {
|
|
3509
|
-
const
|
|
3512
|
+
const downloadId = crypto.randomUUID();
|
|
3513
|
+
const finish = this.events.get(page).startDownload(download, downloadId);
|
|
3510
3514
|
const saving = Promise.resolve().then(async () => {
|
|
3511
3515
|
if (this.downloadHandler) {
|
|
3512
|
-
await this.downloadHandler(download, page);
|
|
3513
|
-
finish({ state: "completed" });
|
|
3516
|
+
finish(await this.downloadHandler(download, page, downloadId));
|
|
3514
3517
|
} else {
|
|
3515
3518
|
await download.cancel();
|
|
3516
|
-
finish({ state: "canceled" });
|
|
3519
|
+
finish({ state: "canceled", readiness: "unavailable", code: "capture_unavailable" });
|
|
3517
3520
|
}
|
|
3518
3521
|
}).catch((error) => {
|
|
3519
|
-
finish({ state: "failed", code: "
|
|
3522
|
+
finish({ state: "failed", readiness: "unavailable", code: "download_capture_failed", recovery: "Inspect browser_list_downloads or browser_transfer_status with resourceId equal to downloadId. Do not automatically replay the website action." });
|
|
3520
3523
|
process.stderr.write(`[r5d-browser] failed to save download
|
|
3521
3524
|
`);
|
|
3522
3525
|
}).finally(() => this.savingDownloads.delete(saving));
|
|
@@ -4066,7 +4069,13 @@ class BrowserRuntime {
|
|
|
4066
4069
|
mimeType: file.mimeType
|
|
4067
4070
|
};
|
|
4068
4071
|
});
|
|
4069
|
-
return { tabId, exported: true, format: input.format, exports
|
|
4072
|
+
return { tabId, exported: true, format: input.format, exports, ...input.format === "pdf" ? {
|
|
4073
|
+
exportKind: "page_print",
|
|
4074
|
+
printMode: "css_print",
|
|
4075
|
+
contentCompleteness: "unverified",
|
|
4076
|
+
limitations: "PDF bytes were generated from the current page using Chrome print CSS, not a native document/message export. Nested scroll containers, lazy/unloaded content, collapsed sections, images, and application print styles may omit content; successful generation does not verify all source content.",
|
|
4077
|
+
guidance: "Inspect every PDF page for expected text and images. For an original message/document use the website's native download/export. If authorized, open the site's dedicated print view using its normal controls and export that tab; no print view, expansion, scrolling, or page modification is performed automatically."
|
|
4078
|
+
} : {} };
|
|
4070
4079
|
}
|
|
4071
4080
|
case "webmcp_list":
|
|
4072
4081
|
return { tabId, ...await this.webmcp.get(page).list() };
|
|
@@ -4544,7 +4553,7 @@ class NativeRuntime {
|
|
|
4544
4553
|
this.instanceId = instanceId;
|
|
4545
4554
|
this.serverOrigin = serverOrigin;
|
|
4546
4555
|
installCancellation(context);
|
|
4547
|
-
this.engine = new BrowserRuntime(context, directory, `${directory}.uploads`, (download, page) => this.download(download, page), (page) => this.assertPageDeep(page));
|
|
4556
|
+
this.engine = new BrowserRuntime(context, directory, `${directory}.uploads`, (download, page, downloadId) => this.download(download, page, downloadId), (page) => this.assertPageDeep(page));
|
|
4548
4557
|
context.on("page", (page) => {
|
|
4549
4558
|
this.track(page);
|
|
4550
4559
|
});
|
|
@@ -4585,19 +4594,18 @@ class NativeRuntime {
|
|
|
4585
4594
|
});
|
|
4586
4595
|
});
|
|
4587
4596
|
}
|
|
4588
|
-
async download(download, page) {
|
|
4597
|
+
async download(download, page, downloadId) {
|
|
4589
4598
|
const id = await this.engine.idFor(page), scope = this.owners.get(id);
|
|
4590
4599
|
if (!scope || this.disconnected) {
|
|
4591
4600
|
await download.cancel();
|
|
4592
|
-
return;
|
|
4601
|
+
return { state: "canceled", readiness: "unavailable", code: "download_scope_unavailable" };
|
|
4593
4602
|
}
|
|
4594
|
-
const
|
|
4595
|
-
if (!
|
|
4603
|
+
const handler = this.plugins.find((p) => p.onDownload);
|
|
4604
|
+
if (!handler) {
|
|
4596
4605
|
await download.cancel();
|
|
4597
|
-
return;
|
|
4606
|
+
return { state: "canceled", readiness: "unavailable", code: "capture_unavailable" };
|
|
4598
4607
|
}
|
|
4599
|
-
|
|
4600
|
-
await p.onDownload(download, id, scope, this.generations.get(id) ?? 0);
|
|
4608
|
+
return handler.onDownload(download, id, scope, this.generations.get(id) ?? 0, downloadId);
|
|
4601
4609
|
}
|
|
4602
4610
|
scopeEpoch(scope) {
|
|
4603
4611
|
this.validateScope(scope);
|
|
@@ -5287,9 +5295,16 @@ class Relay {
|
|
|
5287
5295
|
seen = new Set;
|
|
5288
5296
|
active;
|
|
5289
5297
|
recent = [];
|
|
5298
|
+
blocker(active, scope) {
|
|
5299
|
+
const quarantined = active.timedOut || active.interrupted;
|
|
5300
|
+
const state = { quarantined, executionState: active.settled ? active.interrupted ? "settled_after_interruption" : "settled_late" : quarantined ? "unresolved" : "in_progress" };
|
|
5301
|
+
if (scope && !sameScope3(active.scope, scope))
|
|
5302
|
+
return { ...state, ownedByAnotherScope: true };
|
|
5303
|
+
return { ...state, operationId: active.id, operation: active.op, startedAt: active.startedAt, deadlineAt: active.deadlineAt, callerDeadline: active.timedOut ? "expired" : active.interrupted ? "interrupted" : "pending", cancellationConfirmed: false, recoveryAvailable: quarantined && !!active.tabId && !active.recovering };
|
|
5304
|
+
}
|
|
5290
5305
|
health(scope) {
|
|
5291
|
-
const active = this.active
|
|
5292
|
-
return { state: this.state, paused: this.paused, queueDepth: 0, admission: active ? "blocked" : "ready", quarantined: !!active && (active.timedOut || active.interrupted), operation:
|
|
5306
|
+
const active = this.active;
|
|
5307
|
+
return { state: this.state, paused: this.paused, queueDepth: 0, admission: active ? "blocked" : "ready", quarantined: !!active && (active.timedOut || active.interrupted), operation: active ? this.blocker(active, scope) : null, recent: this.recent.filter((r) => !scope || sameScope3(r.scope, scope)).map((r) => r.result) };
|
|
5293
5308
|
}
|
|
5294
5309
|
interrupt() {
|
|
5295
5310
|
if (this.active)
|
|
@@ -5343,7 +5358,7 @@ class Relay {
|
|
|
5343
5358
|
heartbeat.unref();
|
|
5344
5359
|
socket.once("open", () => {
|
|
5345
5360
|
this.state = "authenticating";
|
|
5346
|
-
socket.send(JSON.stringify({ type: "auth", token: this.token, client: { protocol: 3, version: "0.3.
|
|
5361
|
+
socket.send(JSON.stringify({ type: "auth", token: this.token, client: { protocol: 3, version: "0.3.14", instanceId: this.runtime.instanceId, operations: [...BROWSER_OPERATIONS, ...this.runtime.plugins.flatMap((p) => p.operations), "session_end", "release_tab", "runtime_health", "runtime_recover"], capabilities: ["runtime-quarantine.v1", "binary-artifacts.v1", "browser-controls.v1", "screenshot-ids.v1", "webmcp.page-context.v1", "clipboard.native.v1", "native-transfers.v1", "secrets.v1", "forwarding.v1", "live-view.v1"], liveView: { enabled: this.liveEnabled } } }));
|
|
5347
5362
|
});
|
|
5348
5363
|
socket.on("message", (bytes, binary) => {
|
|
5349
5364
|
if (binary || Buffer.byteLength(bytes.toString()) > LIMIT) {
|
|
@@ -5452,7 +5467,8 @@ class Relay {
|
|
|
5452
5467
|
return;
|
|
5453
5468
|
}
|
|
5454
5469
|
if (this.active) {
|
|
5455
|
-
|
|
5470
|
+
const active2 = this.active, quarantined = active2.timedOut || active2.interrupted;
|
|
5471
|
+
send({ type: "result", id: message.id, ok: false, outcome: "not_dispatched", error: { code: quarantined ? "blocked_by_prior_operation" : "runtime_busy", message: quarantined ? "A prior operation is quarantined after its deadline or an interruption. No action was queued or dispatched." : "Another operation is still in progress. No action was queued or dispatched." }, result: { operationId: message.id, blockingOperationId: sameScope3(active2.scope, message.scope) ? active2.id : undefined, category: quarantined ? "runtime_quarantined" : "runtime_busy", blocker: this.blocker(active2, message.scope), quarantined, retrySafe: true, executionState: "not_started", ...!quarantined ? { retryAfterMs: 250 } : {}, recovery: quarantined ? "Call browser_runtime_health. The prior outcome remains unknown; never replay the prior mutation. Wait for late settlement or request explicit user-approved recovery if available." : "Wait for the in-progress call to finish, or wait 250 ms and check browser_runtime_health before retrying only this never-dispatched request with a new request ID. Avoid tight retry loops; no tab closure or recovery is needed for ordinary contention." } });
|
|
5456
5472
|
return;
|
|
5457
5473
|
}
|
|
5458
5474
|
let finish;
|
|
@@ -5470,6 +5486,7 @@ class Relay {
|
|
|
5470
5486
|
}, Math.max(1, active.deadlineAt - Date.now()));
|
|
5471
5487
|
});
|
|
5472
5488
|
const task = (async () => {
|
|
5489
|
+
let response;
|
|
5473
5490
|
try {
|
|
5474
5491
|
const result = await this.runtime.execute(message.op, message.args, message.scope, message.id);
|
|
5475
5492
|
if (active.timedOut || active.interrupted || this.paused || this.stopping || socket !== this.socket || socket.readyState !== WebSocket2.OPEN)
|
|
@@ -5506,12 +5523,10 @@ class Relay {
|
|
|
5506
5523
|
}
|
|
5507
5524
|
if (Buffer.byteLength(JSON.stringify(result)) > 1800000)
|
|
5508
5525
|
throw new Error("Result budget exceeded");
|
|
5509
|
-
|
|
5510
|
-
send({ type: "result", id: message.id, ok: true, result: wireResult(message.op, result), blobs, outcome: result?.status === "unknown" ? "unknown" : "completed" });
|
|
5526
|
+
response = { type: "result", id: message.id, ok: true, result: wireResult(message.op, result), blobs, outcome: result?.status === "unknown" ? "unknown" : "completed" };
|
|
5511
5527
|
} catch (error) {
|
|
5512
5528
|
const failure = failureFor(error, message.op, message.id, stage);
|
|
5513
|
-
|
|
5514
|
-
send({ type: "result", id: message.id, ok: false, ...failure });
|
|
5529
|
+
response = { type: "result", id: message.id, ok: false, ...failure };
|
|
5515
5530
|
} finally {
|
|
5516
5531
|
clearTimeout(timer);
|
|
5517
5532
|
active.settled = true;
|
|
@@ -5521,6 +5536,8 @@ class Relay {
|
|
|
5521
5536
|
if (this.active === active && !active.interrupted && !active.recovering)
|
|
5522
5537
|
this.active = undefined;
|
|
5523
5538
|
}
|
|
5539
|
+
if (response && !active.timedOut && !active.interrupted)
|
|
5540
|
+
send(response);
|
|
5524
5541
|
})();
|
|
5525
5542
|
await Promise.race([task, expired]);
|
|
5526
5543
|
}
|
|
@@ -5721,8 +5738,22 @@ async function createDataPlugin(access, options) {
|
|
|
5721
5738
|
await mkdir2(options.directory, { mode: 448 });
|
|
5722
5739
|
const resources = new Map, owned = new Set, ownedDirs = new Set, vault = new SecretVault(access);
|
|
5723
5740
|
let stopped = false;
|
|
5741
|
+
const terminal = new Map;
|
|
5742
|
+
function remember(r) {
|
|
5743
|
+
if (r.purpose !== "download")
|
|
5744
|
+
return;
|
|
5745
|
+
terminal.set(r.id, { scope: r.scope, meta: { ...meta(r), state: r.terminalCode?.startsWith("download_capture") || r.terminalCode === "download_quota_exceeded" ? "failed" : r.terminalCode === "download_expired" ? "expired" : "cancelled", size: r.hash ? r.size : undefined, maxBytes: undefined, retrieval: undefined, readiness: "unavailable", code: r.terminalCode ?? "download_revoked", recovery: "Retained bytes are unavailable. Do not automatically replay the source action; ask before recreating the download." }, until: Date.now() + LIMITS.ttl });
|
|
5746
|
+
while (terminal.size > 128)
|
|
5747
|
+
terminal.delete(terminal.keys().next().value);
|
|
5748
|
+
}
|
|
5749
|
+
function status(scope, id) {
|
|
5750
|
+
const t = terminal.get(String(id));
|
|
5751
|
+
if (t && t.until >= Date.now() && sameScope(t.scope, scope))
|
|
5752
|
+
return t.meta;
|
|
5753
|
+
return meta(get(scope, id));
|
|
5754
|
+
}
|
|
5724
5755
|
function meta(r) {
|
|
5725
|
-
return { resourceId: r.id, fileId: r.id, maxBytes: r.size, size: r.size, name: r.name, state: r.state, sha256: r.hash, expiresAt: r.expiresAt, ...r.purpose === "download" ? { downloadId: r.id, mimeType: "application/octet-stream", sourceKind: "download", readiness: r.state === "ready" ? "ready" : "pending", retrieval: { tool: "browser_create_download", arguments: { downloadId: r.id } } } : {} };
|
|
5756
|
+
return { resourceId: r.id, fileId: r.id, maxBytes: r.size, size: r.purpose === "download" && !r.hash ? undefined : r.size, name: r.name, state: r.state, sha256: r.hash, expiresAt: r.expiresAt, ...r.purpose === "download" ? { downloadId: r.id, mimeType: "application/octet-stream", sourceKind: "download", readiness: r.state === "ready" ? "ready" : "pending", retrieval: { tool: "browser_create_download", arguments: { downloadId: r.id } } } : {} };
|
|
5726
5757
|
}
|
|
5727
5758
|
function get(scope, id) {
|
|
5728
5759
|
const r = resources.get(String(id));
|
|
@@ -5742,8 +5773,10 @@ async function createDataPlugin(access, options) {
|
|
|
5742
5773
|
return r;
|
|
5743
5774
|
}
|
|
5744
5775
|
async function remove(r) {
|
|
5776
|
+
r.terminalCode ??= "download_revoked";
|
|
5745
5777
|
r.abort.abort();
|
|
5746
5778
|
r.state = "cancelled";
|
|
5779
|
+
remember(r);
|
|
5747
5780
|
await r.task?.catch(() => {});
|
|
5748
5781
|
r.bytes?.fill(0);
|
|
5749
5782
|
r.bytes = undefined;
|
|
@@ -5835,8 +5868,20 @@ async function createDataPlugin(access, options) {
|
|
|
5835
5868
|
}
|
|
5836
5869
|
}
|
|
5837
5870
|
}
|
|
5871
|
+
async function sweepExpired() {
|
|
5872
|
+
await revoke((r) => {
|
|
5873
|
+
if (r.expiresAt < Date.now() && r.state !== "attached") {
|
|
5874
|
+
r.terminalCode = "download_expired";
|
|
5875
|
+
return true;
|
|
5876
|
+
}
|
|
5877
|
+
return false;
|
|
5878
|
+
});
|
|
5879
|
+
for (const [id, t] of terminal)
|
|
5880
|
+
if (t.until < Date.now())
|
|
5881
|
+
terminal.delete(id);
|
|
5882
|
+
}
|
|
5838
5883
|
let sweep = setInterval(() => {
|
|
5839
|
-
|
|
5884
|
+
sweepExpired();
|
|
5840
5885
|
}, 1e4);
|
|
5841
5886
|
sweep.unref?.();
|
|
5842
5887
|
return {
|
|
@@ -5861,12 +5906,15 @@ async function createDataPlugin(access, options) {
|
|
|
5861
5906
|
throw new Error("Download unavailable");
|
|
5862
5907
|
return meta(r);
|
|
5863
5908
|
}
|
|
5864
|
-
if (op === "transfer_status")
|
|
5865
|
-
|
|
5909
|
+
if (op === "transfer_status") {
|
|
5910
|
+
await sweepExpired();
|
|
5911
|
+
return status(scope, args.resourceId ?? args.transferId);
|
|
5912
|
+
}
|
|
5866
5913
|
if (op === "cancel_transfer") {
|
|
5867
5914
|
const r = get(scope, args.resourceId ?? args.transferId);
|
|
5868
5915
|
if (r.state === "attached")
|
|
5869
5916
|
throw new Error("Attached files retained until document ends");
|
|
5917
|
+
r.terminalCode = "download_cancelled";
|
|
5870
5918
|
await remove(r);
|
|
5871
5919
|
return { cancelled: true };
|
|
5872
5920
|
}
|
|
@@ -5880,8 +5928,10 @@ async function createDataPlugin(access, options) {
|
|
|
5880
5928
|
r.task = transfer(r, grant);
|
|
5881
5929
|
return { resourceId: r.id, state: "transferring" };
|
|
5882
5930
|
}
|
|
5883
|
-
if (op === "list_downloads")
|
|
5884
|
-
|
|
5931
|
+
if (op === "list_downloads") {
|
|
5932
|
+
await sweepExpired();
|
|
5933
|
+
return { files: [...resources.values()].filter((r) => sameScope(r.scope, scope) && r.purpose === "download").map(meta), terminal: [...terminal.values()].filter((t) => sameScope(t.scope, scope)).map((t) => t.meta) };
|
|
5934
|
+
}
|
|
5885
5935
|
if (op === "upload_files") {
|
|
5886
5936
|
const ids = args.fileIds;
|
|
5887
5937
|
if (!Array.isArray(ids) || !ids.length || ids.length > 100 || new Set(ids).size !== ids.length)
|
|
@@ -5935,54 +5985,79 @@ async function createDataPlugin(access, options) {
|
|
|
5935
5985
|
}
|
|
5936
5986
|
throw new Error("Unsupported data operation");
|
|
5937
5987
|
},
|
|
5938
|
-
async onDownload(download, tabId, scope, generation) {
|
|
5988
|
+
async onDownload(download, tabId, scope, generation, downloadId = randomUUID7()) {
|
|
5939
5989
|
let r;
|
|
5990
|
+
let timeout2;
|
|
5940
5991
|
try {
|
|
5941
5992
|
r = create(scope, "download", LIMITS.file, download.suggestedFilename());
|
|
5993
|
+
resources.delete(r.id);
|
|
5994
|
+
r.id = downloadId;
|
|
5995
|
+
resources.set(r.id, r);
|
|
5942
5996
|
r.tabId = tabId;
|
|
5943
5997
|
r.generation = generation;
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
received += chunk.length;
|
|
5953
|
-
if (received > LIMITS.file)
|
|
5954
|
-
return callback(new Error("Download quota exceeded"));
|
|
5955
|
-
callback(null, chunk);
|
|
5956
|
-
} });
|
|
5957
|
-
const timeout2 = setTimeout(() => r.abort.abort(), LIMITS.duration);
|
|
5998
|
+
r.abort.signal.addEventListener("abort", () => {
|
|
5999
|
+
download.cancel().catch(() => {});
|
|
6000
|
+
}, { once: true });
|
|
6001
|
+
timeout2 = setTimeout(() => {
|
|
6002
|
+
r.terminalCode = "download_capture_timeout";
|
|
6003
|
+
r.abort.abort();
|
|
6004
|
+
download.cancel().catch(() => {});
|
|
6005
|
+
}, LIMITS.duration);
|
|
5958
6006
|
timeout2.unref?.();
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
6007
|
+
const captured = r;
|
|
6008
|
+
r.task = (async () => {
|
|
6009
|
+
const path9 = join2(options.directory, captured.id);
|
|
6010
|
+
captured.path = path9;
|
|
6011
|
+
owned.add(path9);
|
|
6012
|
+
const source = await download.createReadStream();
|
|
6013
|
+
if (!source)
|
|
6014
|
+
throw new Error("Download unavailable");
|
|
6015
|
+
let received = 0;
|
|
6016
|
+
const hash = createHash6("sha256");
|
|
6017
|
+
const bound = new Transform({ transform(chunk, _encoding, callback) {
|
|
6018
|
+
received += chunk.length;
|
|
6019
|
+
if (received > LIMITS.file) {
|
|
6020
|
+
captured.terminalCode = "download_quota_exceeded";
|
|
6021
|
+
return callback(new Error("Download quota exceeded"));
|
|
6022
|
+
}
|
|
6023
|
+
hash.update(chunk);
|
|
6024
|
+
callback(null, chunk);
|
|
6025
|
+
} });
|
|
6026
|
+
await pipeline(source, bound, createWriteStream(path9, { flags: "wx", mode: 384 }), { signal: captured.abort.signal });
|
|
6027
|
+
await chmod(path9, 384);
|
|
6028
|
+
const stat = await lstat2(path9);
|
|
6029
|
+
if (!stat.isFile() || stat.size !== received || captured.abort.signal.aborted || stopped || resources.get(captured.id) !== captured)
|
|
6030
|
+
throw new Error("Download revoked");
|
|
6031
|
+
captured.size = stat.size;
|
|
6032
|
+
captured.hash = hash.digest("hex");
|
|
6033
|
+
captured.state = "ready";
|
|
6034
|
+
})();
|
|
6035
|
+
await r.task;
|
|
6036
|
+
await download.delete().catch(() => {});
|
|
6037
|
+
if (r.abort.signal.aborted || stopped || resources.get(r.id) !== r)
|
|
5974
6038
|
throw new Error("Download revoked");
|
|
5975
|
-
r
|
|
6039
|
+
return { ...meta(r), state: "completed", readiness: "ready" };
|
|
5976
6040
|
} catch {
|
|
5977
6041
|
await download.cancel().catch(() => {});
|
|
5978
|
-
if (r)
|
|
6042
|
+
if (r) {
|
|
6043
|
+
r.terminalCode ??= "download_capture_failed";
|
|
5979
6044
|
await remove(r);
|
|
6045
|
+
return { ...status(scope, downloadId), state: "failed" };
|
|
6046
|
+
}
|
|
6047
|
+
const failed = { downloadId, resourceId: downloadId, state: "failed", readiness: "unavailable", code: "download_capture_rejected", recovery: "Capture could not be reserved. Do not automatically repeat the website action." };
|
|
6048
|
+
terminal.set(downloadId, { scope: { ...scope }, meta: failed, until: Date.now() + LIMITS.ttl });
|
|
6049
|
+
while (terminal.size > 128)
|
|
6050
|
+
terminal.delete(terminal.keys().next().value);
|
|
6051
|
+
return failed;
|
|
5980
6052
|
} finally {
|
|
5981
|
-
|
|
6053
|
+
if (timeout2)
|
|
6054
|
+
clearTimeout(timeout2);
|
|
6055
|
+
if (r?.state !== "ready")
|
|
6056
|
+
await download.delete().catch(() => {});
|
|
5982
6057
|
}
|
|
5983
6058
|
},
|
|
5984
6059
|
async onNavigation(tabId, generation) {
|
|
5985
|
-
await revoke((r) => r.tabId === tabId && r.generation !== generation);
|
|
6060
|
+
await revoke((r) => r.purpose !== "download" && r.tabId === tabId && r.generation !== generation);
|
|
5986
6061
|
},
|
|
5987
6062
|
async onTabClose(tabId) {
|
|
5988
6063
|
await revoke((r) => r.tabId === tabId);
|
|
@@ -6010,7 +6085,7 @@ async function createDataPlugin(access, options) {
|
|
|
6010
6085
|
await mkdir2(options.directory, { mode: 448 });
|
|
6011
6086
|
stopped = false;
|
|
6012
6087
|
sweep = setInterval(() => {
|
|
6013
|
-
|
|
6088
|
+
sweepExpired();
|
|
6014
6089
|
}, 1e4);
|
|
6015
6090
|
sweep.unref?.();
|
|
6016
6091
|
}
|
|
@@ -6282,7 +6357,7 @@ async function startProfile(root, server, profile, options, groupSignal) {
|
|
|
6282
6357
|
return;
|
|
6283
6358
|
} else if (cmd !== "status")
|
|
6284
6359
|
throw new Error("Invalid command");
|
|
6285
|
-
socket.end(JSON.stringify({ ...relay.health(), instanceId: session.instanceId, profile, version: "0.3.
|
|
6360
|
+
socket.end(JSON.stringify({ ...relay.health(), instanceId: session.instanceId, profile, version: "0.3.14", protocol: 3 }) + `
|
|
6286
6361
|
`);
|
|
6287
6362
|
})().catch(() => socket.destroy());
|
|
6288
6363
|
});
|
package/dist/main.js
CHANGED
|
@@ -8,7 +8,7 @@ var args = process.argv.slice(2);
|
|
|
8
8
|
var command = args.shift();
|
|
9
9
|
async function main() {
|
|
10
10
|
if (!command || command === "--help" || command === "help") {
|
|
11
|
-
console.log(`@ricsam/browser-mcp 0.3.
|
|
11
|
+
console.log(`@ricsam/browser-mcp 0.3.14
|
|
12
12
|
Usage: browser-mcp browser start|status|pause|resume|stop|recover [options]
|
|
13
13
|
browser-mcp files upload|download [options]
|
|
14
14
|
browser-mcp secrets export|exec [options]
|
|
@@ -18,15 +18,15 @@ Browser dependencies load only for browser commands. No automatic Chrome downloa
|
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
if (command === "--version") {
|
|
21
|
-
console.log("0.3.
|
|
21
|
+
console.log("0.3.14");
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
if (command === "browser")
|
|
25
|
-
return (await import("./chunk-
|
|
25
|
+
return (await import("./chunk-y9x8c0rq.js")).runBrowser(args);
|
|
26
26
|
if (command === "files")
|
|
27
|
-
return (await import("./chunk-
|
|
27
|
+
return (await import("./chunk-zv1900tw.js")).runFilesCommand(args);
|
|
28
28
|
if (command === "secrets")
|
|
29
|
-
return (await import("./chunk-
|
|
29
|
+
return (await import("./chunk-g3yyvtve.js")).runSecretsCommand(args);
|
|
30
30
|
if (command === "forward")
|
|
31
31
|
return (await import("./chunk-swy0qtx0.js")).runForward(args);
|
|
32
32
|
throw new Error("Unknown command. Use --help.");
|