@ricsam/browser-mcp 0.3.26 → 0.3.27
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/{chunk-swy0qtx0.js → chunk-0w5sk2a1.js} +1 -2
- package/dist/{chunk-51fbjjza.js → chunk-b0h4gxtq.js} +691 -692
- package/dist/chunk-gm2wyb5f.js +6 -0
- package/dist/{chunk-cy1a8r79.js → chunk-j8pdx3wj.js} +4 -6
- package/dist/chunk-qvxqggcd.js +7 -0
- package/dist/{chunk-zv1900tw.js → chunk-r2g1qf64.js} +4 -7
- package/dist/{chunk-g3yyvtve.js → chunk-v77jfzyx.js} +6 -9
- package/dist/main.js +5 -8
- package/package.json +1 -1
- package/dist/chunk-1sjcwr28.js +0 -4
- package/dist/chunk-42sbfmcv.js +0 -7
- package/dist/chunk-6st21tsd.js +0 -7
- /package/dist/{chunk-v483gpt7.js → chunk-6e06hyfa.js} +0 -0
- /package/dist/{chunk-j6psfksr.js → chunk-sxdnmsez.js} +0 -0
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
CLI_VERSION2
|
|
3
|
+
} from "./chunk-qvxqggcd.js";
|
|
4
4
|
import {
|
|
5
5
|
LIMITS,
|
|
6
6
|
sameScope,
|
|
7
|
-
secureDataUrl,
|
|
8
|
-
serializeSecrets,
|
|
9
7
|
validName,
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
secureDataUrl,
|
|
9
|
+
validateGrant,
|
|
10
|
+
serializeSecrets
|
|
11
|
+
} from "./chunk-sxdnmsez.js";
|
|
12
12
|
import {
|
|
13
13
|
FORWARD,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import"./chunk-1sjcwr28.js";
|
|
14
|
+
sameScope2,
|
|
15
|
+
connectForward
|
|
16
|
+
} from "./chunk-j8pdx3wj.js";
|
|
18
17
|
|
|
19
18
|
// cli/src/browser/main.ts
|
|
20
19
|
import fs13 from "node:fs/promises";
|
|
@@ -260,16 +259,16 @@ async function writeChromeIncident(root, record) {
|
|
|
260
259
|
} catch (error) {
|
|
261
260
|
if (error.code !== "EEXIST")
|
|
262
261
|
throw error;
|
|
263
|
-
const stat = await lstat(lock).catch((
|
|
264
|
-
if (
|
|
265
|
-
throw
|
|
262
|
+
const stat = await lstat(lock).catch((error) => {
|
|
263
|
+
if (error.code !== "ENOENT")
|
|
264
|
+
throw error;
|
|
266
265
|
return null;
|
|
267
266
|
});
|
|
268
267
|
if (!stat)
|
|
269
268
|
continue;
|
|
270
269
|
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.() || (stat.mode & 511) !== 448)
|
|
271
270
|
fail();
|
|
272
|
-
await new Promise((
|
|
271
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
273
272
|
}
|
|
274
273
|
}
|
|
275
274
|
if (!acquired)
|
|
@@ -346,8 +345,8 @@ class ChromeLifecycle {
|
|
|
346
345
|
reporting;
|
|
347
346
|
constructor(identity) {
|
|
348
347
|
this.identity = identity;
|
|
349
|
-
this.ended = new Promise((
|
|
350
|
-
this.wake =
|
|
348
|
+
this.ended = new Promise((resolve) => {
|
|
349
|
+
this.wake = resolve;
|
|
351
350
|
});
|
|
352
351
|
}
|
|
353
352
|
setStage(stage) {
|
|
@@ -420,7 +419,7 @@ class ChromeLifecycle {
|
|
|
420
419
|
profile: this.identity.profile,
|
|
421
420
|
instanceId: this.identity.instanceId,
|
|
422
421
|
pid: this.pid,
|
|
423
|
-
cliVersion:
|
|
422
|
+
cliVersion: CLI_VERSION2,
|
|
424
423
|
chromeVersion: this.chromeVersion,
|
|
425
424
|
outcome,
|
|
426
425
|
reason,
|
|
@@ -508,8 +507,8 @@ class DownloadGuard {
|
|
|
508
507
|
return;
|
|
509
508
|
}
|
|
510
509
|
let settle;
|
|
511
|
-
const settled = new Promise((
|
|
512
|
-
settle =
|
|
510
|
+
const settled = new Promise((resolve) => {
|
|
511
|
+
settle = resolve;
|
|
513
512
|
});
|
|
514
513
|
const entry = { guid, key: key(url, suggestedFilename), url, suggestedFilename, state: "inProgress", received: 0, settled, settle, claimed: this.earlyClaims.delete(guid), adopted: false, deferrals: 0 };
|
|
515
514
|
this.entries.set(guid, entry);
|
|
@@ -740,16 +739,16 @@ async function openBackgroundTab(context, newWindow, timeoutMs = 1e4, createTarg
|
|
|
740
739
|
const sessions = new Set;
|
|
741
740
|
let stopped = false;
|
|
742
741
|
const bounded = async (operation) => {
|
|
743
|
-
let
|
|
742
|
+
let timer;
|
|
744
743
|
try {
|
|
745
744
|
return await Promise.race([
|
|
746
745
|
operation,
|
|
747
746
|
new Promise((_, reject) => {
|
|
748
|
-
|
|
747
|
+
timer = setTimeout(() => reject(new Error("open_tab timed out identifying its created target. Inspect tabs before retrying.")), Math.max(0, deadline - Date.now()));
|
|
749
748
|
})
|
|
750
749
|
]);
|
|
751
750
|
} finally {
|
|
752
|
-
clearTimeout(
|
|
751
|
+
clearTimeout(timer);
|
|
753
752
|
}
|
|
754
753
|
};
|
|
755
754
|
const attach = async (page) => {
|
|
@@ -772,8 +771,8 @@ async function openBackgroundTab(context, newWindow, timeoutMs = 1e4, createTarg
|
|
|
772
771
|
let targetId;
|
|
773
772
|
const candidates = new Map;
|
|
774
773
|
let resolvePage, rejectPage;
|
|
775
|
-
const found = new Promise((
|
|
776
|
-
resolvePage =
|
|
774
|
+
const found = new Promise((resolve, reject) => {
|
|
775
|
+
resolvePage = resolve;
|
|
777
776
|
rejectPage = reject;
|
|
778
777
|
});
|
|
779
778
|
found.catch(() => {
|
|
@@ -859,26 +858,26 @@ var STARTUP_MS = 30000;
|
|
|
859
858
|
var CLOSE_MS = 2000;
|
|
860
859
|
var GRACEFUL_EXIT_MS = 30000;
|
|
861
860
|
async function allocateChromePort() {
|
|
862
|
-
return new Promise((
|
|
861
|
+
return new Promise((resolve, reject) => {
|
|
863
862
|
const server = net.createServer();
|
|
864
|
-
const
|
|
863
|
+
const timer = setTimeout(() => {
|
|
865
864
|
server.close();
|
|
866
865
|
reject(new Error("Chrome port allocation timed out"));
|
|
867
866
|
}, STARTUP_MS);
|
|
868
867
|
server.once("error", (error) => {
|
|
869
|
-
clearTimeout(
|
|
868
|
+
clearTimeout(timer);
|
|
870
869
|
reject(error);
|
|
871
870
|
});
|
|
872
871
|
server.listen(0, "127.0.0.1", () => {
|
|
873
872
|
const address = server.address();
|
|
874
873
|
server.close((error) => {
|
|
875
|
-
clearTimeout(
|
|
874
|
+
clearTimeout(timer);
|
|
876
875
|
if (error)
|
|
877
876
|
reject(error);
|
|
878
877
|
else if (!address || typeof address === "string" || !address.port)
|
|
879
878
|
reject(new Error("Invalid Chrome port allocation"));
|
|
880
879
|
else
|
|
881
|
-
|
|
880
|
+
resolve(address.port);
|
|
882
881
|
});
|
|
883
882
|
});
|
|
884
883
|
});
|
|
@@ -905,13 +904,13 @@ function chromeEndpointFromLine(line, port) {
|
|
|
905
904
|
return match && Number(match[2]) === port ? match[1] : undefined;
|
|
906
905
|
}
|
|
907
906
|
async function bounded(promise, ms) {
|
|
908
|
-
let
|
|
907
|
+
let timer;
|
|
909
908
|
try {
|
|
910
909
|
return await Promise.race([promise, new Promise((_, reject) => {
|
|
911
|
-
|
|
910
|
+
timer = setTimeout(() => reject(new Error("Owned Chrome operation timed out")), ms);
|
|
912
911
|
})]);
|
|
913
912
|
} finally {
|
|
914
|
-
clearTimeout(
|
|
913
|
+
clearTimeout(timer);
|
|
915
914
|
}
|
|
916
915
|
}
|
|
917
916
|
async function launchOwnedChrome(options) {
|
|
@@ -941,8 +940,8 @@ async function launchOwnedChrome(options) {
|
|
|
941
940
|
let downloads;
|
|
942
941
|
let closing = false;
|
|
943
942
|
let resolveExit;
|
|
944
|
-
const exit = new Promise((
|
|
945
|
-
resolveExit =
|
|
943
|
+
const exit = new Promise((resolve) => {
|
|
944
|
+
resolveExit = resolve;
|
|
946
945
|
});
|
|
947
946
|
let rejectStartup;
|
|
948
947
|
const failed = new Promise((_, reject) => {
|
|
@@ -962,7 +961,7 @@ async function launchOwnedChrome(options) {
|
|
|
962
961
|
}
|
|
963
962
|
rejectStartup(new Error("Could not start owned Chrome process"));
|
|
964
963
|
});
|
|
965
|
-
const streamsClosed = new Promise((
|
|
964
|
+
const streamsClosed = new Promise((resolve) => child.once("close", () => resolve()));
|
|
966
965
|
failed.catch(() => {});
|
|
967
966
|
const alive = () => !exited && child.exitCode === null && child.signalCode === null && !!child.pid;
|
|
968
967
|
const signalChild = (signal) => {
|
|
@@ -1015,8 +1014,8 @@ async function launchOwnedChrome(options) {
|
|
|
1015
1014
|
});
|
|
1016
1015
|
let lineBuffer = "", droppingLine = false, endpointPending = true;
|
|
1017
1016
|
let resolveEndpoint;
|
|
1018
|
-
const endpoint = new Promise((
|
|
1019
|
-
resolveEndpoint =
|
|
1017
|
+
const endpoint = new Promise((resolve) => {
|
|
1018
|
+
resolveEndpoint = resolve;
|
|
1020
1019
|
});
|
|
1021
1020
|
const onData = (chunk) => {
|
|
1022
1021
|
lifecycle.diagnostics.push(chunk);
|
|
@@ -1109,7 +1108,7 @@ async function launchOwnedChrome(options) {
|
|
|
1109
1108
|
await stage(context.addInitScript("if (navigator.serviceWorker) navigator.serviceWorker.register = async () => { console.warn('Service Worker registration blocked by Playwright'); };"));
|
|
1110
1109
|
lifecycle.setStage("webdriver");
|
|
1111
1110
|
failureReason = "missing-blank-page";
|
|
1112
|
-
const page = options.background ? await stage(openBackgroundTab(context, true, Math.max(1, deadline - Date.now()), () => createMinimizedWindow(context))) : context.pages().find((
|
|
1111
|
+
const page = options.background ? await stage(openBackgroundTab(context, true, Math.max(1, deadline - Date.now()), () => createMinimizedWindow(context))) : context.pages().find((page) => page.url() === "about:blank");
|
|
1113
1112
|
if (!page)
|
|
1114
1113
|
throw new Error("Owned Chrome did not open the initial blank page");
|
|
1115
1114
|
const chromeOpenedTabs = context.pages().filter((other) => other !== page).length;
|
|
@@ -1255,11 +1254,11 @@ async function assertProfileStopped(profile) {
|
|
|
1255
1254
|
}
|
|
1256
1255
|
async function refusedSocket(file) {
|
|
1257
1256
|
assertControlSocketPath(file);
|
|
1258
|
-
await new Promise((
|
|
1257
|
+
await new Promise((resolve, reject) => {
|
|
1259
1258
|
const socket = net2.createConnection(file);
|
|
1260
1259
|
const finish = (error) => {
|
|
1261
1260
|
socket.destroy();
|
|
1262
|
-
error ? reject(error) :
|
|
1261
|
+
error ? reject(error) : resolve();
|
|
1263
1262
|
};
|
|
1264
1263
|
socket.setTimeout(1000, () => finish(new Error(`Recovery refused: socket probe timed out: ${file}`)));
|
|
1265
1264
|
socket.once("connect", () => finish(new Error(`Recovery refused: live control listener: ${file}`)));
|
|
@@ -1394,8 +1393,8 @@ async function privateDirectory2(directory) {
|
|
|
1394
1393
|
if (e.code !== "EEXIST")
|
|
1395
1394
|
throw e;
|
|
1396
1395
|
}
|
|
1397
|
-
const
|
|
1398
|
-
if (
|
|
1396
|
+
const stat = await fs4.lstat(cursor);
|
|
1397
|
+
if (stat.isSymbolicLink() || !stat.isDirectory())
|
|
1399
1398
|
throw new Error("Unsafe directory path");
|
|
1400
1399
|
}
|
|
1401
1400
|
const stat = await fs4.stat(absolute);
|
|
@@ -1566,7 +1565,7 @@ async function listenControl(server, root, controlPath) {
|
|
|
1566
1565
|
const close = onceAsync(() => cleanupSteps([
|
|
1567
1566
|
["Control listener", async () => {
|
|
1568
1567
|
if (server.listening)
|
|
1569
|
-
await new Promise((
|
|
1568
|
+
await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
|
|
1570
1569
|
}],
|
|
1571
1570
|
["Control pathname", async () => {
|
|
1572
1571
|
if (!published)
|
|
@@ -1595,9 +1594,9 @@ async function listenControl(server, root, controlPath) {
|
|
|
1595
1594
|
try {
|
|
1596
1595
|
await fs5.writeFile(path6.join(directory, "ownership.json"), JSON.stringify({ pid: process.pid, controlPath, ownedPaths: [directory, boundPath] }), { mode: 384, flag: "wx" });
|
|
1597
1596
|
assertControlSocketPath(boundPath);
|
|
1598
|
-
await new Promise((
|
|
1597
|
+
await new Promise((resolve, reject) => {
|
|
1599
1598
|
server.once("error", reject);
|
|
1600
|
-
server.listen(boundPath,
|
|
1599
|
+
server.listen(boundPath, resolve);
|
|
1601
1600
|
});
|
|
1602
1601
|
socketStat = await fs5.lstat(boundPath);
|
|
1603
1602
|
await fs5.chmod(boundPath, 384);
|
|
@@ -1712,9 +1711,9 @@ class RuntimeFault extends Error {
|
|
|
1712
1711
|
beforeDispatch;
|
|
1713
1712
|
details;
|
|
1714
1713
|
definite;
|
|
1715
|
-
constructor(
|
|
1716
|
-
super(
|
|
1717
|
-
this.code =
|
|
1714
|
+
constructor(code, recovery, beforeDispatch = false, details, definite = false) {
|
|
1715
|
+
super(code);
|
|
1716
|
+
this.code = code;
|
|
1718
1717
|
this.recovery = recovery;
|
|
1719
1718
|
this.beforeDispatch = beforeDispatch;
|
|
1720
1719
|
this.details = details;
|
|
@@ -1799,7 +1798,7 @@ var messages = {
|
|
|
1799
1798
|
http_auth_username_unsupported: "The username contains a colon, which HTTP Basic authentication cannot send. Nothing was sent to the site.",
|
|
1800
1799
|
http_auth_answer_pending: "This HTTP sign-in is being answered already. Nothing more was sent to the site."
|
|
1801
1800
|
};
|
|
1802
|
-
var faultMessage = (
|
|
1801
|
+
var faultMessage = (code) => messages[code] ?? "Runtime operation rejected.";
|
|
1803
1802
|
var READ_SCRIPT_RECOVERY = "Review the submitted script and the exception details (untrusted page data). The script was declared intent read, so its failure is reported like an observation's: correct it and run it again. If it did change the page after all, observe the page before repeating it.";
|
|
1804
1803
|
function failureClass(text) {
|
|
1805
1804
|
return /Target crashed|Page crashed/i.test(text) ? "tab_crashed" : /no longer open|Target page, context or browser has been closed|Target closed|Frame was detached/i.test(text) ? "tab_closed" : /Runtime disconnected|Browser closed|browser has been closed|Connection closed/i.test(text) ? "runtime_disconnected" : /Execution context was destroyed|destroying its JavaScript context|Cannot find context with specified id/i.test(text) ? "context_destroyed" : /Timeout|timed out|time out/i.test(text) ? "execution_timeout" : /Protocol error.*(?:not supported|not allowed|wasn't found|Method not found)|Printing is not available|not available in an isolated browser context/i.test(text) ? "browser_operation_unsupported" : undefined;
|
|
@@ -1815,32 +1814,32 @@ var NOT_DISPATCHED_RECOVERY = {
|
|
|
1815
1814
|
function notDispatchedFault(error) {
|
|
1816
1815
|
if (error instanceof RuntimeFault)
|
|
1817
1816
|
return error.beforeDispatch ? error : new RuntimeFault(error.code, error.recovery, true, error.details, error.definite);
|
|
1818
|
-
const
|
|
1819
|
-
return new RuntimeFault(
|
|
1817
|
+
const code = failureClass(error instanceof Error ? error.message : "") ?? "runtime_operation_failed";
|
|
1818
|
+
return new RuntimeFault(code, NOT_DISPATCHED_RECOVERY[code] ?? NOT_DISPATCHED_RECOVERY.runtime_operation_failed, true);
|
|
1820
1819
|
}
|
|
1821
1820
|
var OPENED_TAB_RECOVERY = "The tab was opened and is result.tab; only its first navigation failed, and whether it reached the site is unknown. Look at the tab (browser_screenshot, or its url and crashed in browser_list_tabs) before deciding: navigate it again with browser_navigate, or close it with browser_close_tab. Do not open another tab for the same address without checking.";
|
|
1822
1821
|
function openedTabFault(error, tab) {
|
|
1823
|
-
const
|
|
1824
|
-
return new RuntimeFault(
|
|
1822
|
+
const code = error instanceof RuntimeFault ? error.code : failureClass(error instanceof Error ? error.message : "") ?? "runtime_operation_failed";
|
|
1823
|
+
return new RuntimeFault(code, OPENED_TAB_RECOVERY, false, { ...error instanceof RuntimeFault ? error.details : {}, tab });
|
|
1825
1824
|
}
|
|
1826
1825
|
function failureFor(error, op, operationId, stage, timing, dispatched = true, observation = OBSERVATION_OPERATIONS.has(op)) {
|
|
1827
1826
|
if (!dispatched)
|
|
1828
1827
|
error = notDispatchedFault(error);
|
|
1829
1828
|
const text = error instanceof Error ? error.message : "";
|
|
1830
|
-
let
|
|
1831
|
-
if (op === "screenshot" &&
|
|
1829
|
+
let code = error instanceof RuntimeFault ? error.code : failureClass(text) ?? (stage === "transfer" ? "transfer_failed" : op === "run_js" ? "script_exception" : /download|upload|transfer|resource|grant/i.test(op) ? "transfer_failed" : "runtime_operation_failed");
|
|
1830
|
+
if (op === "screenshot" && code === "execution_timeout") {
|
|
1832
1831
|
if (stage === "screenshot_capture")
|
|
1833
|
-
|
|
1832
|
+
code = "screenshot_capture_timeout";
|
|
1834
1833
|
if (stage === "screenshot_upload")
|
|
1835
|
-
|
|
1834
|
+
code = "screenshot_upload_timeout";
|
|
1836
1835
|
}
|
|
1837
|
-
if (op === "screenshot" && stage === "screenshot_upload" &&
|
|
1838
|
-
|
|
1836
|
+
if (op === "screenshot" && stage === "screenshot_upload" && code === "runtime_operation_failed")
|
|
1837
|
+
code = "transfer_failed";
|
|
1839
1838
|
const outcome = error instanceof RuntimeFault && error.beforeDispatch ? "not_dispatched" : observation || error instanceof RuntimeFault && error.definite ? "failed" : "unknown";
|
|
1840
|
-
const recovery = error instanceof RuntimeFault ? error.recovery :
|
|
1839
|
+
const recovery = error instanceof RuntimeFault ? error.recovery : code === "tab_crashed" ? "The tab crashed during this operation, which was not retried; an action may have taken effect before the crash. browser_list_tabs marks the tab crashed and says what still works in it. To continue, open the page in a new tab with browser_open_tab; do not repeat an action that may have caused the crash as it was." : op === "screenshot" ? "Call browser_runtime_health. A settled screenshot failure can leave admission ready; health does not probe Chrome capture. The stage identifies geometry (including a bounded web-font wait), capture (Chrome render/encode work), encoding or upload, not a specific Chrome cause. No screenshot was delivered and no automatic retry occurred. Inspect the target before deciding on a fresh screenshot; never replay a prior mutation or recover without approval." : code === "runtime_disconnected" ? "Reconnect the runtime, then call browser_runtime_health. Do not repeat an uncertain mutation." : code === "tab_closed" ? "Use browser_list_tabs to select an existing tab. Do not replay the prior mutation." : code === "execution_timeout" ? "Call browser_runtime_health to distinguish a settled wait from quarantined execution. A timeout does not cancel page effects." : code === "transfer_failed" ? "Inspect browser_transfer_status and browser_list_downloads. Reissue a grant only for retained bytes; do not repeat a website action." : code === "browser_operation_unsupported" ? "Use browser_capabilities for interface prerequisites. Other operations, including navigation away, may still work. For original document bytes use an available website/viewer download control, browser_list_downloads and browser_create_download. Do not replay an uncertain mutation." : code === "script_exception" ? observation ? READ_SCRIPT_RECOVERY : "Review the submitted script locally. Effects before the exception may have occurred; do not replay automatically." : "Call browser_runtime_health, then browser_capabilities for a supported target. Do not repeat an uncertain mutation.";
|
|
1841
1840
|
const diagnosticId = randomUUID4();
|
|
1842
|
-
console.error(JSON.stringify({ event: "runtime_failure", diagnosticId, operationId, operation: op, stage, code
|
|
1843
|
-
return { error: { code
|
|
1841
|
+
console.error(JSON.stringify({ event: "runtime_failure", diagnosticId, operationId, operation: op, stage, code, outcome, ...timing }));
|
|
1842
|
+
return { error: { code, message: messages[code] ?? "Runtime operation rejected." }, outcome, result: { diagnosticId, operationId, category: code, stage, ...timing, ...error instanceof RuntimeFault ? error.details : undefined, recovery, retrySafe: outcome !== "unknown", executionState: outcome === "not_dispatched" ? "not_started" : "settled", cancellationConfirmed: false } };
|
|
1844
1843
|
}
|
|
1845
1844
|
|
|
1846
1845
|
// cli/src/browser/screenshot-coordinates.ts
|
|
@@ -1896,7 +1895,7 @@ var TARGET_ACTIONS = new Set(["mouse_click", "hover", "form_input", "scroll", "e
|
|
|
1896
1895
|
var SCREENSHOT_DELIVERIES = ["image", "file", "both"];
|
|
1897
1896
|
var screenshotDelivery = (input) => input.deliver === "file" || input.deliver === "both" ? input.deliver : "image";
|
|
1898
1897
|
function screenshotInputProblem(input) {
|
|
1899
|
-
const targets = ["ref", "selector", "crop"].filter((
|
|
1898
|
+
const targets = ["ref", "selector", "crop"].filter((key) => input[key] !== undefined);
|
|
1900
1899
|
if (input.fullPage === true)
|
|
1901
1900
|
targets.push("fullPage");
|
|
1902
1901
|
if (targets.length > 1)
|
|
@@ -1953,7 +1952,7 @@ function parseUploadTarget(input) {
|
|
|
1953
1952
|
throw new Error("File input selector must be a non-empty string.");
|
|
1954
1953
|
return { selector };
|
|
1955
1954
|
}
|
|
1956
|
-
var refuse = (
|
|
1955
|
+
var refuse = (code, recovery, details) => new RuntimeFault(code, recovery, true, details, true);
|
|
1957
1956
|
var uploadRefusal = {
|
|
1958
1957
|
notFound: () => refuse("file_input_not_found", "Read the page again with browser_read_page (a ref is valid only for the page it was read from), then pass the file input's current ref, a selector that matches it, or the chooserId of an open file chooser. Nothing was attached."),
|
|
1959
1958
|
ambiguous: (matchCount) => refuse("file_input_ambiguous", "Pass a selector that matches only the intended file input, or its ref from browser_read_page. Nothing was attached.", { matchCount }),
|
|
@@ -1975,15 +1974,15 @@ function target(value, field) {
|
|
|
1975
1974
|
throw new Error(`${field} must be a locator object.`);
|
|
1976
1975
|
const result = Object.fromEntries(Object.entries(value).filter(([, v]) => v !== null));
|
|
1977
1976
|
const keys = ["ref", "selector", "role", "name", "text", "label", "placeholder", "testId"];
|
|
1978
|
-
for (const [
|
|
1979
|
-
if (
|
|
1977
|
+
for (const [key, item] of Object.entries(result)) {
|
|
1978
|
+
if (key === "exact") {
|
|
1980
1979
|
if (typeof item !== "boolean")
|
|
1981
1980
|
throw new Error(`${field}.exact must be a boolean.`);
|
|
1982
|
-
} else if (!keys.includes(
|
|
1981
|
+
} else if (!keys.includes(key) || typeof item !== "string" || !item.trim() || item.length > 2000) {
|
|
1983
1982
|
throw new Error(`${field} contains an invalid locator field.`);
|
|
1984
1983
|
}
|
|
1985
1984
|
}
|
|
1986
|
-
const strategies = keys.filter((
|
|
1985
|
+
const strategies = keys.filter((key) => result[key] !== undefined && !(key === "name" && result.role));
|
|
1987
1986
|
if (strategies.length !== 1)
|
|
1988
1987
|
throw new Error(`${field} requires one of ref, selector, role (with optional name), name, text, label, placeholder or testId.`);
|
|
1989
1988
|
if (result.ref && !REF_PATTERN.test(result.ref))
|
|
@@ -2001,10 +2000,10 @@ function parseActionTarget(value) {
|
|
|
2001
2000
|
return result;
|
|
2002
2001
|
}
|
|
2003
2002
|
function parseSnapshotInput(input) {
|
|
2004
|
-
const integer = (
|
|
2005
|
-
const value = input[
|
|
2003
|
+
const integer = (key, fallback, min, max) => {
|
|
2004
|
+
const value = input[key] ?? fallback;
|
|
2006
2005
|
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max)
|
|
2007
|
-
throw new Error(`read_page ${
|
|
2006
|
+
throw new Error(`read_page ${key} must be an integer from ${min} to ${max}.`);
|
|
2008
2007
|
return value;
|
|
2009
2008
|
};
|
|
2010
2009
|
const scope = target(input.scope, "scope"), query = target(input.query, "query");
|
|
@@ -2022,9 +2021,9 @@ function parseSnapshotInput(input) {
|
|
|
2022
2021
|
throw new Error("read_page snapshotId must be the hash returned by the previous search.");
|
|
2023
2022
|
if (offset > 0 && !input.snapshotId)
|
|
2024
2023
|
throw new Error("Continuing a search requires its snapshotId, so changed pages cannot silently skip matches.");
|
|
2025
|
-
for (const
|
|
2026
|
-
if (input[
|
|
2027
|
-
throw new Error(`read_page ${
|
|
2024
|
+
for (const key of ["interactive", "boxes"])
|
|
2025
|
+
if (input[key] != null && typeof input[key] !== "boolean")
|
|
2026
|
+
throw new Error(`read_page ${key} must be a boolean.`);
|
|
2028
2027
|
if (input.filter != null && input.filter !== "interactive" && input.filter !== "all")
|
|
2029
2028
|
throw new Error('read_page filter must be "interactive" (the same as interactive: true) or "all".');
|
|
2030
2029
|
if (input.filter != null && input.interactive != null && input.filter === "interactive" !== input.interactive)
|
|
@@ -2045,11 +2044,11 @@ function parseSnapshotInput(input) {
|
|
|
2045
2044
|
boxes: input.boxes === true
|
|
2046
2045
|
};
|
|
2047
2046
|
}
|
|
2048
|
-
function snapshotSelector(page,
|
|
2049
|
-
if (!
|
|
2047
|
+
function snapshotSelector(page, target, includeHidden = false) {
|
|
2048
|
+
if (!target)
|
|
2050
2049
|
return;
|
|
2051
|
-
const exact =
|
|
2052
|
-
const locator =
|
|
2050
|
+
const exact = target.exact ?? true;
|
|
2051
|
+
const locator = target.ref ? page.locator(refSelector(target.ref)) : target.selector ? page.locator(target.selector) : target.role ? page.getByRole(target.role, { name: target.name, exact, includeHidden }) : target.text ? page.getByText(target.text, { exact }) : target.label ? page.getByLabel(target.label, { exact }) : target.placeholder ? page.getByPlaceholder(target.placeholder, { exact }) : target.testId ? page.getByTestId(target.testId) : page.locator("*");
|
|
2053
2052
|
const selector = locator._selector;
|
|
2054
2053
|
if (typeof selector !== "string")
|
|
2055
2054
|
throw new Error("Snapshot locator API unavailable; update r5d-browser.");
|
|
@@ -2090,7 +2089,7 @@ function waitTimeout(value, fallback) {
|
|
|
2090
2089
|
}
|
|
2091
2090
|
var CONDITIONS = ["target", "text", "textGone", "url", "loadState", "networkQuietMs", "time"];
|
|
2092
2091
|
function parseWaitInput(input) {
|
|
2093
|
-
const conditions = CONDITIONS.filter((
|
|
2092
|
+
const conditions = CONDITIONS.filter((key) => input[key] != null);
|
|
2094
2093
|
if (conditions.length !== 1)
|
|
2095
2094
|
throw new Error("wait_for requires exactly one of text, textGone, target, url, loadState, networkQuietMs or time.");
|
|
2096
2095
|
if (input.selector != null || input.ref != null)
|
|
@@ -2109,8 +2108,8 @@ function parseWaitInput(input) {
|
|
|
2109
2108
|
} else if (input.exact != null)
|
|
2110
2109
|
throw new Error("exact goes with text or textGone.");
|
|
2111
2110
|
const locator = parseSnapshotInput({ scope: input.scope, query, frames: input.frames });
|
|
2112
|
-
for (const
|
|
2113
|
-
if (
|
|
2111
|
+
for (const target of [locator.scope, locator.query])
|
|
2112
|
+
if (target?.name && !target.role)
|
|
2114
2113
|
throw new Error("Wait locators require role with name; use target.ref for a discovered element.");
|
|
2115
2114
|
if (locator.query?.ref && locator.frames.length)
|
|
2116
2115
|
throw new Error("A target ref already identifies its frame; omit frames.");
|
|
@@ -2160,7 +2159,7 @@ function parseNavigationExpectation(value) {
|
|
|
2160
2159
|
if (typeof value !== "object" || Array.isArray(value))
|
|
2161
2160
|
throw new Error("expectNavigation must be an object.");
|
|
2162
2161
|
const input = value;
|
|
2163
|
-
if (Object.keys(input).some((
|
|
2162
|
+
if (Object.keys(input).some((key) => !["url", "waitUntil", "timeoutMs"].includes(key)))
|
|
2164
2163
|
throw new Error("Unknown expectNavigation field.");
|
|
2165
2164
|
if (input.url != null && (typeof input.url !== "string" || !input.url.trim() || input.url.length > 4000))
|
|
2166
2165
|
throw new Error("expectNavigation url must be a nonempty URL glob.");
|
|
@@ -2182,7 +2181,7 @@ var MAX_HTTP_AUTH_PASSWORD = 512;
|
|
|
2182
2181
|
var HTTP_AUTH_ARGUMENTS = ["vaultId", "names", "expectedOrigin"];
|
|
2183
2182
|
var VAULT_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
2184
2183
|
function signsInWithVault(input) {
|
|
2185
|
-
return !!input && HTTP_AUTH_ARGUMENTS.some((
|
|
2184
|
+
return !!input && HTTP_AUTH_ARGUMENTS.some((key) => input[key] !== undefined && input[key] !== null);
|
|
2186
2185
|
}
|
|
2187
2186
|
function exactOrigin(value) {
|
|
2188
2187
|
if (typeof value !== "string" || value.length > 255)
|
|
@@ -2197,7 +2196,7 @@ function exactOrigin(value) {
|
|
|
2197
2196
|
function httpAuthInputProblem(input) {
|
|
2198
2197
|
if (!signsInWithVault(input))
|
|
2199
2198
|
return;
|
|
2200
|
-
const missing = HTTP_AUTH_ARGUMENTS.filter((
|
|
2199
|
+
const missing = HTTP_AUTH_ARGUMENTS.filter((key) => input[key] === undefined || input[key] === null);
|
|
2201
2200
|
if (missing.length)
|
|
2202
2201
|
return `An HTTP sign-in takes vaultId, names and expectedOrigin together: ${missing.join(" and ")} ${missing.length === 1 ? "is" : "are"} missing.`;
|
|
2203
2202
|
if (input.decision !== "accept")
|
|
@@ -2207,12 +2206,12 @@ function httpAuthInputProblem(input) {
|
|
|
2207
2206
|
if (typeof input.vaultId !== "string" || !input.vaultId.trim() || input.vaultId.length > 128)
|
|
2208
2207
|
return "vaultId must be the vaultId of a local secret vault, from browser_capture_secrets or browser_list_secrets.";
|
|
2209
2208
|
const names = input.names;
|
|
2210
|
-
if (!names || typeof names !== "object" || Array.isArray(names) || Object.keys(names).some((
|
|
2209
|
+
if (!names || typeof names !== "object" || Array.isArray(names) || Object.keys(names).some((key) => key !== "username" && key !== "password"))
|
|
2211
2210
|
return 'names must be {"username": NAME, "password": NAME}: the names of the vault values that hold the username and the password, never the values.';
|
|
2212
|
-
for (const
|
|
2213
|
-
const name = names[
|
|
2211
|
+
for (const key of ["username", "password"]) {
|
|
2212
|
+
const name = names[key];
|
|
2214
2213
|
if (typeof name !== "string" || !VAULT_NAME.test(name))
|
|
2215
|
-
return `names.${
|
|
2214
|
+
return `names.${key} must be the name of a value in the vault, such as ${key === "username" ? "SITE_USERNAME" : "SITE_PASSWORD"}, never the value itself.`;
|
|
2216
2215
|
}
|
|
2217
2216
|
if (!exactOrigin(input.expectedOrigin))
|
|
2218
2217
|
return "expectedOrigin must be the exact origin the user authorized these credentials for, such as https://example.com: scheme, host and port only.";
|
|
@@ -2306,8 +2305,8 @@ function validateControlInput(action, input) {
|
|
|
2306
2305
|
if (input.from !== undefined || input.to !== undefined)
|
|
2307
2306
|
throw new Error("drag takes refs or coordinates, not both.");
|
|
2308
2307
|
} else
|
|
2309
|
-
for (const
|
|
2310
|
-
const p = input[
|
|
2308
|
+
for (const key of ["from", "to"]) {
|
|
2309
|
+
const p = input[key];
|
|
2311
2310
|
if (!p || typeof p.x !== "number" || typeof p.y !== "number" || !Number.isFinite(p.x) || !Number.isFinite(p.y))
|
|
2312
2311
|
throw new Error("drag requires finite from/to x/y coordinates.");
|
|
2313
2312
|
}
|
|
@@ -2467,14 +2466,14 @@ function parseViewportInput(input) {
|
|
|
2467
2466
|
}
|
|
2468
2467
|
function normalizeBrowserInput(action, input) {
|
|
2469
2468
|
const fields = browserInputFields[action];
|
|
2470
|
-
for (const
|
|
2471
|
-
if (input[
|
|
2472
|
-
throw new Error(`${action} requires ${
|
|
2469
|
+
for (const key of fields.required) {
|
|
2470
|
+
if (input[key] === null || input[key] === undefined)
|
|
2471
|
+
throw new Error(`${action} requires ${key}.`);
|
|
2473
2472
|
}
|
|
2474
2473
|
const normalized = { ...input };
|
|
2475
|
-
for (const
|
|
2476
|
-
if (normalized[
|
|
2477
|
-
delete normalized[
|
|
2474
|
+
for (const key of [...fields.optional, "screenshotId", "screenshot", ...observedActions.has(action) ? ["observe", "expect"] : []]) {
|
|
2475
|
+
if (normalized[key] === null)
|
|
2476
|
+
delete normalized[key];
|
|
2478
2477
|
}
|
|
2479
2478
|
return normalized;
|
|
2480
2479
|
}
|
|
@@ -2493,7 +2492,7 @@ function preflightBrowserInput(action, raw) {
|
|
|
2493
2492
|
}
|
|
2494
2493
|
if (action === "screenshot" && input.crop !== undefined) {
|
|
2495
2494
|
const crop = input.crop;
|
|
2496
|
-
if (!crop || !["x", "y", "width", "height"].every((
|
|
2495
|
+
if (!crop || !["x", "y", "width", "height"].every((key) => Number.isInteger(crop[key]) && crop[key] >= (key === "x" || key === "y" ? 0 : 1)) || input.fullPage === true)
|
|
2497
2496
|
throw new Error("crop requires nonnegative x/y and positive width/height in viewport CSS pixels; omit fullPage");
|
|
2498
2497
|
}
|
|
2499
2498
|
validateControlInput(action, input);
|
|
@@ -2505,7 +2504,7 @@ function preflightBrowserInput(action, raw) {
|
|
|
2505
2504
|
if (action === "batch")
|
|
2506
2505
|
for (const step of input.steps)
|
|
2507
2506
|
if (step.action === "sleep") {
|
|
2508
|
-
if (!Number.isInteger(step.input.ms) || step.input.ms < 1 || step.input.ms > 5000 || Object.keys(step.input).some((
|
|
2507
|
+
if (!Number.isInteger(step.input.ms) || step.input.ms < 1 || step.input.ms > 5000 || Object.keys(step.input).some((key) => key !== "ms"))
|
|
2509
2508
|
throw new Error("A sleep step takes only ms, an integer from 1 to 5000.");
|
|
2510
2509
|
} else
|
|
2511
2510
|
preflightBrowserInput(step.action, { ...step.input, tabId: input.tabId });
|
|
@@ -2555,7 +2554,7 @@ function preflightBrowserInput(action, raw) {
|
|
|
2555
2554
|
if (input.ref !== undefined || input.target !== undefined) {
|
|
2556
2555
|
if (input.ref !== undefined && input.target !== undefined)
|
|
2557
2556
|
throw new Error("scroll accepts ref or target, not both.");
|
|
2558
|
-
if (["direction", "amount", "x", "y"].some((
|
|
2557
|
+
if (["direction", "amount", "x", "y"].some((key) => input[key] !== undefined))
|
|
2559
2558
|
throw new Error("scroll accepts ref or target, or wheel/pointer parameters, not both.");
|
|
2560
2559
|
if (input.ref !== undefined)
|
|
2561
2560
|
ref();
|
|
@@ -2571,7 +2570,7 @@ function preflightBrowserInput(action, raw) {
|
|
|
2571
2570
|
if (action === "upload_files" || action === "upload_begin")
|
|
2572
2571
|
parseUploadTarget(input);
|
|
2573
2572
|
if (action === "form_input") {
|
|
2574
|
-
const provided = ["value", "values", "checked"].filter((
|
|
2573
|
+
const provided = ["value", "values", "checked"].filter((key) => input[key] !== undefined);
|
|
2575
2574
|
if (provided.length !== 1)
|
|
2576
2575
|
throw new Error("form_input requires exactly one of value, values, or checked.");
|
|
2577
2576
|
if (provided[0] === "values" && (!Array.isArray(input.values) || input.values.some((value) => typeof value !== "string")))
|
|
@@ -2595,24 +2594,24 @@ class BrowserUploadStore {
|
|
|
2595
2594
|
fs7.mkdirSync(root, { recursive: true, mode: 448 });
|
|
2596
2595
|
this.directory = fs7.mkdtempSync(path8.join(root, "run-"));
|
|
2597
2596
|
}
|
|
2598
|
-
begin(id, tabId, files,
|
|
2597
|
+
begin(id, tabId, files, target) {
|
|
2599
2598
|
if (typeof id !== "string" || !/^[a-f0-9-]{36}$/.test(id) || this.uploads.has(id))
|
|
2600
2599
|
throw new Error("Invalid or duplicate upload id.");
|
|
2601
2600
|
if (!Array.isArray(files) || files.length === 0 || files.length > 100)
|
|
2602
2601
|
throw new Error("Upload requires between 1 and 100 files.");
|
|
2603
|
-
const
|
|
2602
|
+
const metadata = files.map(validateUploadFile);
|
|
2604
2603
|
const directory = fs7.mkdtempSync(path8.join(this.directory, "upload-"));
|
|
2605
2604
|
try {
|
|
2606
|
-
const staged =
|
|
2605
|
+
const staged = metadata.map((file, index) => {
|
|
2607
2606
|
const parent = path8.join(directory, String(index));
|
|
2608
2607
|
fs7.mkdirSync(parent, { mode: 448 });
|
|
2609
2608
|
const filePath = path8.join(parent, file.filename);
|
|
2610
2609
|
fs7.closeSync(fs7.openSync(filePath, "wx", 384));
|
|
2611
2610
|
return { ...file, path: filePath, offset: 0, hash: createHash3("sha256") };
|
|
2612
2611
|
});
|
|
2613
|
-
const
|
|
2614
|
-
|
|
2615
|
-
this.uploads.set(id, { tabId, directory, files: staged, target
|
|
2612
|
+
const timer = setTimeout(() => this.abort(id, tabId), 5 * 60 * 1000);
|
|
2613
|
+
timer.unref();
|
|
2614
|
+
this.uploads.set(id, { tabId, directory, files: staged, target, attached: false, timer });
|
|
2616
2615
|
} catch (error) {
|
|
2617
2616
|
fs7.rmSync(directory, { recursive: true, force: true });
|
|
2618
2617
|
throw error;
|
|
@@ -2732,7 +2731,7 @@ function internalsOf(page) {
|
|
|
2732
2731
|
return;
|
|
2733
2732
|
}
|
|
2734
2733
|
}
|
|
2735
|
-
var sleep = (ms) => new Promise((
|
|
2734
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
2736
2735
|
var quietly = (work) => {
|
|
2737
2736
|
try {
|
|
2738
2737
|
work();
|
|
@@ -2816,8 +2815,8 @@ class RestoredFrames {
|
|
|
2816
2815
|
this.forget(targetId);
|
|
2817
2816
|
const held = { session, event, parentId, timers: [] };
|
|
2818
2817
|
held.timers.push(setTimeout(() => this.schedule(() => this.handOver(targetId)), ATTACH_HOLD_MS), setTimeout(() => this.drop(targetId), ATTACH_DROP_MS));
|
|
2819
|
-
for (const
|
|
2820
|
-
|
|
2818
|
+
for (const timer of held.timers)
|
|
2819
|
+
timer.unref?.();
|
|
2821
2820
|
this.held.set(targetId, held);
|
|
2822
2821
|
if (this.current())
|
|
2823
2822
|
this.schedule();
|
|
@@ -2835,8 +2834,8 @@ class RestoredFrames {
|
|
|
2835
2834
|
const held = this.held.get(targetId);
|
|
2836
2835
|
if (!held)
|
|
2837
2836
|
return;
|
|
2838
|
-
for (const
|
|
2839
|
-
clearTimeout(
|
|
2837
|
+
for (const timer of held.timers)
|
|
2838
|
+
clearTimeout(timer);
|
|
2840
2839
|
this.held.delete(targetId);
|
|
2841
2840
|
}
|
|
2842
2841
|
async handOver(targetId, restore) {
|
|
@@ -2885,9 +2884,9 @@ class RestoredFrames {
|
|
|
2885
2884
|
});
|
|
2886
2885
|
}
|
|
2887
2886
|
async settled(ms) {
|
|
2888
|
-
let
|
|
2889
|
-
await Promise.race([this.work, new Promise((
|
|
2890
|
-
clearTimeout(
|
|
2887
|
+
let timer;
|
|
2888
|
+
await Promise.race([this.work, new Promise((resolve) => timer = setTimeout(resolve, ms))]);
|
|
2889
|
+
clearTimeout(timer);
|
|
2891
2890
|
}
|
|
2892
2891
|
async reconcile() {
|
|
2893
2892
|
const restore = this.current();
|
|
@@ -3021,8 +3020,8 @@ function jsonStringLength(value, start) {
|
|
|
3021
3020
|
function snapshotLineParts(line) {
|
|
3022
3021
|
const value = line.trimStart().replace(/^- /, "");
|
|
3023
3022
|
if (value.startsWith("'")) {
|
|
3024
|
-
const
|
|
3025
|
-
return { ...snapshotLineParts(
|
|
3023
|
+
const key = /^'((?:[^']|'')*)'/.exec(value)?.[1]?.replaceAll("''", "'") ?? "";
|
|
3024
|
+
return { ...snapshotLineParts(key), key };
|
|
3026
3025
|
}
|
|
3027
3026
|
let index = /^[^\s:"[]*/.exec(value)[0].length;
|
|
3028
3027
|
const role = value.slice(0, index);
|
|
@@ -3039,28 +3038,28 @@ function snapshotLineParts(line) {
|
|
|
3039
3038
|
const attributes = [];
|
|
3040
3039
|
for (let match;match = /^ \[([^\]]*)\]/.exec(value.slice(index)); index += match[0].length)
|
|
3041
3040
|
attributes.push(match[1]);
|
|
3042
|
-
const
|
|
3041
|
+
const key = value.slice(0, index);
|
|
3043
3042
|
const rest = value.slice(index);
|
|
3044
3043
|
const text = rest.startsWith(": ") ? rest.slice(2) : undefined;
|
|
3045
3044
|
const ref = attributes.map((attribute) => REF.exec(attribute)?.[1]).find(Boolean);
|
|
3046
|
-
return { key
|
|
3045
|
+
return { key, role, ...name === undefined ? {} : { name }, attributes, ...ref ? { ref } : {}, ...text === undefined ? {} : { text } };
|
|
3047
3046
|
}
|
|
3048
3047
|
function snapshotLine(line) {
|
|
3049
|
-
const { key
|
|
3050
|
-
return { key
|
|
3048
|
+
const { key, ref, role } = snapshotLineParts(line);
|
|
3049
|
+
return { key, ref, role };
|
|
3051
3050
|
}
|
|
3052
3051
|
var BOX = / \[box=(-?\d+),(-?\d+),(-?\d+),(-?\d+)\]$/;
|
|
3053
3052
|
function moveLineBox(line, origin) {
|
|
3054
3053
|
const indent = line.length - line.trimStart().length;
|
|
3055
3054
|
if (!line.startsWith("- ", indent))
|
|
3056
3055
|
return line;
|
|
3057
|
-
const { key
|
|
3058
|
-
const box = BOX.exec(
|
|
3056
|
+
const { key } = snapshotLineParts(line);
|
|
3057
|
+
const box = BOX.exec(key);
|
|
3059
3058
|
if (!box)
|
|
3060
3059
|
return line;
|
|
3061
3060
|
const start = indent + 2 + box.index;
|
|
3062
3061
|
const moved = origin ? ` [box=${Math.round(Number(box[1]) + origin.x)},${Math.round(Number(box[2]) + origin.y)},${box[3]},${box[4]}]` : "";
|
|
3063
|
-
return line.slice(0, start) + moved + line.slice(indent + 2 +
|
|
3062
|
+
return line.slice(0, start) + moved + line.slice(indent + 2 + key.length);
|
|
3064
3063
|
}
|
|
3065
3064
|
|
|
3066
3065
|
// cli/src/browser/password-safe-snapshot.ts
|
|
@@ -3072,7 +3071,7 @@ var MAX_MATCH_DETAILS = 1000;
|
|
|
3072
3071
|
var PAGE = { x: 0, y: 0 };
|
|
3073
3072
|
var SCALE_TOLERANCE = 1.5;
|
|
3074
3073
|
var FRAME_ELEMENT_PROGRESS = { race: (promise) => Promise.race(Array.isArray(promise) ? promise : [promise]) };
|
|
3075
|
-
var finite = (value, keys) => !!value && typeof value === "object" && keys.every((
|
|
3074
|
+
var finite = (value, keys) => !!value && typeof value === "object" && keys.every((key) => Number.isFinite(value[key]));
|
|
3076
3075
|
var isGeometry = (value) => finite(value, ["x", "y", "width", "height"]) && finite(value.parentViewport, ["width", "height"]);
|
|
3077
3076
|
var drawnAtScale = (size, viewport) => size.width === undefined || size.height === undefined || Math.abs(viewport.width - size.width) <= SCALE_TOLERANCE && Math.abs(viewport.height - size.height) <= SCALE_TOLERANCE;
|
|
3078
3077
|
function iframeGeometryInUtilityWorld(context) {
|
|
@@ -3094,8 +3093,8 @@ function iframeGeometryInUtilityWorld(context) {
|
|
|
3094
3093
|
}
|
|
3095
3094
|
};
|
|
3096
3095
|
for (let node = iframe;node; node = node.assignedSlot ?? node.parentElement ?? (node.parentNode?.host ?? null)) {
|
|
3097
|
-
const
|
|
3098
|
-
if (!translation(
|
|
3096
|
+
const style = view.getComputedStyle(node);
|
|
3097
|
+
if (!translation(style.transform) || style.scale !== "none" || style.rotate !== "none" || style.translate.trim().split(/\s+/).length > 2 || (style.offsetPath || "none") !== "none")
|
|
3099
3098
|
return "transformed";
|
|
3100
3099
|
}
|
|
3101
3100
|
const box = iframe.getBoundingClientRect();
|
|
@@ -3165,12 +3164,12 @@ function captureInUtilityWorld({ elements, injected }, options) {
|
|
|
3165
3164
|
lastJson = result.json;
|
|
3166
3165
|
const rendered = injected._lastAriaSnapshotForQuery?.info;
|
|
3167
3166
|
const focusable = (ref) => {
|
|
3168
|
-
const
|
|
3169
|
-
if (!
|
|
3167
|
+
const target = rendered?.get(ref)?.element;
|
|
3168
|
+
if (!target)
|
|
3170
3169
|
return false;
|
|
3171
|
-
if (
|
|
3170
|
+
if (target.isContentEditable === true && target.hasAttribute("contenteditable"))
|
|
3172
3171
|
return true;
|
|
3173
|
-
return typeof
|
|
3172
|
+
return typeof target.tabIndex === "number" && target.tabIndex >= 0 && (target.hasAttribute("tabindex") || target.localName === "summary");
|
|
3174
3173
|
};
|
|
3175
3174
|
const lines = [];
|
|
3176
3175
|
const visit = (node, depth) => {
|
|
@@ -3183,9 +3182,9 @@ function captureInUtilityWorld({ elements, injected }, options) {
|
|
|
3183
3182
|
let line = `${indent}- ${role}`;
|
|
3184
3183
|
if (node.name)
|
|
3185
3184
|
line += ` ${JSON.stringify(node.name)}`;
|
|
3186
|
-
for (const
|
|
3187
|
-
if (node[
|
|
3188
|
-
line += ` [${
|
|
3185
|
+
for (const key of ["checked", "disabled", "expanded", "selected", "pressed", "level", "active"])
|
|
3186
|
+
if (node[key] !== undefined)
|
|
3187
|
+
line += ` [${key}=${JSON.stringify(node[key])}]`;
|
|
3189
3188
|
if (node.ref) {
|
|
3190
3189
|
line += ` [ref=${node.ref}]`;
|
|
3191
3190
|
if (!controlRoles.has(role)) {
|
|
@@ -3304,7 +3303,7 @@ function captureInUtilityWorld({ elements, injected }, options) {
|
|
|
3304
3303
|
if (!node || typeof node !== "object")
|
|
3305
3304
|
return;
|
|
3306
3305
|
if (typeof node.ref === "string")
|
|
3307
|
-
outlineStates.set(node.ref, Object.fromEntries(stateKeys.filter((
|
|
3306
|
+
outlineStates.set(node.ref, Object.fromEntries(stateKeys.filter((key) => node[key] !== undefined).map((key) => [key, node[key]])));
|
|
3308
3307
|
for (const child of node.children || [])
|
|
3309
3308
|
collect(child);
|
|
3310
3309
|
};
|
|
@@ -3455,12 +3454,12 @@ function serverMainFrame(page) {
|
|
|
3455
3454
|
var isGoneFrameRef = (error) => /Invalid frame in aria-ref selector/.test(error instanceof Error ? error.message : String(error));
|
|
3456
3455
|
var frameSeq = (frame) => typeof frame.seq === "number" && Number.isSafeInteger(frame.seq) ? frame.seq : undefined;
|
|
3457
3456
|
async function passwordSafeAriaSnapshot(page, options = {}) {
|
|
3458
|
-
const
|
|
3459
|
-
if (!Number.isFinite(
|
|
3457
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
3458
|
+
if (!Number.isFinite(timeout) || timeout <= 0)
|
|
3460
3459
|
throw new Error("Password-safe snapshots require a finite positive timeout.");
|
|
3461
3460
|
await settleRestoredFrames(page);
|
|
3462
3461
|
const frame = serverMainFrame(page);
|
|
3463
|
-
const deadline = Date.now() +
|
|
3462
|
+
const deadline = Date.now() + timeout;
|
|
3464
3463
|
const renderOptions = {
|
|
3465
3464
|
mode: "ai",
|
|
3466
3465
|
boxes: options.boxes,
|
|
@@ -3475,18 +3474,18 @@ async function passwordSafeAriaSnapshot(page, options = {}) {
|
|
|
3475
3474
|
mainFrameSeq: frameSeq(frame)
|
|
3476
3475
|
};
|
|
3477
3476
|
const document2 = { text: "", priorityRefs: [], matches: [], matchCount: 0, frames: [], unavailableFrames: [] };
|
|
3478
|
-
const timeoutError = () => new Error(`Timeout ${
|
|
3479
|
-
const
|
|
3480
|
-
let
|
|
3477
|
+
const timeoutError = () => new Error(`Timeout ${timeout}ms exceeded building a password-safe browser snapshot.`);
|
|
3478
|
+
const bounded = async (operation) => {
|
|
3479
|
+
let timer;
|
|
3481
3480
|
try {
|
|
3482
3481
|
return await Promise.race([
|
|
3483
3482
|
operation,
|
|
3484
3483
|
new Promise((_, reject) => {
|
|
3485
|
-
|
|
3484
|
+
timer = setTimeout(() => reject(timeoutError()), Math.max(0, deadline - Date.now()));
|
|
3486
3485
|
})
|
|
3487
3486
|
]);
|
|
3488
3487
|
} finally {
|
|
3489
|
-
clearTimeout(
|
|
3488
|
+
clearTimeout(timer);
|
|
3490
3489
|
}
|
|
3491
3490
|
};
|
|
3492
3491
|
const prefix = (options.frames ?? []).map((selector) => `${selector} >> internal:control=enter-frame >> `).join("");
|
|
@@ -3502,7 +3501,7 @@ async function passwordSafeAriaSnapshot(page, options = {}) {
|
|
|
3502
3501
|
return null;
|
|
3503
3502
|
let measured;
|
|
3504
3503
|
try {
|
|
3505
|
-
measured = (await
|
|
3504
|
+
measured = (await bounded(parentFrame.selectors.callOnSelector(selector, { strict: true }, iframeGeometryInUtilityWorld, null)))?.result;
|
|
3506
3505
|
} catch {
|
|
3507
3506
|
measured = undefined;
|
|
3508
3507
|
}
|
|
@@ -3530,11 +3529,11 @@ async function passwordSafeAriaSnapshot(page, options = {}) {
|
|
|
3530
3529
|
const parent = current.parentFrame?.();
|
|
3531
3530
|
if (!parent || typeof current.frameElement !== "function")
|
|
3532
3531
|
return withoutBoxes([], "unknown");
|
|
3533
|
-
const element = await
|
|
3532
|
+
const element = await bounded(current.frameElement(FRAME_ELEMENT_PROGRESS));
|
|
3534
3533
|
let measured;
|
|
3535
3534
|
try {
|
|
3536
3535
|
if (typeof element?.evaluateInUtility === "function")
|
|
3537
|
-
measured = await
|
|
3536
|
+
measured = await bounded(element.evaluateInUtility(iframeGeometryInUtilityWorld, null));
|
|
3538
3537
|
} finally {
|
|
3539
3538
|
element?.dispose?.();
|
|
3540
3539
|
}
|
|
@@ -3562,7 +3561,7 @@ async function passwordSafeAriaSnapshot(page, options = {}) {
|
|
|
3562
3561
|
throw timeoutError();
|
|
3563
3562
|
let captured;
|
|
3564
3563
|
try {
|
|
3565
|
-
captured = await
|
|
3564
|
+
captured = await bounded(currentFrame.selectors.callOnSelector(selector, { strict: true }, captureInUtilityWorld, frameOptions));
|
|
3566
3565
|
} catch (error) {
|
|
3567
3566
|
if (!isMainFrame || !options.scope?.startsWith("aria-ref=") || !isGoneFrameRef(error))
|
|
3568
3567
|
throw error;
|
|
@@ -3581,7 +3580,7 @@ async function passwordSafeAriaSnapshot(page, options = {}) {
|
|
|
3581
3580
|
}
|
|
3582
3581
|
if (options.frames?.length)
|
|
3583
3582
|
throw new Error("Snapshot frame selection failed. Each frames selector must match exactly one iframe with a loaded document.");
|
|
3584
|
-
await
|
|
3583
|
+
await bounded(new Promise((resolve) => setTimeout(resolve, 50)));
|
|
3585
3584
|
return captureFrame(currentFrame, selector, frameOptions, true, framePath, placement);
|
|
3586
3585
|
}
|
|
3587
3586
|
if (captured.info?.world !== "utility" || !isServerFrame(captured.frame))
|
|
@@ -3595,8 +3594,8 @@ async function passwordSafeAriaSnapshot(page, options = {}) {
|
|
|
3595
3594
|
const unchanged = placement === undefined || placement === PAGE;
|
|
3596
3595
|
document2.priorityRefs.push(...snapshot.priorityRefs ?? []);
|
|
3597
3596
|
for (const { box, ...match } of snapshot.matches ?? []) {
|
|
3598
|
-
const
|
|
3599
|
-
document2.matches.push({ ...match, ...
|
|
3597
|
+
const page = unchanged ? box : placement ? { ...box, x: Math.round(box.x + placement.x), y: Math.round(box.y + placement.y) } : undefined;
|
|
3598
|
+
document2.matches.push({ ...match, ...page ? { box: page } : {}, framePath });
|
|
3600
3599
|
}
|
|
3601
3600
|
document2.matchCount += snapshot.matchCount ?? 0;
|
|
3602
3601
|
if (snapshot.scopeMatchCount !== undefined)
|
|
@@ -3632,9 +3631,9 @@ async function passwordSafeAriaSnapshot(page, options = {}) {
|
|
|
3632
3631
|
return document2;
|
|
3633
3632
|
}
|
|
3634
3633
|
async function passwordSafeMatches(page, query, options = {}) {
|
|
3635
|
-
const
|
|
3634
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
3636
3635
|
const frame = serverMainFrame(page);
|
|
3637
|
-
let
|
|
3636
|
+
let timer;
|
|
3638
3637
|
const captured = await Promise.race([
|
|
3639
3638
|
frame.selectors.callOnSelector(":root", { strict: true }, captureInUtilityWorld, {
|
|
3640
3639
|
mode: "ai",
|
|
@@ -3645,9 +3644,9 @@ async function passwordSafeMatches(page, query, options = {}) {
|
|
|
3645
3644
|
mainFrameSeq: frameSeq(frame)
|
|
3646
3645
|
}),
|
|
3647
3646
|
new Promise((_, reject) => {
|
|
3648
|
-
|
|
3647
|
+
timer = setTimeout(() => reject(new Error(`Timeout ${timeout}ms exceeded resolving a target.`)), timeout);
|
|
3649
3648
|
})
|
|
3650
|
-
]).finally(() => clearTimeout(
|
|
3649
|
+
]).finally(() => clearTimeout(timer));
|
|
3651
3650
|
if (!captured)
|
|
3652
3651
|
return { matches: [], matchCount: 0, hiddenMatchCount: 0, invalidQuery: false };
|
|
3653
3652
|
if (captured.info?.world !== "utility")
|
|
@@ -3769,10 +3768,10 @@ function outline(document2) {
|
|
|
3769
3768
|
while (stack.length && stack.at(-1).indent >= indent)
|
|
3770
3769
|
stack.pop();
|
|
3771
3770
|
const parent = stack.at(-1)?.node;
|
|
3772
|
-
const { key
|
|
3771
|
+
const { key, ref } = snapshotLine(line);
|
|
3773
3772
|
const node = {
|
|
3774
3773
|
line: line.trimStart(),
|
|
3775
|
-
key
|
|
3774
|
+
key,
|
|
3776
3775
|
ref,
|
|
3777
3776
|
children: [],
|
|
3778
3777
|
parent,
|
|
@@ -3787,11 +3786,11 @@ function outline(document2) {
|
|
|
3787
3786
|
}
|
|
3788
3787
|
var MATCH_STATES = ["checked", "disabled", "expanded", "selected", "pressed", "level", "active"];
|
|
3789
3788
|
function matchKey(match, boxes) {
|
|
3790
|
-
let
|
|
3789
|
+
let key = match.role + (match.name ? ` ${JSON.stringify(match.name)}` : "");
|
|
3791
3790
|
for (const state of MATCH_STATES)
|
|
3792
3791
|
if (match.states[state] !== undefined)
|
|
3793
|
-
|
|
3794
|
-
return `${
|
|
3792
|
+
key += ` [${state}=${JSON.stringify(match.states[state])}]`;
|
|
3793
|
+
return `${key} [ref=${match.ref}]${boxes && match.box ? ` [box=${[match.box.x, match.box.y, match.box.width, match.box.height].join(",")}]` : ""}`;
|
|
3795
3794
|
}
|
|
3796
3795
|
var publicMatch = (match, inOutline, framePath) => ({
|
|
3797
3796
|
ref: match.ref,
|
|
@@ -3806,7 +3805,7 @@ var publicMatch = (match, inOutline, framePath) => ({
|
|
|
3806
3805
|
});
|
|
3807
3806
|
function renderSnapshot(document2, input) {
|
|
3808
3807
|
const { roots, refs } = outline(document2);
|
|
3809
|
-
const canonicalTarget = (
|
|
3808
|
+
const canonicalTarget = (target) => target && Object.fromEntries(Object.entries({ exact: true, ...target }).sort(([a], [b]) => a.localeCompare(b)));
|
|
3810
3809
|
const snapshotId = createHash4("sha256").update(JSON.stringify({
|
|
3811
3810
|
text: document2.text,
|
|
3812
3811
|
scope: canonicalTarget(input.scope),
|
|
@@ -4027,13 +4026,13 @@ class MainFrameDocuments {
|
|
|
4027
4026
|
heardAfter(since, ms) {
|
|
4028
4027
|
if (this.commits > since)
|
|
4029
4028
|
return Promise.resolve();
|
|
4030
|
-
return new Promise((
|
|
4029
|
+
return new Promise((resolve) => {
|
|
4031
4030
|
const done = () => {
|
|
4032
|
-
clearTimeout(
|
|
4031
|
+
clearTimeout(timer);
|
|
4033
4032
|
stop();
|
|
4034
|
-
|
|
4033
|
+
resolve();
|
|
4035
4034
|
};
|
|
4036
|
-
const
|
|
4035
|
+
const timer = setTimeout(done, ms);
|
|
4037
4036
|
const stop = this.onChange(() => {
|
|
4038
4037
|
if (this.commits > since)
|
|
4039
4038
|
done();
|
|
@@ -4103,10 +4102,10 @@ async function waitForLoadState(page, state, timeoutMs, since) {
|
|
|
4103
4102
|
if (documents.restoredAt(page, state, since))
|
|
4104
4103
|
return;
|
|
4105
4104
|
let stop = () => {};
|
|
4106
|
-
const restored = new Promise((
|
|
4105
|
+
const restored = new Promise((resolve) => {
|
|
4107
4106
|
const check = () => {
|
|
4108
4107
|
if (documents.restoredAt(page, state, since))
|
|
4109
|
-
|
|
4108
|
+
resolve();
|
|
4110
4109
|
};
|
|
4111
4110
|
const off = documents.onChange(check);
|
|
4112
4111
|
page.on("framenavigated", check);
|
|
@@ -4144,8 +4143,8 @@ function probeStates(_element, options) {
|
|
|
4144
4143
|
return false;
|
|
4145
4144
|
const range = document.createRange();
|
|
4146
4145
|
range.selectNode(child);
|
|
4147
|
-
const
|
|
4148
|
-
return
|
|
4146
|
+
const rect = range.getBoundingClientRect();
|
|
4147
|
+
return rect.width > 0 && rect.height > 0;
|
|
4149
4148
|
});
|
|
4150
4149
|
if (style.visibility !== "visible" || !element.checkVisibility())
|
|
4151
4150
|
return false;
|
|
@@ -4189,8 +4188,8 @@ async function waitForBrowserCondition(page, input, network) {
|
|
|
4189
4188
|
url: page.url(),
|
|
4190
4189
|
...extra
|
|
4191
4190
|
});
|
|
4192
|
-
const timedOut = (
|
|
4193
|
-
...
|
|
4191
|
+
const timedOut = (counts = {}, error = WAIT_TIMEOUT) => result(false, {
|
|
4192
|
+
...counts,
|
|
4194
4193
|
code: "wait_timeout",
|
|
4195
4194
|
timeoutMs: input.timeoutMs,
|
|
4196
4195
|
error
|
|
@@ -4200,21 +4199,21 @@ async function waitForBrowserCondition(page, input, network) {
|
|
|
4200
4199
|
code: "invalid_wait_target",
|
|
4201
4200
|
error: "Cannot resolve the wait target. Check target, scope and frame selectors with browser_read_page."
|
|
4202
4201
|
});
|
|
4203
|
-
const
|
|
4204
|
-
let
|
|
4202
|
+
const bounded = async (promise) => {
|
|
4203
|
+
let timer;
|
|
4205
4204
|
try {
|
|
4206
4205
|
return await Promise.race([
|
|
4207
4206
|
promise,
|
|
4208
4207
|
new Promise((_, reject) => {
|
|
4209
|
-
|
|
4208
|
+
timer = setTimeout(() => reject(new Error("Wait deadline exceeded")), Math.max(0, deadline - Date.now()));
|
|
4210
4209
|
})
|
|
4211
4210
|
]);
|
|
4212
4211
|
} finally {
|
|
4213
|
-
clearTimeout(
|
|
4212
|
+
clearTimeout(timer);
|
|
4214
4213
|
}
|
|
4215
4214
|
};
|
|
4216
4215
|
if (input.sleepMs !== undefined) {
|
|
4217
|
-
await new Promise((
|
|
4216
|
+
await new Promise((resolve) => setTimeout(resolve, Math.max(0, Math.min(input.sleepMs, deadline - Date.now()))));
|
|
4218
4217
|
return page.isClosed() ? tabClosed() : result(true, { sleptMs: input.sleepMs });
|
|
4219
4218
|
}
|
|
4220
4219
|
if (input.networkQuietMs !== undefined) {
|
|
@@ -4234,7 +4233,7 @@ async function waitForBrowserCondition(page, input, network) {
|
|
|
4234
4233
|
return result(true, { network: quiet });
|
|
4235
4234
|
if (now >= deadline)
|
|
4236
4235
|
return timedOut({ network: { ...quiet, busyUrls: network.busyRequestUrls({ ...options, windowMs: input.networkQuietMs }, now) } }, NETWORK_TIMEOUT);
|
|
4237
|
-
await new Promise((
|
|
4236
|
+
await new Promise((resolve) => setTimeout(resolve, Math.max(1, Math.min(50, deadline - now))));
|
|
4238
4237
|
}
|
|
4239
4238
|
}
|
|
4240
4239
|
if (!input.target) {
|
|
@@ -4260,12 +4259,12 @@ async function waitForBrowserCondition(page, input, network) {
|
|
|
4260
4259
|
} catch {
|
|
4261
4260
|
return invalidTarget();
|
|
4262
4261
|
}
|
|
4263
|
-
let
|
|
4262
|
+
let counts = { matchCount: 0, satisfiedCount: 0 };
|
|
4264
4263
|
while (Date.now() < deadline) {
|
|
4265
4264
|
if (page.isClosed())
|
|
4266
4265
|
return tabClosed();
|
|
4267
4266
|
try {
|
|
4268
|
-
const observed = await
|
|
4267
|
+
const observed = await bounded((async () => {
|
|
4269
4268
|
let handle = null;
|
|
4270
4269
|
let frameHandle = null;
|
|
4271
4270
|
let elements = [];
|
|
@@ -4273,18 +4272,18 @@ async function waitForBrowserCondition(page, input, network) {
|
|
|
4273
4272
|
if (input.frames.length) {
|
|
4274
4273
|
const frameRoot = root.locator(":root");
|
|
4275
4274
|
if (!await frameRoot.count())
|
|
4276
|
-
return { ...
|
|
4275
|
+
return { ...counts, scopeMissing: true };
|
|
4277
4276
|
frameHandle = await frameRoot.elementHandle({ timeout: Math.max(1, Math.min(250, deadline - Date.now())) });
|
|
4278
4277
|
if (!frameHandle)
|
|
4279
|
-
return { ...
|
|
4278
|
+
return { ...counts, scopeMissing: true };
|
|
4280
4279
|
}
|
|
4281
4280
|
if (scope) {
|
|
4282
4281
|
const count = await scope.count();
|
|
4283
4282
|
if (count !== 1)
|
|
4284
|
-
return { ...
|
|
4283
|
+
return { ...counts, scopeMissing: count === 0, scopeCount: count };
|
|
4285
4284
|
handle = await scope.elementHandle({ timeout: Math.max(1, Math.min(250, deadline - Date.now())) });
|
|
4286
4285
|
if (!handle)
|
|
4287
|
-
return { ...
|
|
4286
|
+
return { ...counts, scopeMissing: true };
|
|
4288
4287
|
elements = await handle.$$(selector);
|
|
4289
4288
|
} else {
|
|
4290
4289
|
elements = await root.locator(selector).elementHandles();
|
|
@@ -4309,18 +4308,18 @@ async function waitForBrowserCondition(page, input, network) {
|
|
|
4309
4308
|
scopeMatchCount: observed.scopeCount,
|
|
4310
4309
|
error: "Scope matched multiple elements. Narrow scope or use a unique ref from browser_read_page."
|
|
4311
4310
|
});
|
|
4312
|
-
|
|
4311
|
+
counts = { matchCount: observed.matchCount, satisfiedCount: observed.satisfiedCount };
|
|
4313
4312
|
if (!observed.scopeMissing) {
|
|
4314
|
-
if (input.match === "unique" &&
|
|
4313
|
+
if (input.match === "unique" && counts.matchCount > 1)
|
|
4315
4314
|
return result(false, {
|
|
4316
|
-
...
|
|
4315
|
+
...counts,
|
|
4317
4316
|
code: "ambiguous_wait_target",
|
|
4318
4317
|
error: "Target matched multiple elements. Narrow target/scope, or explicitly choose match: any or all."
|
|
4319
4318
|
});
|
|
4320
|
-
const absent =
|
|
4321
|
-
const matched = absent ||
|
|
4319
|
+
const absent = counts.matchCount === 0 && (input.state === "hidden" || input.state === "detached");
|
|
4320
|
+
const matched = absent || counts.matchCount > 0 && (input.match === "any" ? counts.satisfiedCount > 0 : counts.satisfiedCount === counts.matchCount);
|
|
4322
4321
|
if (matched)
|
|
4323
|
-
return result(true, { ...
|
|
4322
|
+
return result(true, { ...counts, state: input.state, match: input.match });
|
|
4324
4323
|
}
|
|
4325
4324
|
} catch (error) {
|
|
4326
4325
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -4330,13 +4329,13 @@ async function waitForBrowserCondition(page, input, network) {
|
|
|
4330
4329
|
error: "A scope or frame selector matched multiple elements. Use a unique scope and frame path."
|
|
4331
4330
|
});
|
|
4332
4331
|
if (Date.now() >= deadline)
|
|
4333
|
-
return timedOut(
|
|
4332
|
+
return timedOut(counts);
|
|
4334
4333
|
if (!/Timeout|detached|frame.*not found|Failed to find frame|Execution context|navigation|Target closed/i.test(message))
|
|
4335
4334
|
return invalidTarget();
|
|
4336
4335
|
}
|
|
4337
|
-
await new Promise((
|
|
4336
|
+
await new Promise((resolve) => setTimeout(resolve, Math.max(0, Math.min(50, deadline - Date.now()))));
|
|
4338
4337
|
}
|
|
4339
|
-
return timedOut(
|
|
4338
|
+
return timedOut(counts);
|
|
4340
4339
|
}
|
|
4341
4340
|
|
|
4342
4341
|
// cli/src/browser/passkey-guard.ts
|
|
@@ -4420,7 +4419,7 @@ var MAX_TRACKED = 200;
|
|
|
4420
4419
|
var HTTP_AUTH_RECOVERY = `A site asks for a username and password (an HTTP sign-in, in httpAuth). Answer it with browser_handle_dialog and its dialogId: decision "dismiss" cancels it and the tab shows the site's 401 page; "accept" signs in with vaultId and names (the names of the local vault values from browser_capture_secrets that hold the username and the password, never the values) and expectedOrigin, the exact origin the user authorized them for. Without such values, hand the tab to the user with browser_takeover: live view asks them to sign in. Other actions on this tab are refused until the sign-in is answered.`;
|
|
4421
4420
|
var REJECTED_RECOVERY = "The site rejected these credentials and asks again (httpAuth, a new dialogId): check that the vault values are this site's username and password, or ask the user. Answer the new sign-in or dismiss it; do not send the same values again.";
|
|
4422
4421
|
var GONE_RECOVERY = "Chrome no longer has this sign-in's request: the page navigated elsewhere, or its navigation was stopped. Nothing was sent. Read browser_events and the page.";
|
|
4423
|
-
var refusal = (
|
|
4422
|
+
var refusal = (code, recovery, details) => new RuntimeFault(code, recovery, true, details, true);
|
|
4424
4423
|
var protocolLogging = () => /\*|pw:protocol/.test(process.env.DEBUG ?? "");
|
|
4425
4424
|
var originOf = (url) => {
|
|
4426
4425
|
try {
|
|
@@ -4430,11 +4429,11 @@ var originOf = (url) => {
|
|
|
4430
4429
|
}
|
|
4431
4430
|
};
|
|
4432
4431
|
async function bounded2(work, ms) {
|
|
4433
|
-
let
|
|
4432
|
+
let timer;
|
|
4434
4433
|
await Promise.race([work.catch(() => {
|
|
4435
4434
|
return;
|
|
4436
|
-
}), new Promise((
|
|
4437
|
-
clearTimeout(
|
|
4435
|
+
}), new Promise((resolve) => timer = setTimeout(resolve, ms))]);
|
|
4436
|
+
clearTimeout(timer);
|
|
4438
4437
|
}
|
|
4439
4438
|
|
|
4440
4439
|
class HttpAuthPrompts {
|
|
@@ -4669,15 +4668,15 @@ class HttpAuthPrompts {
|
|
|
4669
4668
|
let outcome;
|
|
4670
4669
|
if (accept) {
|
|
4671
4670
|
const { requestId, url } = state;
|
|
4672
|
-
outcome = new Promise((
|
|
4671
|
+
outcome = new Promise((resolve) => {
|
|
4673
4672
|
const finish = (value) => {
|
|
4674
|
-
clearTimeout(
|
|
4673
|
+
clearTimeout(timer);
|
|
4675
4674
|
if (this.waits.get(requestId) === wait)
|
|
4676
4675
|
this.waits.delete(requestId);
|
|
4677
|
-
|
|
4676
|
+
resolve(value);
|
|
4678
4677
|
};
|
|
4679
4678
|
const wait = { url, resolve: finish };
|
|
4680
|
-
const
|
|
4679
|
+
const timer = setTimeout(() => finish({ kind: "pending" }), OUTCOME_MS);
|
|
4681
4680
|
this.waits.set(requestId, wait);
|
|
4682
4681
|
});
|
|
4683
4682
|
}
|
|
@@ -4755,8 +4754,8 @@ function diagnosticUrl(raw) {
|
|
|
4755
4754
|
u.username = "";
|
|
4756
4755
|
u.password = "";
|
|
4757
4756
|
u.hash = "";
|
|
4758
|
-
for (const
|
|
4759
|
-
u.searchParams.set(
|
|
4757
|
+
for (const key of [...u.searchParams.keys()])
|
|
4758
|
+
u.searchParams.set(key, "[redacted]");
|
|
4760
4759
|
return u.href;
|
|
4761
4760
|
} catch {
|
|
4762
4761
|
return "[unavailable]";
|
|
@@ -5038,9 +5037,9 @@ class BrowserPageEvents {
|
|
|
5038
5037
|
const current = this.passkey;
|
|
5039
5038
|
if (!current)
|
|
5040
5039
|
return;
|
|
5041
|
-
for (const
|
|
5042
|
-
if (
|
|
5043
|
-
current.requests.delete(
|
|
5040
|
+
for (const key of [...current.requests.keys()])
|
|
5041
|
+
if (key.startsWith(`${executionContextId}:`))
|
|
5042
|
+
current.requests.delete(key);
|
|
5044
5043
|
if (!current.requests.size)
|
|
5045
5044
|
this.closePasskey("settled");
|
|
5046
5045
|
});
|
|
@@ -5066,11 +5065,11 @@ class BrowserPageEvents {
|
|
|
5066
5065
|
const report = parsePasskeyReport(payload);
|
|
5067
5066
|
if (!report)
|
|
5068
5067
|
return;
|
|
5069
|
-
const
|
|
5068
|
+
const key = `${contextId}:${report.id}`;
|
|
5070
5069
|
if (report.state === "closed") {
|
|
5071
|
-
const
|
|
5072
|
-
if (
|
|
5073
|
-
this.closePasskey(
|
|
5070
|
+
const current = this.passkey;
|
|
5071
|
+
if (current?.requests.delete(key) && !current.requests.size)
|
|
5072
|
+
this.closePasskey(current.cancelledBy ? "cancelled" : "settled");
|
|
5074
5073
|
return;
|
|
5075
5074
|
}
|
|
5076
5075
|
let current = this.passkey;
|
|
@@ -5087,7 +5086,7 @@ class BrowserPageEvents {
|
|
|
5087
5086
|
current = this.passkey = opened;
|
|
5088
5087
|
}
|
|
5089
5088
|
if (current.requests.size < MAX_PASSKEY_REQUESTS)
|
|
5090
|
-
current.requests.set(
|
|
5089
|
+
current.requests.set(key, report.request);
|
|
5091
5090
|
}
|
|
5092
5091
|
closePasskey(reason) {
|
|
5093
5092
|
const current = this.passkey;
|
|
@@ -5128,16 +5127,16 @@ class BrowserPageEvents {
|
|
|
5128
5127
|
const cdp = this.cdp;
|
|
5129
5128
|
if (!cdp || !this.passkeyDetection || this.dialog || this.crashed || this.httpAuth.holdsMainFrame() || this.navigationLoading())
|
|
5130
5129
|
return;
|
|
5131
|
-
let
|
|
5130
|
+
let timer;
|
|
5132
5131
|
await Promise.race([
|
|
5133
5132
|
cdp.send("Runtime.evaluate", { expression: "0", silent: true }).catch(() => {
|
|
5134
5133
|
return;
|
|
5135
5134
|
}),
|
|
5136
|
-
new Promise((
|
|
5137
|
-
|
|
5135
|
+
new Promise((resolve) => {
|
|
5136
|
+
timer = setTimeout(resolve, PASSKEY_FLUSH_MS);
|
|
5138
5137
|
})
|
|
5139
5138
|
]);
|
|
5140
|
-
clearTimeout(
|
|
5139
|
+
clearTimeout(timer);
|
|
5141
5140
|
}
|
|
5142
5141
|
async cancelPasskey(handledBy) {
|
|
5143
5142
|
const current = this.passkey, cdp = this.cdp;
|
|
@@ -5149,13 +5148,13 @@ class BrowserPageEvents {
|
|
|
5149
5148
|
}
|
|
5150
5149
|
current.cancelledBy = handledBy;
|
|
5151
5150
|
const frames = new Set;
|
|
5152
|
-
for (const
|
|
5153
|
-
const frameId = this.contextFrames.get(Number(
|
|
5151
|
+
for (const key of current.requests.keys()) {
|
|
5152
|
+
const frameId = this.contextFrames.get(Number(key.slice(0, key.indexOf(":"))));
|
|
5154
5153
|
if (frameId)
|
|
5155
5154
|
frames.add(frameId);
|
|
5156
5155
|
}
|
|
5157
5156
|
const expression = `dispatchEvent(new Event(${JSON.stringify(this.passkeyCancel)}))`;
|
|
5158
|
-
let
|
|
5157
|
+
let timer;
|
|
5159
5158
|
await Promise.race([
|
|
5160
5159
|
Promise.all([...frames].map(async (frameId) => {
|
|
5161
5160
|
try {
|
|
@@ -5163,11 +5162,11 @@ class BrowserPageEvents {
|
|
|
5163
5162
|
await cdp.send("Runtime.evaluate", { contextId: world.executionContextId, expression });
|
|
5164
5163
|
} catch {}
|
|
5165
5164
|
})),
|
|
5166
|
-
new Promise((
|
|
5167
|
-
|
|
5165
|
+
new Promise((resolve) => {
|
|
5166
|
+
timer = setTimeout(resolve, PASSKEY_CANCEL_MS);
|
|
5168
5167
|
})
|
|
5169
5168
|
]);
|
|
5170
|
-
clearTimeout(
|
|
5169
|
+
clearTimeout(timer);
|
|
5171
5170
|
const closed = await this.passkeyClosed(current, PASSKEY_CANCEL_MS);
|
|
5172
5171
|
if (!closed && this.passkey === current)
|
|
5173
5172
|
current.cancelledBy = undefined;
|
|
@@ -5176,17 +5175,17 @@ class BrowserPageEvents {
|
|
|
5176
5175
|
passkeyClosed(current, ms) {
|
|
5177
5176
|
if (this.passkey !== current)
|
|
5178
5177
|
return Promise.resolve(true);
|
|
5179
|
-
return new Promise((
|
|
5178
|
+
return new Promise((resolve) => {
|
|
5180
5179
|
const finish = () => {
|
|
5181
|
-
clearTimeout(
|
|
5180
|
+
clearTimeout(timer);
|
|
5182
5181
|
this.changes.delete(changed);
|
|
5183
|
-
|
|
5182
|
+
resolve(this.passkey !== current);
|
|
5184
5183
|
};
|
|
5185
5184
|
const changed = () => {
|
|
5186
5185
|
if (this.passkey !== current)
|
|
5187
5186
|
finish();
|
|
5188
5187
|
};
|
|
5189
|
-
const
|
|
5188
|
+
const timer = setTimeout(finish, ms);
|
|
5190
5189
|
this.changes.add(changed);
|
|
5191
5190
|
});
|
|
5192
5191
|
}
|
|
@@ -5268,17 +5267,17 @@ class BrowserPageEvents {
|
|
|
5268
5267
|
};
|
|
5269
5268
|
if (!waiting())
|
|
5270
5269
|
return Promise.resolve();
|
|
5271
|
-
return new Promise((
|
|
5270
|
+
return new Promise((resolve) => {
|
|
5272
5271
|
const done = () => {
|
|
5273
|
-
clearTimeout(
|
|
5272
|
+
clearTimeout(timer);
|
|
5274
5273
|
this.frameDocumentChecks.delete(check);
|
|
5275
|
-
|
|
5274
|
+
resolve();
|
|
5276
5275
|
};
|
|
5277
5276
|
const check = () => {
|
|
5278
5277
|
if (!waiting())
|
|
5279
5278
|
done();
|
|
5280
5279
|
};
|
|
5281
|
-
const
|
|
5280
|
+
const timer = setTimeout(done, ms);
|
|
5282
5281
|
this.frameDocumentChecks.add(check);
|
|
5283
5282
|
});
|
|
5284
5283
|
}
|
|
@@ -5375,12 +5374,12 @@ class BrowserPageEvents {
|
|
|
5375
5374
|
const cdp = this.cdp;
|
|
5376
5375
|
if (!pending || !cdp)
|
|
5377
5376
|
return;
|
|
5378
|
-
let
|
|
5377
|
+
let timer;
|
|
5379
5378
|
const answered = await Promise.race([
|
|
5380
5379
|
cdp.send("Runtime.evaluate", { expression: "0", silent: true }).then(() => true, () => true),
|
|
5381
|
-
new Promise((
|
|
5380
|
+
new Promise((resolve) => timer = setTimeout(() => resolve(false), LOADING_PROBE_MS))
|
|
5382
5381
|
]);
|
|
5383
|
-
clearTimeout(
|
|
5382
|
+
clearTimeout(timer);
|
|
5384
5383
|
return answered ? undefined : { url: diagnosticUrl(pending.url), pendingMs: Math.max(0, Date.now() - pending.since) };
|
|
5385
5384
|
}
|
|
5386
5385
|
setCrashed(crashed) {
|
|
@@ -5484,20 +5483,20 @@ class BrowserPageEvents {
|
|
|
5484
5483
|
const first = this.query(input, false);
|
|
5485
5484
|
if (first.entries.length || !input.timeoutMs)
|
|
5486
5485
|
return first;
|
|
5487
|
-
let
|
|
5486
|
+
let timer, changed;
|
|
5488
5487
|
try {
|
|
5489
|
-
return await new Promise((
|
|
5488
|
+
return await new Promise((resolve) => {
|
|
5490
5489
|
changed = () => {
|
|
5491
5490
|
const result = this.query(input, false);
|
|
5492
5491
|
if (result.entries.length)
|
|
5493
|
-
|
|
5492
|
+
resolve(result);
|
|
5494
5493
|
};
|
|
5495
5494
|
this.changes.add(changed);
|
|
5496
|
-
|
|
5495
|
+
timer = setTimeout(() => resolve(this.query(input, false)), Number(input.timeoutMs));
|
|
5497
5496
|
changed();
|
|
5498
5497
|
});
|
|
5499
5498
|
} finally {
|
|
5500
|
-
clearTimeout(
|
|
5499
|
+
clearTimeout(timer);
|
|
5501
5500
|
this.changes.delete(changed);
|
|
5502
5501
|
}
|
|
5503
5502
|
}
|
|
@@ -5541,9 +5540,9 @@ class BrowserPageEvents {
|
|
|
5541
5540
|
reveal: options.reveal
|
|
5542
5541
|
});
|
|
5543
5542
|
if (auth) {
|
|
5544
|
-
const
|
|
5545
|
-
const
|
|
5546
|
-
return { ...auth, ...auth.handled === true ? { originalAction:
|
|
5543
|
+
const pending = held ?? this.pending;
|
|
5544
|
+
const outcome = auth.handled === true && auth.signIn !== "rejected" && pending ? await this.racePending(pending, 1000) : undefined;
|
|
5545
|
+
return { ...auth, ...auth.handled === true ? { originalAction: outcome ?? this.pendingAction() } : {}, dialog: this.activeDialog() };
|
|
5547
5546
|
}
|
|
5548
5547
|
if (signsInWithVault(input))
|
|
5549
5548
|
return {
|
|
@@ -5600,16 +5599,16 @@ class BrowserPageEvents {
|
|
|
5600
5599
|
};
|
|
5601
5600
|
}
|
|
5602
5601
|
async racePending(pending, ms) {
|
|
5603
|
-
let
|
|
5602
|
+
let timer;
|
|
5604
5603
|
try {
|
|
5605
5604
|
return await Promise.race([
|
|
5606
5605
|
pending.result,
|
|
5607
|
-
new Promise((
|
|
5608
|
-
|
|
5606
|
+
new Promise((resolve) => {
|
|
5607
|
+
timer = setTimeout(() => resolve(undefined), ms);
|
|
5609
5608
|
})
|
|
5610
5609
|
]);
|
|
5611
5610
|
} finally {
|
|
5612
|
-
clearTimeout(
|
|
5611
|
+
clearTimeout(timer);
|
|
5613
5612
|
}
|
|
5614
5613
|
}
|
|
5615
5614
|
async run(actionId, dispatch) {
|
|
@@ -5626,11 +5625,11 @@ class BrowserPageEvents {
|
|
|
5626
5625
|
this.currentAction = actionId;
|
|
5627
5626
|
let interruptedByDialog = false;
|
|
5628
5627
|
let wake;
|
|
5629
|
-
const interrupted = new Promise((
|
|
5628
|
+
const interrupted = new Promise((resolve) => {
|
|
5630
5629
|
wake = () => {
|
|
5631
5630
|
interruptedByDialog = true;
|
|
5632
5631
|
const auth = this.dialog ? undefined : this.httpAuth.requiredResult(actionId);
|
|
5633
|
-
|
|
5632
|
+
resolve(auth ?? { dispatch: { status: "blocked", actionId, code: "dialog_open" }, dialog: this.activeDialog() });
|
|
5634
5633
|
};
|
|
5635
5634
|
this.listeners.add(wake);
|
|
5636
5635
|
});
|
|
@@ -5641,10 +5640,10 @@ class BrowserPageEvents {
|
|
|
5641
5640
|
this.record("action", { actionId, status: "completed", outcomeVerified: false });
|
|
5642
5641
|
return { actionId, status: "completed", result };
|
|
5643
5642
|
}, () => {
|
|
5644
|
-
const
|
|
5643
|
+
const code = pending.unanswered ? "dialog_unanswered" : "executor_uncertain";
|
|
5645
5644
|
if (interruptedByDialog)
|
|
5646
|
-
this.record("action", { actionId, status: "unknown", code
|
|
5647
|
-
return { actionId, status: "unknown", code
|
|
5645
|
+
this.record("action", { actionId, status: "unknown", code, retrySafe: false });
|
|
5646
|
+
return { actionId, status: "unknown", code, retrySafe: false };
|
|
5648
5647
|
}).finally(() => {
|
|
5649
5648
|
pending.settled = true;
|
|
5650
5649
|
if (this.pending === pending)
|
|
@@ -5729,20 +5728,20 @@ function observeNavigation(page, input, events) {
|
|
|
5729
5728
|
const bound = started + input.timeoutMs + (deadline ? DIALOG_WAIT_MS : 0);
|
|
5730
5729
|
const since = commitsHeard(page);
|
|
5731
5730
|
let settled = false;
|
|
5732
|
-
let
|
|
5731
|
+
let resolve;
|
|
5733
5732
|
const result = new Promise((done) => {
|
|
5734
|
-
|
|
5733
|
+
resolve = done;
|
|
5735
5734
|
});
|
|
5736
|
-
const finish = (matched,
|
|
5735
|
+
const finish = (matched, code, error) => {
|
|
5737
5736
|
if (settled)
|
|
5738
5737
|
return;
|
|
5739
5738
|
settled = true;
|
|
5740
|
-
clearTimeout(
|
|
5739
|
+
clearTimeout(timer);
|
|
5741
5740
|
deadline?.stop();
|
|
5742
5741
|
page.off("framenavigated", onNavigation);
|
|
5743
5742
|
page.off("close", onClose);
|
|
5744
5743
|
page.off("crash", onClose);
|
|
5745
|
-
|
|
5744
|
+
resolve({ matched, url: page.url(), elapsedMs: Date.now() - started, waitUntil: input.waitUntil, ...code ? { code, error } : {} });
|
|
5746
5745
|
};
|
|
5747
5746
|
const onClose = () => finish(false, "navigation_tab_closed", "The tab closed before navigation was observed. Inspect tabs before another action.");
|
|
5748
5747
|
const onNavigation = (frame) => {
|
|
@@ -5761,7 +5760,7 @@ function observeNavigation(page, input, events) {
|
|
|
5761
5760
|
};
|
|
5762
5761
|
const timedOut = () => finish(false, "navigation_timeout", "Input was dispatched, but the expected navigation was not observed before the deadline. Inspect the page; do not repeat the action solely because this wait timed out.");
|
|
5763
5762
|
deadline?.expired.catch(timedOut);
|
|
5764
|
-
const
|
|
5763
|
+
const timer = setTimeout(() => deadline?.held() ? finish(false, "dialog_unanswered", "Input was dispatched, but a dialog that nobody answered still holds the expected navigation. Read browser_events for the dialog and answer or dismiss it; do not repeat the action.") : timedOut(), bound - started);
|
|
5765
5764
|
page.on("framenavigated", onNavigation);
|
|
5766
5765
|
page.on("close", onClose);
|
|
5767
5766
|
page.on("crash", onClose);
|
|
@@ -5784,7 +5783,7 @@ async function traverseToEntry(page, cdp, entryId, timeoutMs, expired) {
|
|
|
5784
5783
|
let response = null;
|
|
5785
5784
|
let reachedAt;
|
|
5786
5785
|
let settle;
|
|
5787
|
-
const committed = new Promise((
|
|
5786
|
+
const committed = new Promise((resolve, reject) => {
|
|
5788
5787
|
let settled = false;
|
|
5789
5788
|
settle = (value) => {
|
|
5790
5789
|
if (settled)
|
|
@@ -5794,7 +5793,7 @@ async function traverseToEntry(page, cdp, entryId, timeoutMs, expired) {
|
|
|
5794
5793
|
if (value instanceof Error)
|
|
5795
5794
|
reject(value);
|
|
5796
5795
|
else
|
|
5797
|
-
|
|
5796
|
+
resolve(value);
|
|
5798
5797
|
};
|
|
5799
5798
|
});
|
|
5800
5799
|
const decide = () => {
|
|
@@ -5846,11 +5845,11 @@ async function traverseToEntry(page, cdp, entryId, timeoutMs, expired) {
|
|
|
5846
5845
|
cdp.on("Page.frameNavigated", onCommit);
|
|
5847
5846
|
cdp.on("Page.navigatedWithinDocument", onWithinDocument);
|
|
5848
5847
|
const poll = setInterval(readEntry, POLL_MS);
|
|
5849
|
-
const
|
|
5848
|
+
const timer = setTimeout(() => settle(new Error(`Timeout ${timeoutMs}ms exceeded waiting for the history entry to commit.`)), Math.max(1, deadline - Date.now()));
|
|
5850
5849
|
expired?.catch((error) => settle(error instanceof Error ? error : new Error(String(error))));
|
|
5851
5850
|
function stop() {
|
|
5852
5851
|
clearInterval(poll);
|
|
5853
|
-
clearTimeout(
|
|
5852
|
+
clearTimeout(timer);
|
|
5854
5853
|
page.off("framenavigated", onFrameNavigated);
|
|
5855
5854
|
page.off("response", onResponse);
|
|
5856
5855
|
page.off("close", onClose);
|
|
@@ -5945,8 +5944,8 @@ function frameOrigin(iframe) {
|
|
|
5945
5944
|
if (zoom !== undefined && zoom !== 1)
|
|
5946
5945
|
return "transformed";
|
|
5947
5946
|
for (let node = iframe;node; node = node.parentElement ?? (node.getRootNode().host || null)) {
|
|
5948
|
-
const
|
|
5949
|
-
if (
|
|
5947
|
+
const style = view.getComputedStyle(node);
|
|
5948
|
+
if (style.transform !== "none" || style.scale !== "none" || style.rotate !== "none" || style.translate !== "none")
|
|
5950
5949
|
return "transformed";
|
|
5951
5950
|
}
|
|
5952
5951
|
const box = iframe.getBoundingClientRect();
|
|
@@ -6044,7 +6043,7 @@ async function framePath(chain, point, nameChars, inRoot = 1) {
|
|
|
6044
6043
|
}
|
|
6045
6044
|
return { kind: "reached", root, page: current };
|
|
6046
6045
|
}
|
|
6047
|
-
async function revealFrames(chain,
|
|
6046
|
+
async function revealFrames(chain, timeout) {
|
|
6048
6047
|
for (const frame of chain.toReversed()) {
|
|
6049
6048
|
const iframe = await frame.frameElement().catch(() => {
|
|
6050
6049
|
return;
|
|
@@ -6052,7 +6051,7 @@ async function revealFrames(chain, timeout2) {
|
|
|
6052
6051
|
if (!iframe)
|
|
6053
6052
|
return;
|
|
6054
6053
|
try {
|
|
6055
|
-
await iframe.scrollIntoViewIfNeeded({ timeout
|
|
6054
|
+
await iframe.scrollIntoViewIfNeeded({ timeout });
|
|
6056
6055
|
} catch {} finally {
|
|
6057
6056
|
iframe.dispose().catch(() => {
|
|
6058
6057
|
return;
|
|
@@ -6080,16 +6079,16 @@ class FrameTarget {
|
|
|
6080
6079
|
if (!showsRestoredDocument(page) || !chain.length)
|
|
6081
6080
|
return;
|
|
6082
6081
|
for (let index = 0;index < chain.length; index++) {
|
|
6083
|
-
const
|
|
6084
|
-
if (
|
|
6085
|
-
return { target
|
|
6082
|
+
const target = await FrameTarget.open(page, chain[index]);
|
|
6083
|
+
if (target)
|
|
6084
|
+
return { target, inRoot: index + 1 };
|
|
6086
6085
|
}
|
|
6087
6086
|
return;
|
|
6088
6087
|
}
|
|
6089
6088
|
static async at(page, point, reuse) {
|
|
6090
6089
|
if (!showsRestoredDocument(page))
|
|
6091
6090
|
return;
|
|
6092
|
-
const
|
|
6091
|
+
const path = [];
|
|
6093
6092
|
let frame = page.mainFrame();
|
|
6094
6093
|
let local = point;
|
|
6095
6094
|
for (let depth = 0;depth < 8; depth++) {
|
|
@@ -6112,20 +6111,20 @@ class FrameTarget {
|
|
|
6112
6111
|
break;
|
|
6113
6112
|
local = { x: local.x - origin.x, y: local.y - origin.y };
|
|
6114
6113
|
frame = child;
|
|
6115
|
-
|
|
6114
|
+
path.push({ frame, local });
|
|
6116
6115
|
} finally {
|
|
6117
6116
|
iframe.dispose().catch(() => {
|
|
6118
6117
|
return;
|
|
6119
6118
|
});
|
|
6120
6119
|
}
|
|
6121
6120
|
}
|
|
6122
|
-
for (const step of
|
|
6121
|
+
for (const step of path.toReversed()) {
|
|
6123
6122
|
const offset = { x: point.x - step.local.x, y: point.y - step.local.y };
|
|
6124
6123
|
if (reuse && reuse.frame === step.frame)
|
|
6125
6124
|
return { target: reuse, local: step.local, offset };
|
|
6126
|
-
const
|
|
6127
|
-
if (
|
|
6128
|
-
return { target
|
|
6125
|
+
const target = await FrameTarget.open(page, step.frame);
|
|
6126
|
+
if (target)
|
|
6127
|
+
return { target, local: step.local, offset };
|
|
6129
6128
|
}
|
|
6130
6129
|
return;
|
|
6131
6130
|
}
|
|
@@ -6206,12 +6205,12 @@ class DragInterception {
|
|
|
6206
6205
|
async wait(ms) {
|
|
6207
6206
|
if (this.caught)
|
|
6208
6207
|
return this.caught;
|
|
6209
|
-
let
|
|
6210
|
-
await new Promise((
|
|
6211
|
-
this.heard =
|
|
6212
|
-
|
|
6208
|
+
let timer;
|
|
6209
|
+
await new Promise((resolve) => {
|
|
6210
|
+
this.heard = resolve;
|
|
6211
|
+
timer = setTimeout(resolve, ms);
|
|
6213
6212
|
});
|
|
6214
|
-
clearTimeout(
|
|
6213
|
+
clearTimeout(timer);
|
|
6215
6214
|
this.heard = undefined;
|
|
6216
6215
|
return this.caught;
|
|
6217
6216
|
}
|
|
@@ -6224,30 +6223,30 @@ class DragInterception {
|
|
|
6224
6223
|
});
|
|
6225
6224
|
}
|
|
6226
6225
|
}
|
|
6227
|
-
async function dragOnTarget(
|
|
6228
|
-
const interception = await DragInterception.start(
|
|
6226
|
+
async function dragOnTarget(target, from, to, steps, modifiers = 0) {
|
|
6227
|
+
const interception = await DragInterception.start(target.page);
|
|
6229
6228
|
let entered = false;
|
|
6230
6229
|
try {
|
|
6231
|
-
await
|
|
6232
|
-
await
|
|
6230
|
+
await target.move(from, 0, modifiers);
|
|
6231
|
+
await target.press(from, "left", 1, BUTTON_BITS.left, modifiers);
|
|
6233
6232
|
const count = Math.max(1, Math.round(steps));
|
|
6234
6233
|
for (let step = 1;step <= count; step++) {
|
|
6235
6234
|
const point = { x: from.x + (to.x - from.x) * step / count, y: from.y + (to.y - from.y) * step / count };
|
|
6236
|
-
const
|
|
6237
|
-
if (
|
|
6238
|
-
await
|
|
6235
|
+
const data = interception?.data;
|
|
6236
|
+
if (data) {
|
|
6237
|
+
await target.drag(entered ? "dragOver" : "dragEnter", point, data, modifiers);
|
|
6239
6238
|
entered = true;
|
|
6240
6239
|
} else
|
|
6241
|
-
await
|
|
6240
|
+
await target.move(point, BUTTON_BITS.left, modifiers);
|
|
6242
6241
|
}
|
|
6243
6242
|
const data = await interception?.wait(DRAG_HANDOVER_MS);
|
|
6244
6243
|
if (data) {
|
|
6245
6244
|
if (!entered)
|
|
6246
|
-
await
|
|
6247
|
-
await
|
|
6245
|
+
await target.drag("dragEnter", to, data, modifiers);
|
|
6246
|
+
await target.drag("drop", to, data, modifiers);
|
|
6248
6247
|
}
|
|
6249
6248
|
} finally {
|
|
6250
|
-
await
|
|
6249
|
+
await target.release(to, "left", 1, 0, modifiers).catch(() => {
|
|
6251
6250
|
return;
|
|
6252
6251
|
});
|
|
6253
6252
|
await interception?.stop();
|
|
@@ -6257,7 +6256,7 @@ async function dragOnTarget(target2, from, to, steps, modifiers = 0) {
|
|
|
6257
6256
|
// cli/src/browser/browser-webmcp.ts
|
|
6258
6257
|
var NAME_REGISTRATION_WAIT_MS = 1000;
|
|
6259
6258
|
var FRAMES_LOADED_BEFORE_WATCHING = 'Frames of this document loaded before the runtime began watching the tab, and Chrome does not report the WebMCP tools they registered before that: such tools are missing here. Reloading the tab (browser_history {direction: "reload"}) lists them.';
|
|
6260
|
-
var refusal2 = (
|
|
6259
|
+
var refusal2 = (code, recovery, details) => new RuntimeFault(code, recovery, true, details, true);
|
|
6261
6260
|
var STALE_RECOVERY2 = "Call the tool by its name, which is resolved in the tab's current document, or take a current toolId from browser_webmcp_list. Nothing was invoked.";
|
|
6262
6261
|
|
|
6263
6262
|
class BrowserWebMCP {
|
|
@@ -6286,9 +6285,9 @@ class BrowserWebMCP {
|
|
|
6286
6285
|
async watch(waitMs) {
|
|
6287
6286
|
if (this.connection)
|
|
6288
6287
|
return;
|
|
6289
|
-
let
|
|
6290
|
-
await Promise.race([this.connect(), new Promise((
|
|
6291
|
-
clearTimeout(
|
|
6288
|
+
let timer;
|
|
6289
|
+
await Promise.race([this.connect(), new Promise((resolve) => timer = setTimeout(resolve, waitMs))]);
|
|
6290
|
+
clearTimeout(timer);
|
|
6292
6291
|
}
|
|
6293
6292
|
async connect() {
|
|
6294
6293
|
return this.connection ??= (async () => {
|
|
@@ -6334,9 +6333,9 @@ class BrowserWebMCP {
|
|
|
6334
6333
|
visit(tree.frameTree);
|
|
6335
6334
|
cdp.on("WebMCP.toolsAdded", ({ tools }) => {
|
|
6336
6335
|
for (const tool of tools) {
|
|
6337
|
-
for (const [
|
|
6336
|
+
for (const [id, entry] of this.tools)
|
|
6338
6337
|
if (entry.tool.frameId === tool.frameId && entry.tool.name === tool.name)
|
|
6339
|
-
this.tools.delete(
|
|
6338
|
+
this.tools.delete(id);
|
|
6340
6339
|
const frame = this.frames.get(tool.frameId);
|
|
6341
6340
|
if (!frame || this.tools.size >= 100 || JSON.stringify(tool.inputSchema ?? {}).length > 50000)
|
|
6342
6341
|
continue;
|
|
@@ -6411,18 +6410,18 @@ class BrowserWebMCP {
|
|
|
6411
6410
|
if (this.named(name).length)
|
|
6412
6411
|
return;
|
|
6413
6412
|
let notify = () => {};
|
|
6414
|
-
const arrived = new Promise((
|
|
6413
|
+
const arrived = new Promise((resolve) => {
|
|
6415
6414
|
notify = () => {
|
|
6416
6415
|
if (this.named(name).length)
|
|
6417
|
-
|
|
6416
|
+
resolve();
|
|
6418
6417
|
};
|
|
6419
6418
|
});
|
|
6420
6419
|
this.registered.add(notify);
|
|
6421
|
-
let
|
|
6420
|
+
let timer;
|
|
6422
6421
|
try {
|
|
6423
|
-
await Promise.race([arrived, new Promise((
|
|
6422
|
+
await Promise.race([arrived, new Promise((resolve) => timer = setTimeout(resolve, ms))]);
|
|
6424
6423
|
} finally {
|
|
6425
|
-
clearTimeout(
|
|
6424
|
+
clearTimeout(timer);
|
|
6426
6425
|
this.registered.delete(notify);
|
|
6427
6426
|
}
|
|
6428
6427
|
}
|
|
@@ -6445,9 +6444,9 @@ class BrowserWebMCP {
|
|
|
6445
6444
|
throw refusal2("webmcp_tool_ambiguous", "Several frames of the page register this name: call the one you mean by its toolId from candidates (toolId, frameId and the frame's origin, page data). Nothing was invoked.", { candidates: matches.slice(0, 20).map((entry) => ({ toolId: entry.id, frameId: entry.tool.frameId, origin: entry.origin })) });
|
|
6446
6445
|
}
|
|
6447
6446
|
annotatedReadOnly(invocationId) {
|
|
6448
|
-
const
|
|
6449
|
-
const readOnly = this.annotations.get(
|
|
6450
|
-
this.annotations.delete(
|
|
6447
|
+
const key = String(invocationId);
|
|
6448
|
+
const readOnly = this.annotations.get(key) === true;
|
|
6449
|
+
this.annotations.delete(key);
|
|
6451
6450
|
return readOnly;
|
|
6452
6451
|
}
|
|
6453
6452
|
async invoke(input) {
|
|
@@ -6460,7 +6459,7 @@ class BrowserWebMCP {
|
|
|
6460
6459
|
const find = (node) => node.frame.id === entry.tool.frameId ? node.frame : node.childFrames?.map(find).find(Boolean);
|
|
6461
6460
|
if (find(tree.frameTree)?.loaderId !== entry.loaderId || this.tools.get(entry.id) !== entry)
|
|
6462
6461
|
throw refusal2("stale_webmcp_tool", STALE_RECOVERY2);
|
|
6463
|
-
let
|
|
6462
|
+
let timer;
|
|
6464
6463
|
const { invocationId } = await this.cdp.send("WebMCP.invokeTool", {
|
|
6465
6464
|
frameId: entry.tool.frameId,
|
|
6466
6465
|
toolName: entry.tool.name,
|
|
@@ -6470,9 +6469,9 @@ class BrowserWebMCP {
|
|
|
6470
6469
|
if (this.annotations.size > 16)
|
|
6471
6470
|
this.annotations.delete(this.annotations.keys().next().value);
|
|
6472
6471
|
try {
|
|
6473
|
-
const outcome = await new Promise((
|
|
6474
|
-
this.responses.set(invocationId,
|
|
6475
|
-
|
|
6472
|
+
const outcome = await new Promise((resolve) => {
|
|
6473
|
+
this.responses.set(invocationId, resolve);
|
|
6474
|
+
timer = setTimeout(() => resolve(undefined), Number(input.timeoutMs ?? 1e4));
|
|
6476
6475
|
});
|
|
6477
6476
|
if (!outcome) {
|
|
6478
6477
|
await this.cdp.send("WebMCP.cancelInvocation", { invocationId }).catch(() => {
|
|
@@ -6495,7 +6494,7 @@ class BrowserWebMCP {
|
|
|
6495
6494
|
outcomeVerified: false
|
|
6496
6495
|
};
|
|
6497
6496
|
} finally {
|
|
6498
|
-
clearTimeout(
|
|
6497
|
+
clearTimeout(timer);
|
|
6499
6498
|
this.responses.delete(invocationId);
|
|
6500
6499
|
}
|
|
6501
6500
|
}
|
|
@@ -6563,10 +6562,10 @@ function probeInPage(element, options) {
|
|
|
6563
6562
|
};
|
|
6564
6563
|
const labelPoint = () => {
|
|
6565
6564
|
for (const label of labelsOf(element)) {
|
|
6566
|
-
const
|
|
6567
|
-
if (empty(
|
|
6565
|
+
const area = cut(label.getBoundingClientRect(), viewport);
|
|
6566
|
+
if (empty(area))
|
|
6568
6567
|
continue;
|
|
6569
|
-
const point = middle(
|
|
6568
|
+
const point = middle(area);
|
|
6570
6569
|
const hit = hitAt(point);
|
|
6571
6570
|
if (!hit || !within(hit, label))
|
|
6572
6571
|
continue;
|
|
@@ -6717,9 +6716,9 @@ function probeInPage(element, options) {
|
|
|
6717
6716
|
};
|
|
6718
6717
|
}
|
|
6719
6718
|
var NAME_CHARS = 80;
|
|
6720
|
-
async function probePointer(
|
|
6719
|
+
async function probePointer(target, timeout = 5000) {
|
|
6721
6720
|
const options = { nameChars: NAME_CHARS };
|
|
6722
|
-
return "count" in
|
|
6721
|
+
return "count" in target ? await target.evaluate(probeInPage, options, { timeout }) : await target.evaluate(probeInPage, options);
|
|
6723
6722
|
}
|
|
6724
6723
|
function inputKindInPage(element) {
|
|
6725
6724
|
const tag = element.tagName.toLowerCase();
|
|
@@ -6743,10 +6742,10 @@ function inputKindInPage(element) {
|
|
|
6743
6742
|
return { tag, kind: "custom_textbox", role };
|
|
6744
6743
|
return { tag, kind: "other" };
|
|
6745
6744
|
}
|
|
6746
|
-
async function inputKind(
|
|
6747
|
-
return await
|
|
6745
|
+
async function inputKind(target, timeout = 5000) {
|
|
6746
|
+
return await target.evaluate(inputKindInPage, undefined, { timeout });
|
|
6748
6747
|
}
|
|
6749
|
-
async function focusWithin(
|
|
6748
|
+
async function focusWithin(target) {
|
|
6750
6749
|
const check = (element) => {
|
|
6751
6750
|
let active = element.ownerDocument.activeElement;
|
|
6752
6751
|
while (active?.shadowRoot?.activeElement)
|
|
@@ -6756,7 +6755,7 @@ async function focusWithin(target2) {
|
|
|
6756
6755
|
return true;
|
|
6757
6756
|
return false;
|
|
6758
6757
|
};
|
|
6759
|
-
return "count" in
|
|
6758
|
+
return "count" in target ? await target.evaluate(check, undefined, { timeout: 2000 }) : await target.evaluate(check);
|
|
6760
6759
|
}
|
|
6761
6760
|
function focusedElementInPage(nameChars) {
|
|
6762
6761
|
let doc = document;
|
|
@@ -6900,10 +6899,10 @@ function pointerReach(probe) {
|
|
|
6900
6899
|
}
|
|
6901
6900
|
}
|
|
6902
6901
|
async function inspectElement(page, input) {
|
|
6903
|
-
const
|
|
6902
|
+
const target = input.ref ? page.locator(refSelector(String(input.ref))) : page.locator(String(input.selector));
|
|
6904
6903
|
let count;
|
|
6905
6904
|
try {
|
|
6906
|
-
count = await
|
|
6905
|
+
count = await target.count();
|
|
6907
6906
|
} catch (error) {
|
|
6908
6907
|
if (!input.ref || !isGoneFrameRef(error))
|
|
6909
6908
|
throw error;
|
|
@@ -6912,7 +6911,7 @@ async function inspectElement(page, input) {
|
|
|
6912
6911
|
if (count !== 1)
|
|
6913
6912
|
return { inspected: false, code: count ? "ambiguous_target" : "target_missing", matchCount: count };
|
|
6914
6913
|
const [details, info, probe] = await Promise.all([
|
|
6915
|
-
|
|
6914
|
+
target.evaluate((el, maxChars) => {
|
|
6916
6915
|
const secret = el instanceof HTMLInputElement && el.type === "password";
|
|
6917
6916
|
const attributes = Object.fromEntries([
|
|
6918
6917
|
"id",
|
|
@@ -6956,15 +6955,15 @@ async function inspectElement(page, input) {
|
|
|
6956
6955
|
truncated: (el.textContent?.length ?? 0) > maxChars
|
|
6957
6956
|
};
|
|
6958
6957
|
}, Number(input.maxChars ?? 2000), { timeout: 5000 }),
|
|
6959
|
-
inputKind(
|
|
6960
|
-
probePointer(
|
|
6958
|
+
inputKind(target),
|
|
6959
|
+
probePointer(target)
|
|
6961
6960
|
]);
|
|
6962
6961
|
const { readOnly, ...rest } = details;
|
|
6963
6962
|
return { ...rest, input: takesInput(info, readOnly), pointer: pointerReach(probe) };
|
|
6964
6963
|
}
|
|
6965
|
-
async function selectText(
|
|
6966
|
-
await
|
|
6967
|
-
const result = await
|
|
6964
|
+
async function selectText(target, input) {
|
|
6965
|
+
await target.waitFor({ state: "visible", timeout: 5000 });
|
|
6966
|
+
const result = await target.evaluate((element, request) => {
|
|
6968
6967
|
const control = element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement;
|
|
6969
6968
|
let proxy = !!element.editContext;
|
|
6970
6969
|
if (control && !proxy) {
|
|
@@ -7092,8 +7091,8 @@ async function clipboard(page, input) {
|
|
|
7092
7091
|
return { supported: true, written: true, formats: ["text/plain"] };
|
|
7093
7092
|
}
|
|
7094
7093
|
const items = await navigator.clipboard.read();
|
|
7095
|
-
const formats = [...new Set(items.flatMap((
|
|
7096
|
-
const item = items.find((
|
|
7094
|
+
const formats = [...new Set(items.flatMap((item) => item.types))];
|
|
7095
|
+
const item = items.find((item) => item.types.includes("text/plain"));
|
|
7097
7096
|
const blob = item ? await item.getType("text/plain") : undefined;
|
|
7098
7097
|
if (blob && blob.size > 1e5)
|
|
7099
7098
|
return { supported: true, formats, code: "clipboard_too_large" };
|
|
@@ -7138,14 +7137,14 @@ async function exportDocument(page, format) {
|
|
|
7138
7137
|
});
|
|
7139
7138
|
}
|
|
7140
7139
|
}
|
|
7141
|
-
const text = await page.evaluate((
|
|
7142
|
-
const
|
|
7143
|
-
if (
|
|
7140
|
+
const text = await page.evaluate((format) => {
|
|
7141
|
+
const bounded = (text) => {
|
|
7142
|
+
if (text.length > 20 * 1024 * 1024 || new TextEncoder().encode(text).length > 20 * 1024 * 1024)
|
|
7144
7143
|
throw new Error("Document export exceeds 20 MiB.");
|
|
7145
|
-
return
|
|
7144
|
+
return text;
|
|
7146
7145
|
};
|
|
7147
|
-
if (
|
|
7148
|
-
return
|
|
7146
|
+
if (format === "text")
|
|
7147
|
+
return bounded(document.body.innerText);
|
|
7149
7148
|
const clone = document.documentElement.cloneNode(true);
|
|
7150
7149
|
for (const el of clone.querySelectorAll('input[type="password"]'))
|
|
7151
7150
|
el.setAttribute("value", "[password]");
|
|
@@ -7155,7 +7154,7 @@ async function exportDocument(page, format) {
|
|
|
7155
7154
|
for (const attr of [...el.attributes])
|
|
7156
7155
|
if (/^on/i.test(attr.name) || attr.name === "srcdoc" || /^[\s\u0000-\u0020]*(javascript|vbscript):/i.test(attr.value))
|
|
7157
7156
|
el.removeAttribute(attr.name);
|
|
7158
|
-
return
|
|
7157
|
+
return bounded(`<!doctype html>
|
|
7159
7158
|
` + clone.outerHTML);
|
|
7160
7159
|
}, format);
|
|
7161
7160
|
return {
|
|
@@ -7199,9 +7198,9 @@ async function drawFrames(page) {
|
|
|
7199
7198
|
})().catch(() => {
|
|
7200
7199
|
return;
|
|
7201
7200
|
});
|
|
7202
|
-
let
|
|
7203
|
-
await Promise.race([started, new Promise((
|
|
7204
|
-
clearTimeout(
|
|
7201
|
+
let timer;
|
|
7202
|
+
await Promise.race([started, new Promise((resolve) => timer = setTimeout(resolve, SETUP_MS))]);
|
|
7203
|
+
clearTimeout(timer);
|
|
7205
7204
|
return stop;
|
|
7206
7205
|
}
|
|
7207
7206
|
|
|
@@ -7452,19 +7451,19 @@ async function captureScreenshot(context, page, region, output, timeoutMs, guard
|
|
|
7452
7451
|
}, () => {
|
|
7453
7452
|
return;
|
|
7454
7453
|
});
|
|
7455
|
-
let
|
|
7454
|
+
let timer;
|
|
7456
7455
|
try {
|
|
7457
7456
|
return await guard(() => Promise.race([
|
|
7458
7457
|
work,
|
|
7459
7458
|
new Promise((_, reject) => {
|
|
7460
|
-
|
|
7459
|
+
timer = setTimeout(() => reject(new ObservationError(`Timeout ${timeoutMs}ms exceeded while capturing the screenshot.`)), timeoutMs);
|
|
7461
7460
|
})
|
|
7462
7461
|
]));
|
|
7463
7462
|
} finally {
|
|
7464
|
-
clearTimeout(
|
|
7463
|
+
clearTimeout(timer);
|
|
7465
7464
|
let bound;
|
|
7466
|
-
Promise.race([settled, new Promise((
|
|
7467
|
-
bound = setTimeout(
|
|
7465
|
+
Promise.race([settled, new Promise((resolve) => {
|
|
7466
|
+
bound = setTimeout(resolve, ABANDONED_CAPTURE_DETACH_MS);
|
|
7468
7467
|
bound.unref?.();
|
|
7469
7468
|
})]).then(() => {
|
|
7470
7469
|
clearTimeout(bound);
|
|
@@ -7623,24 +7622,24 @@ function readsDocument(action, input, pointerKnown) {
|
|
|
7623
7622
|
}
|
|
7624
7623
|
}
|
|
7625
7624
|
function withTimeout(work, ms) {
|
|
7626
|
-
let
|
|
7625
|
+
let timer;
|
|
7627
7626
|
return Promise.race([
|
|
7628
7627
|
work,
|
|
7629
7628
|
new Promise((_, reject) => {
|
|
7630
|
-
|
|
7629
|
+
timer = setTimeout(() => reject(new Error("Optional read timed out")), ms);
|
|
7631
7630
|
})
|
|
7632
|
-
]).finally(() => clearTimeout(
|
|
7631
|
+
]).finally(() => clearTimeout(timer));
|
|
7633
7632
|
}
|
|
7634
|
-
var refusal3 = (
|
|
7635
|
-
function coveredProbe(probe,
|
|
7633
|
+
var refusal3 = (code, recovery, details) => new RuntimeFault(code, recovery, true, details, true);
|
|
7634
|
+
function coveredProbe(probe, path) {
|
|
7636
7635
|
return {
|
|
7637
7636
|
kind: "covered",
|
|
7638
7637
|
point: probe.point,
|
|
7639
7638
|
box: probe.box,
|
|
7640
7639
|
...probe.standIn ? { standIn: probe.standIn } : {},
|
|
7641
|
-
cover:
|
|
7642
|
-
...
|
|
7643
|
-
...
|
|
7640
|
+
cover: path.cover,
|
|
7641
|
+
...path.layer ? { layer: path.layer } : {},
|
|
7642
|
+
...path.passThrough ? { passThrough: true } : {}
|
|
7644
7643
|
};
|
|
7645
7644
|
}
|
|
7646
7645
|
var staleRef = (ref) => refusal3("ref_stale", "Read the page again with browser_read_page and use a current ref. Nothing was dispatched.", { ref });
|
|
@@ -7752,8 +7751,8 @@ class BrowserRuntime {
|
|
|
7752
7751
|
this.guardPage = guardPage;
|
|
7753
7752
|
this.passkeyDetection = passkeyDetection;
|
|
7754
7753
|
this.screenshotMaxEdge = screenshotMaxEdge;
|
|
7755
|
-
this.uploads = new BrowserUploadStore(uploadsPath, (
|
|
7756
|
-
|
|
7754
|
+
this.uploads = new BrowserUploadStore(uploadsPath, (target) => {
|
|
7755
|
+
target.dispose().catch(() => {
|
|
7757
7756
|
return;
|
|
7758
7757
|
});
|
|
7759
7758
|
});
|
|
@@ -8031,13 +8030,13 @@ class BrowserRuntime {
|
|
|
8031
8030
|
return { ref: requireRef(input.ref) };
|
|
8032
8031
|
return await this.targetRef(page, input.target);
|
|
8033
8032
|
}
|
|
8034
|
-
async targetRef(page,
|
|
8035
|
-
if (
|
|
8036
|
-
return { ref: requireRef(
|
|
8037
|
-
const echo = { target
|
|
8033
|
+
async targetRef(page, target) {
|
|
8034
|
+
if (target.ref)
|
|
8035
|
+
return { ref: requireRef(target.ref) };
|
|
8036
|
+
const echo = { target };
|
|
8038
8037
|
let selector;
|
|
8039
8038
|
try {
|
|
8040
|
-
selector = snapshotSelector(page,
|
|
8039
|
+
selector = snapshotSelector(page, target);
|
|
8041
8040
|
} catch (error) {
|
|
8042
8041
|
if (/frames/.test(error instanceof Error ? error.message : ""))
|
|
8043
8042
|
throw refusal3("target_invalid", TARGET_INVALID, echo);
|
|
@@ -8069,10 +8068,10 @@ class BrowserRuntime {
|
|
|
8069
8068
|
throw refusal3("target_ambiguous", TARGET_AMBIGUOUS, { ...echo, matchCount: found.matchCount, candidates: found.matches.slice(0, MAX_TARGET_CANDIDATES) });
|
|
8070
8069
|
if (Date.now() >= deadline) {
|
|
8071
8070
|
const near = [];
|
|
8072
|
-
if (
|
|
8073
|
-
near.push({ ...
|
|
8074
|
-
if (
|
|
8075
|
-
near.push({ role:
|
|
8071
|
+
if (target.exact !== false && (target.name || target.text || target.label || target.placeholder))
|
|
8072
|
+
near.push({ ...target, exact: false });
|
|
8073
|
+
if (target.role && target.name)
|
|
8074
|
+
near.push({ role: target.role });
|
|
8076
8075
|
let candidates = [];
|
|
8077
8076
|
for (const locator of near) {
|
|
8078
8077
|
candidates = await look(snapshotSelector(page, locator), MAX_TARGET_CANDIDATES).then((similar) => similar.matches).catch(() => []);
|
|
@@ -8086,7 +8085,7 @@ class BrowserRuntime {
|
|
|
8086
8085
|
candidates
|
|
8087
8086
|
});
|
|
8088
8087
|
}
|
|
8089
|
-
await new Promise((
|
|
8088
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(150, Math.max(1, deadline - Date.now()))));
|
|
8090
8089
|
}
|
|
8091
8090
|
}
|
|
8092
8091
|
async screenshotElement(page, input) {
|
|
@@ -8190,22 +8189,22 @@ class BrowserRuntime {
|
|
|
8190
8189
|
continue;
|
|
8191
8190
|
}
|
|
8192
8191
|
const reachable = probe.kind === "element" || probe.kind === "stand_in" ? probe : undefined;
|
|
8193
|
-
const
|
|
8194
|
-
let blocked = reachable &&
|
|
8195
|
-
if (
|
|
8196
|
-
if (!
|
|
8192
|
+
const path = reachable && chain.length ? await framePath(chain, reachable.point, NAME_CHARS, direct?.inRoot) : undefined;
|
|
8193
|
+
let blocked = reachable && path?.kind === "covered" ? coveredProbe(reachable, path) : probe;
|
|
8194
|
+
if (path?.kind === "covered") {} else if (direct && reachable) {
|
|
8195
|
+
if (!path) {
|
|
8197
8196
|
direct.target.dispose();
|
|
8198
8197
|
direct = undefined;
|
|
8199
8198
|
continue;
|
|
8200
8199
|
}
|
|
8201
8200
|
if (steady(previous, reachable)) {
|
|
8202
|
-
if (
|
|
8201
|
+
if (path.kind === "reached") {
|
|
8203
8202
|
this.cursor.delete(tabId);
|
|
8204
8203
|
try {
|
|
8205
8204
|
if (action === "click")
|
|
8206
|
-
await direct.target.click(
|
|
8205
|
+
await direct.target.click(path.root, button, clickCount);
|
|
8207
8206
|
else
|
|
8208
|
-
await direct.target.hover(
|
|
8207
|
+
await direct.target.hover(path.root, modifiers);
|
|
8209
8208
|
} catch (error) {
|
|
8210
8209
|
throw refActionError(error, ref, action);
|
|
8211
8210
|
}
|
|
@@ -8213,7 +8212,7 @@ class BrowserRuntime {
|
|
|
8213
8212
|
return { cursorKnown: false };
|
|
8214
8213
|
return await this.standInResult(page, handle, reachable, action, undefined);
|
|
8215
8214
|
}
|
|
8216
|
-
if (
|
|
8215
|
+
if (path.kind === "outside_viewport" && (!revealed || !scrolled)) {
|
|
8217
8216
|
if (!revealed) {
|
|
8218
8217
|
revealed = true;
|
|
8219
8218
|
await revealFrames(chain, Math.min(remaining(), 2000));
|
|
@@ -8248,21 +8247,21 @@ class BrowserRuntime {
|
|
|
8248
8247
|
}
|
|
8249
8248
|
} else if (!direct && (!standIn || probe.kind === "element")) {
|
|
8250
8249
|
this.cursor.delete(tabId);
|
|
8251
|
-
const
|
|
8250
|
+
const deadline = action === "click" ? this.events.get(page)?.navigationDeadline(remaining()) : undefined;
|
|
8252
8251
|
try {
|
|
8253
8252
|
if (action === "click")
|
|
8254
8253
|
await locator.click({ button, clickCount, timeout: remaining() });
|
|
8255
8254
|
else
|
|
8256
8255
|
await locator.hover({ timeout: remaining(), modifiers });
|
|
8257
8256
|
} catch (error) {
|
|
8258
|
-
const made = action === "click" ? await this.madeClick(page, error,
|
|
8257
|
+
const made = action === "click" ? await this.madeClick(page, error, deadline) : undefined;
|
|
8259
8258
|
if (made === "busy")
|
|
8260
8259
|
throw pageBusy(ref);
|
|
8261
8260
|
if (made)
|
|
8262
8261
|
return { cursorKnown: false, ...made === "loading" ? NAVIGATION_LOADING : {} };
|
|
8263
8262
|
throw await this.pointerFailure(error, handle, ref, action);
|
|
8264
8263
|
} finally {
|
|
8265
|
-
|
|
8264
|
+
deadline?.stop();
|
|
8266
8265
|
}
|
|
8267
8266
|
return { cursorKnown: false };
|
|
8268
8267
|
}
|
|
@@ -8271,7 +8270,7 @@ class BrowserRuntime {
|
|
|
8271
8270
|
throw refusal3("target_not_actionable", `The ref was not ${action === "click" ? "clicked" : "hovered"}: ${standIn ? `${standInState(standIn)}, and ` : ""}${problem}. Nothing was dispatched. ${next}`, { ref, reason, ...blocked.kind === "covered" ? { cover: blocked.cover, ...blocked.layer ? { layer: blocked.layer } : {} } : {} });
|
|
8272
8271
|
}
|
|
8273
8272
|
previous = probe;
|
|
8274
|
-
await new Promise((
|
|
8273
|
+
await new Promise((resolve) => setTimeout(resolve, probe.kind === "stand_in" || direct || path?.kind === "covered" ? 50 : 150));
|
|
8275
8274
|
}
|
|
8276
8275
|
} finally {
|
|
8277
8276
|
handle.dispose().catch(() => {
|
|
@@ -8308,12 +8307,12 @@ class BrowserRuntime {
|
|
|
8308
8307
|
y: box.y + (probe.point.y - probe.box.top) * (height > 0 ? box.height / height : 1)
|
|
8309
8308
|
};
|
|
8310
8309
|
}
|
|
8311
|
-
async pointerFailure(error,
|
|
8310
|
+
async pointerFailure(error, target, ref, action) {
|
|
8312
8311
|
if (!playwrightTimeout(error))
|
|
8313
8312
|
return refActionError(error, ref, action);
|
|
8314
|
-
let probe = await withTimeout(probePointer(
|
|
8313
|
+
let probe = await withTimeout(probePointer(target, 2000), 2000).catch(() => ({ kind: "detached" }));
|
|
8315
8314
|
if (probe.kind === "element" || probe.kind === "stand_in")
|
|
8316
|
-
probe = await withTimeout(this.ancestorCover(
|
|
8315
|
+
probe = await withTimeout(this.ancestorCover(target, probe), 2000).catch(() => {
|
|
8317
8316
|
return;
|
|
8318
8317
|
}) ?? probe;
|
|
8319
8318
|
const { reason, problem, next } = pointerProblem(probe);
|
|
@@ -8332,19 +8331,19 @@ class BrowserRuntime {
|
|
|
8332
8331
|
}
|
|
8333
8332
|
async heldClickNavigation(page, deadline) {
|
|
8334
8333
|
let committed;
|
|
8335
|
-
const commit = new Promise((
|
|
8334
|
+
const commit = new Promise((resolve) => committed = () => resolve("commit"));
|
|
8336
8335
|
const onCommit = (frame) => {
|
|
8337
8336
|
if (frame === page.mainFrame())
|
|
8338
8337
|
committed();
|
|
8339
8338
|
};
|
|
8340
|
-
let
|
|
8339
|
+
let timer;
|
|
8341
8340
|
page.on("framenavigated", onCommit);
|
|
8342
8341
|
page.on("close", committed);
|
|
8343
8342
|
try {
|
|
8344
8343
|
const outcome = await Promise.race([
|
|
8345
8344
|
commit,
|
|
8346
8345
|
deadline.expired.then(() => "expired", () => "expired"),
|
|
8347
|
-
new Promise((
|
|
8346
|
+
new Promise((resolve) => timer = setTimeout(() => resolve("bound"), DIALOG_WAIT_MS))
|
|
8348
8347
|
]);
|
|
8349
8348
|
if (outcome === "bound" && deadline.held()) {
|
|
8350
8349
|
this.events.get(page)?.markUnanswered();
|
|
@@ -8352,30 +8351,30 @@ class BrowserRuntime {
|
|
|
8352
8351
|
}
|
|
8353
8352
|
return outcome === "commit" ? "commit" : "expired";
|
|
8354
8353
|
} finally {
|
|
8355
|
-
clearTimeout(
|
|
8354
|
+
clearTimeout(timer);
|
|
8356
8355
|
page.off("framenavigated", onCommit);
|
|
8357
8356
|
page.off("close", committed);
|
|
8358
8357
|
}
|
|
8359
8358
|
}
|
|
8360
|
-
async ancestorCover(
|
|
8361
|
-
const handle = "count" in
|
|
8359
|
+
async ancestorCover(target, probe) {
|
|
8360
|
+
const handle = "count" in target ? await target.elementHandle({ timeout: 1000 }).catch(() => {
|
|
8362
8361
|
return;
|
|
8363
|
-
}) :
|
|
8362
|
+
}) : target;
|
|
8364
8363
|
if (!handle)
|
|
8365
8364
|
return;
|
|
8366
8365
|
try {
|
|
8367
8366
|
const chain = await frameChain(handle);
|
|
8368
|
-
const
|
|
8369
|
-
return
|
|
8367
|
+
const path = chain.length ? await framePath(chain, probe.point, NAME_CHARS) : undefined;
|
|
8368
|
+
return path?.kind === "covered" ? coveredProbe(probe, path) : undefined;
|
|
8370
8369
|
} finally {
|
|
8371
|
-
if (handle !==
|
|
8370
|
+
if (handle !== target)
|
|
8372
8371
|
handle.dispose().catch(() => {
|
|
8373
8372
|
return;
|
|
8374
8373
|
});
|
|
8375
8374
|
}
|
|
8376
8375
|
}
|
|
8377
|
-
async coveredStandIn(
|
|
8378
|
-
const probe = await probePointer(
|
|
8376
|
+
async coveredStandIn(target) {
|
|
8377
|
+
const probe = await probePointer(target, REF_ACTION_TIMEOUT_MS);
|
|
8379
8378
|
return "standIn" in probe && !!probe.standIn && probe.kind !== "element";
|
|
8380
8379
|
}
|
|
8381
8380
|
async atPoint(page, point, onTarget, onPage) {
|
|
@@ -8427,16 +8426,16 @@ class BrowserRuntime {
|
|
|
8427
8426
|
const probe = await probePointer(handle);
|
|
8428
8427
|
if (probe.kind !== "element" && probe.kind !== "stand_in")
|
|
8429
8428
|
return;
|
|
8430
|
-
const
|
|
8431
|
-
return
|
|
8429
|
+
const path = await framePath(await frameChain(handle), probe.point, NAME_CHARS);
|
|
8430
|
+
return path?.kind === "reached" ? path.page : undefined;
|
|
8432
8431
|
} finally {
|
|
8433
8432
|
handle.dispose().catch(() => {
|
|
8434
8433
|
return;
|
|
8435
8434
|
});
|
|
8436
8435
|
}
|
|
8437
8436
|
}
|
|
8438
|
-
async inChildFrame(
|
|
8439
|
-
const handle = await
|
|
8437
|
+
async inChildFrame(target) {
|
|
8438
|
+
const handle = await target.elementHandle({ timeout: REF_ACTION_TIMEOUT_MS }).catch(() => {
|
|
8440
8439
|
return;
|
|
8441
8440
|
});
|
|
8442
8441
|
if (!handle)
|
|
@@ -8482,7 +8481,7 @@ class BrowserRuntime {
|
|
|
8482
8481
|
async gotoSettled(page, url) {
|
|
8483
8482
|
const mark = this.events.get(page)?.frameDocumentMark();
|
|
8484
8483
|
try {
|
|
8485
|
-
await this.navigating(page, (
|
|
8484
|
+
await this.navigating(page, (timeout) => page.goto(url, { waitUntil: "domcontentloaded", timeout }));
|
|
8486
8485
|
} catch (error) {
|
|
8487
8486
|
const message = error instanceof Error ? error.message : String(error);
|
|
8488
8487
|
if (/Download is starting/i.test(message))
|
|
@@ -8543,10 +8542,10 @@ class BrowserRuntime {
|
|
|
8543
8542
|
async presentation(targets) {
|
|
8544
8543
|
const found = new Map;
|
|
8545
8544
|
const byBrowser = new Map;
|
|
8546
|
-
for (const
|
|
8547
|
-
const browser =
|
|
8545
|
+
for (const target of targets) {
|
|
8546
|
+
const browser = target.page.context().browser();
|
|
8548
8547
|
if (browser)
|
|
8549
|
-
byBrowser.set(browser, [...byBrowser.get(browser) ?? [],
|
|
8548
|
+
byBrowser.set(browser, [...byBrowser.get(browser) ?? [], target]);
|
|
8550
8549
|
}
|
|
8551
8550
|
const lookUp = async (browser, entries) => {
|
|
8552
8551
|
const cdp = await browser.newBrowserCDPSession();
|
|
@@ -8564,16 +8563,16 @@ class BrowserRuntime {
|
|
|
8564
8563
|
});
|
|
8565
8564
|
}
|
|
8566
8565
|
};
|
|
8567
|
-
let
|
|
8566
|
+
let timer;
|
|
8568
8567
|
await Promise.race([
|
|
8569
8568
|
Promise.all([...byBrowser].map(([browser, entries]) => lookUp(browser, entries).catch(() => {
|
|
8570
8569
|
return;
|
|
8571
8570
|
}))),
|
|
8572
|
-
new Promise((
|
|
8573
|
-
|
|
8571
|
+
new Promise((resolve) => {
|
|
8572
|
+
timer = setTimeout(resolve, TAB_PRESENTATION_TIMEOUT_MS);
|
|
8574
8573
|
})
|
|
8575
8574
|
]);
|
|
8576
|
-
clearTimeout(
|
|
8575
|
+
clearTimeout(timer);
|
|
8577
8576
|
return new Map(found);
|
|
8578
8577
|
}
|
|
8579
8578
|
async listTabs() {
|
|
@@ -8708,7 +8707,7 @@ class BrowserRuntime {
|
|
|
8708
8707
|
const held = events.session();
|
|
8709
8708
|
const before = page.url();
|
|
8710
8709
|
let stop = () => {};
|
|
8711
|
-
const loaded = new Promise((
|
|
8710
|
+
const loaded = new Promise((resolve, reject) => {
|
|
8712
8711
|
let committed = false;
|
|
8713
8712
|
const onNavigated = ({ frame }) => {
|
|
8714
8713
|
if (!frame.parentId)
|
|
@@ -8716,16 +8715,16 @@ class BrowserRuntime {
|
|
|
8716
8715
|
};
|
|
8717
8716
|
const onContentLoaded = () => {
|
|
8718
8717
|
if (committed)
|
|
8719
|
-
|
|
8718
|
+
resolve();
|
|
8720
8719
|
};
|
|
8721
8720
|
const onEnd = () => reject(new Error(page.isClosed() ? "Target page, context or browser has been closed" : "Target crashed"));
|
|
8722
|
-
const
|
|
8721
|
+
const timer = setTimeout(() => reject(new Error(`Timeout ${NAVIGATION_TIMEOUT_MS}ms exceeded while reloading the crashed tab.`)), NAVIGATION_TIMEOUT_MS);
|
|
8723
8722
|
held.on("Page.frameNavigated", onNavigated);
|
|
8724
8723
|
held.on("Page.domContentEventFired", onContentLoaded);
|
|
8725
8724
|
const offCrash = events.onCrash(onEnd);
|
|
8726
8725
|
page.once("close", onEnd);
|
|
8727
8726
|
stop = () => {
|
|
8728
|
-
clearTimeout(
|
|
8727
|
+
clearTimeout(timer);
|
|
8729
8728
|
held.off("Page.frameNavigated", onNavigated);
|
|
8730
8729
|
held.off("Page.domContentEventFired", onContentLoaded);
|
|
8731
8730
|
offCrash();
|
|
@@ -8754,8 +8753,8 @@ class BrowserRuntime {
|
|
|
8754
8753
|
outcomeVerified: false
|
|
8755
8754
|
};
|
|
8756
8755
|
}
|
|
8757
|
-
async traverseHistory(page, delta,
|
|
8758
|
-
const deadline = Date.now() +
|
|
8756
|
+
async traverseHistory(page, delta, timeout = NAVIGATION_TIMEOUT_MS, expired) {
|
|
8757
|
+
const deadline = Date.now() + timeout;
|
|
8759
8758
|
const session = this.events.get(page).session();
|
|
8760
8759
|
const history = await session?.send("Page.getNavigationHistory").catch(() => {
|
|
8761
8760
|
return;
|
|
@@ -8765,13 +8764,13 @@ class BrowserRuntime {
|
|
|
8765
8764
|
return;
|
|
8766
8765
|
const since = commitsHeard(page);
|
|
8767
8766
|
if (session && history && entry && entry.url === history.entries[history.currentIndex]?.url) {
|
|
8768
|
-
const traversed = await traverseToEntry(page, session, entry.id,
|
|
8767
|
+
const traversed = await traverseToEntry(page, session, entry.id, timeout, expired);
|
|
8769
8768
|
if (traversed.frame === "child")
|
|
8770
8769
|
return { response: null, restoredFromCache: false, frame: traversed.frame };
|
|
8771
8770
|
await waitForLoadState(page, "domcontentloaded", Math.max(1, deadline - Date.now()), since);
|
|
8772
8771
|
return { response: traversed.response, restoredFromCache: restoredFromCache(page, since), frame: traversed.frame };
|
|
8773
8772
|
}
|
|
8774
|
-
const options = { timeout
|
|
8773
|
+
const options = { timeout, waitUntil: "commit" };
|
|
8775
8774
|
const response = await (delta < 0 ? page.goBack(options) : page.goForward(options));
|
|
8776
8775
|
await waitForLoadState(page, "domcontentloaded", Math.max(1, deadline - Date.now()), since);
|
|
8777
8776
|
return { response, restoredFromCache: restoredFromCache(page, since), frame: "main" };
|
|
@@ -8944,11 +8943,11 @@ class BrowserRuntime {
|
|
|
8944
8943
|
if (observation.mode === "summary" && baseline && current) {
|
|
8945
8944
|
const { changed: changedLines, removed: removedLines } = compareOutlines(baseline, current);
|
|
8946
8945
|
const compared = current.clipped;
|
|
8947
|
-
const
|
|
8948
|
-
const removed = joinLines(removedLines, observation.maxChars -
|
|
8946
|
+
const text = joinLines(changedLines, observation.maxChars);
|
|
8947
|
+
const removed = joinLines(removedLines, observation.maxChars - text.text.length, false);
|
|
8949
8948
|
const notes = [
|
|
8950
8949
|
...changedLines.length || removedLines.length ? [] : ["No outline lines changed since the previous observation of this tab."],
|
|
8951
|
-
...
|
|
8950
|
+
...text.clipped || removed.clipped ? [`Output limited to ${observation.maxChars} characters; changedLines and removedLines count every line. Read the page for the rest.`] : [],
|
|
8952
8951
|
...compared ? [`The outline is longer than ${OBSERVATION_BASELINE_CHARS} characters and only those were compared: read the page with scope or query for changes after them.`] : []
|
|
8953
8952
|
];
|
|
8954
8953
|
return {
|
|
@@ -8962,11 +8961,11 @@ class BrowserRuntime {
|
|
|
8962
8961
|
baselineAvailable: true,
|
|
8963
8962
|
url: snapshot.url,
|
|
8964
8963
|
title: snapshot.title,
|
|
8965
|
-
text:
|
|
8964
|
+
text: text.text,
|
|
8966
8965
|
removed: removed.text,
|
|
8967
8966
|
changedLines: changedLines.length,
|
|
8968
8967
|
removedLines: removedLines.length,
|
|
8969
|
-
characterLimited:
|
|
8968
|
+
characterLimited: text.clipped || removed.clipped,
|
|
8970
8969
|
...compared ? { comparedChars: OBSERVATION_BASELINE_CHARS } : {},
|
|
8971
8970
|
...notes.length ? { note: notes.join(" ") } : {},
|
|
8972
8971
|
pageState: snapshot.pageState,
|
|
@@ -9014,7 +9013,7 @@ class BrowserRuntime {
|
|
|
9014
9013
|
return { results, stoppedAt: index, code: "batch_budget_exhausted", remaining: steps.length - index };
|
|
9015
9014
|
if (step.action === "sleep") {
|
|
9016
9015
|
const ms = Number(step.input.ms);
|
|
9017
|
-
await new Promise((
|
|
9016
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
9018
9017
|
results.push({ index, action: "sleep", result: { slept: ms } });
|
|
9019
9018
|
continue;
|
|
9020
9019
|
}
|
|
@@ -9076,34 +9075,34 @@ class BrowserRuntime {
|
|
|
9076
9075
|
if (action === "get_download")
|
|
9077
9076
|
return await this.getDownloadChunk(input);
|
|
9078
9077
|
if (action === "open_tab") {
|
|
9079
|
-
const
|
|
9080
|
-
this.track(
|
|
9081
|
-
await Promise.all([this.initialization.get(
|
|
9082
|
-
await this.entryOf(
|
|
9078
|
+
const page = await this.openTabIn(execution.openIn ?? this.context, input.disposition === "window");
|
|
9079
|
+
this.track(page);
|
|
9080
|
+
await Promise.all([this.initialization.get(page), this.webmcp.get(page)?.watch(WEBMCP_WATCH_WAIT_MS)]);
|
|
9081
|
+
await this.entryOf(page).tabState.update(page, {
|
|
9083
9082
|
ownerSessionId: execution.sessionId,
|
|
9084
9083
|
retention: input.retention === "temporary" ? "temporary" : "retained"
|
|
9085
9084
|
});
|
|
9086
|
-
execution.onTabOpened?.(this.ids.get(
|
|
9085
|
+
execution.onTabOpened?.(this.ids.get(page));
|
|
9087
9086
|
const url = typeof input.url === "string" ? input.url : "about:blank";
|
|
9088
9087
|
if (url !== "about:blank") {
|
|
9089
|
-
const events = this.events.get(
|
|
9088
|
+
const events = this.events.get(page);
|
|
9090
9089
|
await events.ready;
|
|
9091
9090
|
let result;
|
|
9092
9091
|
try {
|
|
9093
9092
|
result = await events.run(execution.operationId ?? crypto.randomUUID(), async () => {
|
|
9094
|
-
const settled = await this.gotoSettled(
|
|
9095
|
-
await this.guardPage?.(
|
|
9096
|
-
return { tab: await this.tabInfo(
|
|
9093
|
+
const settled = await this.gotoSettled(page, url);
|
|
9094
|
+
await this.guardPage?.(page);
|
|
9095
|
+
return { tab: await this.tabInfo(page), ...settled };
|
|
9097
9096
|
});
|
|
9098
9097
|
} catch (error) {
|
|
9099
|
-
const tab =
|
|
9098
|
+
const tab = page.isClosed() ? undefined : await this.tabInfo(page).catch(() => {
|
|
9100
9099
|
return;
|
|
9101
9100
|
});
|
|
9102
9101
|
throw tab ? openedTabFault(error, tab) : error;
|
|
9103
9102
|
}
|
|
9104
|
-
return { tab: await this.tabInfo(
|
|
9103
|
+
return { tab: await this.tabInfo(page), ...result };
|
|
9105
9104
|
}
|
|
9106
|
-
return { tab: await this.tabInfo(
|
|
9105
|
+
return { tab: await this.tabInfo(page) };
|
|
9107
9106
|
}
|
|
9108
9107
|
const page = this.page(input.tabId);
|
|
9109
9108
|
const tabId = input.tabId;
|
|
@@ -9215,27 +9214,27 @@ class BrowserRuntime {
|
|
|
9215
9214
|
case "edit_text": {
|
|
9216
9215
|
const { ref, match } = await this.actionRef(page, input);
|
|
9217
9216
|
const resolved = input.target !== undefined ? { ref, ...match ? { match } : {} } : {};
|
|
9218
|
-
const
|
|
9217
|
+
const target = await this.liveRef(page, ref);
|
|
9219
9218
|
const text = String(input.text);
|
|
9220
9219
|
let info;
|
|
9221
9220
|
try {
|
|
9222
|
-
info = await inputKind(
|
|
9221
|
+
info = await inputKind(target, REF_ACTION_TIMEOUT_MS);
|
|
9223
9222
|
} catch (error) {
|
|
9224
|
-
throw await this.pointerFailure(error,
|
|
9223
|
+
throw await this.pointerFailure(error, target, ref, "edit_text");
|
|
9225
9224
|
}
|
|
9226
9225
|
if (input.mode === "replace") {
|
|
9227
9226
|
if (info.kind !== "text" && info.kind !== "contenteditable")
|
|
9228
9227
|
throw notAFormField(ref, info);
|
|
9229
|
-
if (await this.coveredStandIn(
|
|
9228
|
+
if (await this.coveredStandIn(target))
|
|
9230
9229
|
throw notAFormField(ref, info, true);
|
|
9231
9230
|
try {
|
|
9232
|
-
await
|
|
9231
|
+
await target.fill(text, { timeout: REF_ACTION_TIMEOUT_MS });
|
|
9233
9232
|
} catch (error) {
|
|
9234
|
-
throw await this.pointerFailure(error,
|
|
9233
|
+
throw await this.pointerFailure(error, target, ref, "edit_text");
|
|
9235
9234
|
}
|
|
9236
9235
|
return { tabId, ...resolved, mode: input.mode, characters: text.length, dispatched: true };
|
|
9237
9236
|
}
|
|
9238
|
-
const editable = info.kind === "editcontext" ? await
|
|
9237
|
+
const editable = info.kind === "editcontext" ? await target.getAttribute("aria-readonly", { timeout: REF_ACTION_TIMEOUT_MS }) !== "true" : await target.isEditable({ timeout: REF_ACTION_TIMEOUT_MS }).catch(() => false);
|
|
9239
9238
|
if (!editable)
|
|
9240
9239
|
return {
|
|
9241
9240
|
tabId,
|
|
@@ -9244,7 +9243,7 @@ class BrowserRuntime {
|
|
|
9244
9243
|
code: "target_not_editable",
|
|
9245
9244
|
recovery: "This element does not take text here. Use the textbox that does, as browser_read_page shows it, or click this element with browser_mouse_click and type with browser_keyboard_type if the page takes typing there, as a code editor does. Nothing was typed."
|
|
9246
9245
|
};
|
|
9247
|
-
await
|
|
9246
|
+
await target.focus({ timeout: REF_ACTION_TIMEOUT_MS });
|
|
9248
9247
|
const focused = await withTimeout(page.evaluate(focusedElementInPage, NAME_CHARS), 1000).catch(() => {
|
|
9249
9248
|
return;
|
|
9250
9249
|
});
|
|
@@ -9263,7 +9262,7 @@ class BrowserRuntime {
|
|
|
9263
9262
|
}
|
|
9264
9263
|
const before = page.url();
|
|
9265
9264
|
const mark = this.events.get(page).frameDocumentMark();
|
|
9266
|
-
const traversed = input.direction === "reload" ? { response: await this.navigating(page, (
|
|
9265
|
+
const traversed = input.direction === "reload" ? { response: await this.navigating(page, (timeout) => page.reload({ timeout, waitUntil: "domcontentloaded" })), restoredFromCache: undefined } : await this.navigating(page, (timeout, expired) => this.traverseHistory(page, input.direction === "back" ? -1 : 1, timeout, expired));
|
|
9267
9266
|
if (traversed && !traversed.restoredFromCache && !(("frame" in traversed) && traversed.frame === "child"))
|
|
9268
9267
|
await this.framesSettled(page, mark);
|
|
9269
9268
|
if (!traversed)
|
|
@@ -9337,10 +9336,10 @@ class BrowserRuntime {
|
|
|
9337
9336
|
if (files.reduce((n, f) => n + f.bytes.length, 0) > 20 * 1024 * 1024)
|
|
9338
9337
|
return { tabId, exported: false, code: "export_too_large" };
|
|
9339
9338
|
const exports = files.map((file) => {
|
|
9340
|
-
const
|
|
9341
|
-
fs9.writeFileSync(
|
|
9339
|
+
const target = this.availableDownloadPath(`${crypto.randomUUID()}-${file.filename}`);
|
|
9340
|
+
fs9.writeFileSync(target, file.bytes, { flag: "wx", mode: 384 });
|
|
9342
9341
|
return {
|
|
9343
|
-
downloadId: this.downloadId(path9.basename(
|
|
9342
|
+
downloadId: this.downloadId(path9.basename(target)),
|
|
9344
9343
|
filename: file.filename,
|
|
9345
9344
|
size: file.bytes.length,
|
|
9346
9345
|
mimeType: file.mimeType
|
|
@@ -9438,9 +9437,9 @@ class BrowserRuntime {
|
|
|
9438
9437
|
this.observations.delete(tabId);
|
|
9439
9438
|
if (documentBefore !== undefined && documentBefore === documentAfter) {
|
|
9440
9439
|
const reuse = request.depth === undefined && request.maxChars === OBSERVATION_BASELINE_CHARS;
|
|
9441
|
-
const
|
|
9442
|
-
const clipped = "completeness" in
|
|
9443
|
-
const kept = { text:
|
|
9440
|
+
const outline = reuse ? result : renderSnapshot(snapshot, { ...parseSnapshotInput({}), maxChars: OBSERVATION_BASELINE_CHARS });
|
|
9441
|
+
const clipped = "completeness" in outline && outline.completeness.characterLimited;
|
|
9442
|
+
const kept = { text: outline.text, url: result.url, clipped, document: documentBefore };
|
|
9444
9443
|
this.observations.set(tabId, kept);
|
|
9445
9444
|
if (this.observations.size > 64)
|
|
9446
9445
|
this.observations.delete(this.observations.keys().next().value);
|
|
@@ -9456,8 +9455,8 @@ class BrowserRuntime {
|
|
|
9456
9455
|
this.observationSession(page, (cdp) => evaluateIsolated(cdp, fontsReadyExpression(SCREENSHOT_FONT_WAIT_MS), true)).catch(() => {
|
|
9457
9456
|
return;
|
|
9458
9457
|
}),
|
|
9459
|
-
new Promise((
|
|
9460
|
-
fontTimer = setTimeout(
|
|
9458
|
+
new Promise((resolve) => {
|
|
9459
|
+
fontTimer = setTimeout(resolve, SCREENSHOT_FONT_WAIT_MS);
|
|
9461
9460
|
})
|
|
9462
9461
|
]);
|
|
9463
9462
|
clearTimeout(fontTimer);
|
|
@@ -9470,8 +9469,8 @@ class BrowserRuntime {
|
|
|
9470
9469
|
const { state, document: documentState } = await this.observationSession(page, readViewportGeometry);
|
|
9471
9470
|
let region, format, kind, extra;
|
|
9472
9471
|
if (box) {
|
|
9473
|
-
const
|
|
9474
|
-
[region, format, kind, extra] = [
|
|
9472
|
+
const target = elementRegion(box, state);
|
|
9473
|
+
[region, format, kind, extra] = [target.region, SCREENSHOT_PNG, "element", target.element];
|
|
9475
9474
|
} else if (input.crop) {
|
|
9476
9475
|
const crop = input.crop;
|
|
9477
9476
|
if (crop.x + crop.width > state.width || crop.y + crop.height > state.height)
|
|
@@ -9560,8 +9559,8 @@ class BrowserRuntime {
|
|
|
9560
9559
|
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
9561
9560
|
throw invalidInput("move_mouse requires numeric x and y coordinates.");
|
|
9562
9561
|
this.cursor.delete(tabId);
|
|
9563
|
-
await withFramesDrawn(page, () => this.atPoint(page, { x, y }, async (
|
|
9564
|
-
await
|
|
9562
|
+
await withFramesDrawn(page, () => this.atPoint(page, { x, y }, async (target, local) => {
|
|
9563
|
+
await target.move(local);
|
|
9565
9564
|
}, () => page.mouse.move(x, y)));
|
|
9566
9565
|
this.cursor.set(tabId, { x, y });
|
|
9567
9566
|
return { tabId, x, y };
|
|
@@ -9585,8 +9584,8 @@ class BrowserRuntime {
|
|
|
9585
9584
|
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
9586
9585
|
throw new Error("mouse_click by coordinates requires numeric x and y.");
|
|
9587
9586
|
this.cursor.delete(tabId);
|
|
9588
|
-
await withFramesDrawn(page, () => this.atPoint(page, { x, y }, async (
|
|
9589
|
-
await
|
|
9587
|
+
await withFramesDrawn(page, () => this.atPoint(page, { x, y }, async (target, local) => {
|
|
9588
|
+
await target.click(local, button, clickCount);
|
|
9590
9589
|
this.cursor.set(tabId, { x, y });
|
|
9591
9590
|
}, async () => {
|
|
9592
9591
|
await page.mouse.move(x, y);
|
|
@@ -9598,7 +9597,7 @@ class BrowserRuntime {
|
|
|
9598
9597
|
const cursor = this.cursor.get(tabId);
|
|
9599
9598
|
if (!cursor)
|
|
9600
9599
|
throw refusal3("pointer_unknown", "Pass a ref or a target, or x/y: the center of a box from browser_read_page with boxes: true, or a point in a screenshot with its screenshotId. Nothing was clicked.");
|
|
9601
|
-
await withFramesDrawn(page, () => this.atPoint(page, cursor, (
|
|
9600
|
+
await withFramesDrawn(page, () => this.atPoint(page, cursor, (target, local) => target.click(local, button, clickCount), () => page.mouse.click(cursor.x, cursor.y, { button, clickCount })));
|
|
9602
9601
|
return { tabId, ...cursor, button };
|
|
9603
9602
|
}
|
|
9604
9603
|
case "scroll": {
|
|
@@ -9613,7 +9612,7 @@ class BrowserRuntime {
|
|
|
9613
9612
|
return { tabId, ref, ...match ? { match } : {} };
|
|
9614
9613
|
}
|
|
9615
9614
|
if (input.ref !== undefined) {
|
|
9616
|
-
if (["direction", "amount", "x", "y"].some((
|
|
9615
|
+
if (["direction", "amount", "x", "y"].some((key) => input[key] !== undefined))
|
|
9617
9616
|
throw new Error("scroll accepts ref or wheel/pointer parameters, not both.");
|
|
9618
9617
|
const ref = requireRef(input.ref);
|
|
9619
9618
|
const locator = await this.liveRef(page, ref);
|
|
@@ -9642,10 +9641,10 @@ class BrowserRuntime {
|
|
|
9642
9641
|
this.cursor.delete(tabId);
|
|
9643
9642
|
const deltaX = direction === "left" ? -amount : direction === "right" ? amount : 0;
|
|
9644
9643
|
const deltaY = direction === "up" ? -amount : direction === "down" ? amount : 0;
|
|
9645
|
-
await withFramesDrawn(page, () => this.atPoint(page, pointer, async (
|
|
9646
|
-
await
|
|
9644
|
+
await withFramesDrawn(page, () => this.atPoint(page, pointer, async (target, local) => {
|
|
9645
|
+
await target.move(local);
|
|
9647
9646
|
this.cursor.set(tabId, pointer);
|
|
9648
|
-
await
|
|
9647
|
+
await target.wheel(local, deltaX, deltaY);
|
|
9649
9648
|
}, async () => {
|
|
9650
9649
|
await page.mouse.move(pointer.x, pointer.y);
|
|
9651
9650
|
this.cursor.set(tabId, pointer);
|
|
@@ -9658,9 +9657,9 @@ class BrowserRuntime {
|
|
|
9658
9657
|
return { tabId, ...await withFramesDrawn(page, () => waitForBrowserCondition(page, wait, this.events.get(page))), pageState: this.observedAt(page, tabId)() };
|
|
9659
9658
|
}
|
|
9660
9659
|
case "upload_begin": {
|
|
9661
|
-
const
|
|
9662
|
-
const locator =
|
|
9663
|
-
const element =
|
|
9660
|
+
const target = parseUploadTarget(input);
|
|
9661
|
+
const locator = target.ref ? this.refLocator(page, target.ref) : target.selector ? page.locator(target.selector) : undefined;
|
|
9662
|
+
const element = target.chooserId ? this.events.get(page).chooser(target.chooserId) : await locator.elementHandle({ timeout: REF_ACTION_TIMEOUT_MS }).catch((error) => {
|
|
9664
9663
|
if (playwrightTimeout(error))
|
|
9665
9664
|
return null;
|
|
9666
9665
|
throw error;
|
|
@@ -9699,7 +9698,7 @@ class BrowserRuntime {
|
|
|
9699
9698
|
}
|
|
9700
9699
|
case "form_input": {
|
|
9701
9700
|
const { ref, match } = await this.actionRef(page, input);
|
|
9702
|
-
const provided = ["value", "values", "checked"].filter((
|
|
9701
|
+
const provided = ["value", "values", "checked"].filter((key) => input[key] !== undefined);
|
|
9703
9702
|
if (provided.length !== 1)
|
|
9704
9703
|
throw new Error("form_input requires exactly one of value, values, or checked.");
|
|
9705
9704
|
const locator = await this.liveRef(page, ref);
|
|
@@ -9716,10 +9715,10 @@ class BrowserRuntime {
|
|
|
9716
9715
|
throw refusal3("invalid_browser_input", `This element (kind ${kind}) takes ${field}, not ${provided[0]}: pass ${field} instead. Nothing was changed.`, { ref, kind, tag: info.tag });
|
|
9717
9716
|
};
|
|
9718
9717
|
const matchOption = (options, entry) => {
|
|
9719
|
-
const
|
|
9720
|
-
if (!
|
|
9718
|
+
const match = options.find((option) => option.value === entry) ?? options.find((option) => option.label === entry.trim());
|
|
9719
|
+
if (!match)
|
|
9721
9720
|
throw refusal3("option_not_found", "Pass the value or the label of one of the options in options (the first 20 of the select, page data). Nothing was changed.", { ref, options: options.slice(0, 20) });
|
|
9722
|
-
return
|
|
9721
|
+
return match.value;
|
|
9723
9722
|
};
|
|
9724
9723
|
try {
|
|
9725
9724
|
switch (info.kind) {
|
|
@@ -9761,14 +9760,14 @@ class BrowserRuntime {
|
|
|
9761
9760
|
}
|
|
9762
9761
|
case "keyboard": {
|
|
9763
9762
|
const keys = Array.isArray(input.keys) ? input.keys : [];
|
|
9764
|
-
if (keys.some((
|
|
9763
|
+
if (keys.some((key) => typeof key !== "string"))
|
|
9765
9764
|
throw invalidInput("keyboard keys must all be strings.");
|
|
9766
9765
|
const modifiers = Array.isArray(input.modifiers) ? input.modifiers.filter((value) => typeof value === "string") : [];
|
|
9767
9766
|
for (const modifier of modifiers)
|
|
9768
9767
|
await page.keyboard.down(modifier);
|
|
9769
9768
|
try {
|
|
9770
|
-
for (const
|
|
9771
|
-
await page.keyboard.press(
|
|
9769
|
+
for (const key of keys)
|
|
9770
|
+
await page.keyboard.press(key);
|
|
9772
9771
|
} finally {
|
|
9773
9772
|
for (const modifier of modifiers.toReversed())
|
|
9774
9773
|
await page.keyboard.up(modifier);
|
|
@@ -9781,8 +9780,8 @@ class BrowserRuntime {
|
|
|
9781
9780
|
if (input.mode === "keys") {
|
|
9782
9781
|
if (input.text.length > MAX_TYPED_KEYS_CHARS)
|
|
9783
9782
|
throw invalidInput(`keyboard_type mode "keys" is limited to ${MAX_TYPED_KEYS_CHARS} characters per call; split the text or use the default insert mode.`);
|
|
9784
|
-
const
|
|
9785
|
-
if (input.text.length *
|
|
9783
|
+
const delay = clampInt(input.delayMs, 0, 100, 20);
|
|
9784
|
+
if (input.text.length * delay > MAX_TYPED_KEYS_TOTAL_MS)
|
|
9786
9785
|
throw invalidInput(`text.length x delayMs must stay at or below ${MAX_TYPED_KEYS_TOTAL_MS}ms; lower delayMs or split the text.`);
|
|
9787
9786
|
}
|
|
9788
9787
|
const focused = await withTimeout(page.evaluate(focusedElementInPage, NAME_CHARS), 1000).catch(() => {
|
|
@@ -9806,7 +9805,7 @@ class BrowserRuntime {
|
|
|
9806
9805
|
throw new Error("run_js requires code.");
|
|
9807
9806
|
let evaluated;
|
|
9808
9807
|
try {
|
|
9809
|
-
evaluated = await page.evaluate(async ({ code
|
|
9808
|
+
evaluated = await page.evaluate(async ({ code, maxBytes, maxCount }) => {
|
|
9810
9809
|
const artifacts = [];
|
|
9811
9810
|
let totalBytes = 0;
|
|
9812
9811
|
const r5dCreateArtifact = (filename, content, mimeType) => {
|
|
@@ -9852,7 +9851,7 @@ class BrowserRuntime {
|
|
|
9852
9851
|
};
|
|
9853
9852
|
try {
|
|
9854
9853
|
const invoke = new Function("r5dCreateArtifact", `"use strict"; return (async () => {
|
|
9855
|
-
${
|
|
9854
|
+
${code}
|
|
9856
9855
|
})()`);
|
|
9857
9856
|
const result = await invoke(r5dCreateArtifact);
|
|
9858
9857
|
return { result, artifacts, document: documentState() };
|
|
@@ -10121,13 +10120,13 @@ class NativeRuntime {
|
|
|
10121
10120
|
const serial = this.serialOf(frame);
|
|
10122
10121
|
return kind === "navigation" ? `${serial}.${this.frameNavigations.get(frame) ?? 0}` : `${serial}:${this.frameDocuments.get(frame) ?? 0}`;
|
|
10123
10122
|
}
|
|
10124
|
-
frameShowing(page,
|
|
10125
|
-
const match = FRAME_KEY.exec(
|
|
10123
|
+
frameShowing(page, key) {
|
|
10124
|
+
const match = FRAME_KEY.exec(key);
|
|
10126
10125
|
if (!match)
|
|
10127
10126
|
return;
|
|
10128
10127
|
const serial = Number(match[1]), kind = match[2] === ":" ? "document" : "navigation";
|
|
10129
10128
|
const frame = page.frames().find((candidate) => this.frameSerials.get(candidate) === serial);
|
|
10130
|
-
return frame && !frame.isDetached() && this.keyOf(frame, kind) ===
|
|
10129
|
+
return frame && !frame.isDetached() && this.keyOf(frame, kind) === key ? { frame, kind } : undefined;
|
|
10131
10130
|
}
|
|
10132
10131
|
documentCurrent(tabId, document2) {
|
|
10133
10132
|
let page;
|
|
@@ -10244,21 +10243,21 @@ class NativeRuntime {
|
|
|
10244
10243
|
return { page, frame, tabId, document: document2, generation: this.frameNavigations.get(frame) ?? 0, assertCurrent };
|
|
10245
10244
|
}
|
|
10246
10245
|
async resolveUploadTarget(tabId, args, scope) {
|
|
10247
|
-
const
|
|
10246
|
+
const target = await this.locate(tabId, scope, Array.isArray(args.frames) ? args.frames : [], "document");
|
|
10248
10247
|
let parsed;
|
|
10249
10248
|
try {
|
|
10250
10249
|
parsed = parseUploadTarget(args);
|
|
10251
10250
|
} catch (error) {
|
|
10252
10251
|
throw new RuntimeFault("invalid_browser_input", "Pass exactly one of ref, selector or chooserId for the file input. Nothing was attached.", true, { problem: (error instanceof Error ? error.message : "Invalid file input target.").slice(0, 300) }, true);
|
|
10253
10252
|
}
|
|
10254
|
-
const element = parsed.chooserId ? this.engine.pageEvents(
|
|
10253
|
+
const element = parsed.chooserId ? this.engine.pageEvents(target.page).chooser(parsed.chooserId) : await this.fileInputElement(target.frame, parsed);
|
|
10255
10254
|
try {
|
|
10256
10255
|
const frame = await element.ownerFrame();
|
|
10257
10256
|
if (!frame || frame.isDetached())
|
|
10258
10257
|
throw uploadRefusal.changed();
|
|
10259
|
-
const input = this.bound(
|
|
10258
|
+
const input = this.bound(target.page, frame, tabId, scope, "document");
|
|
10260
10259
|
const assertCurrent = () => {
|
|
10261
|
-
|
|
10260
|
+
target.assertCurrent();
|
|
10262
10261
|
input.assertCurrent();
|
|
10263
10262
|
};
|
|
10264
10263
|
const info = await element.evaluate((el) => ({ file: el instanceof HTMLInputElement && el.type === "file" && !el.webkitdirectory && el.isConnected, multiple: el instanceof HTMLInputElement && el.multiple }));
|
|
@@ -10311,7 +10310,7 @@ class NativeRuntime {
|
|
|
10311
10310
|
try {
|
|
10312
10311
|
return await work();
|
|
10313
10312
|
} finally {
|
|
10314
|
-
await new Promise((
|
|
10313
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
10315
10314
|
events.diagnosticsSuppressed = false;
|
|
10316
10315
|
}
|
|
10317
10316
|
}
|
|
@@ -10400,13 +10399,13 @@ class NativeRuntime {
|
|
|
10400
10399
|
this.assertAgentControl(tabId, op);
|
|
10401
10400
|
if (tabId) {
|
|
10402
10401
|
this.sessions?.assertTabAvailable(tabId);
|
|
10403
|
-
let
|
|
10402
|
+
let current;
|
|
10404
10403
|
try {
|
|
10405
|
-
|
|
10404
|
+
current = this.engine.page(tabId);
|
|
10406
10405
|
} catch {
|
|
10407
10406
|
throw new RuntimeFault("tab_closed", "Select an open tab before submitting a new request.", true);
|
|
10408
10407
|
}
|
|
10409
|
-
if (
|
|
10408
|
+
if (current !== page || checkDocument && this.documents.get(tabId) !== admittedDocument)
|
|
10410
10409
|
throw new RuntimeFault("stale_queued_target", "The target document changed while waiting. Observe it again before submitting a new request.", true);
|
|
10411
10410
|
const owner = this.owners.get(tabId);
|
|
10412
10411
|
if (owner && scopeKey(owner) !== scopeKey(scope))
|
|
@@ -10422,11 +10421,11 @@ class NativeRuntime {
|
|
|
10422
10421
|
await this.endSession(scope);
|
|
10423
10422
|
return { ended: true };
|
|
10424
10423
|
}
|
|
10425
|
-
const controller = new AbortController,
|
|
10426
|
-
let set = this.controllers.get(
|
|
10424
|
+
const controller = new AbortController, key = scopeKey(scope);
|
|
10425
|
+
let set = this.controllers.get(key);
|
|
10427
10426
|
if (!set) {
|
|
10428
10427
|
set = new Set;
|
|
10429
|
-
this.controllers.set(
|
|
10428
|
+
this.controllers.set(key, set);
|
|
10430
10429
|
}
|
|
10431
10430
|
set.add(controller);
|
|
10432
10431
|
this.operations.set(operationId, controller);
|
|
@@ -10436,7 +10435,7 @@ class NativeRuntime {
|
|
|
10436
10435
|
this.operations.delete(operationId);
|
|
10437
10436
|
set.delete(controller);
|
|
10438
10437
|
if (!set.size)
|
|
10439
|
-
this.controllers.delete(
|
|
10438
|
+
this.controllers.delete(key);
|
|
10440
10439
|
}
|
|
10441
10440
|
}
|
|
10442
10441
|
async executeInner(op, args, scope, operationId, beforeDispatch, screenshotStage) {
|
|
@@ -10448,14 +10447,14 @@ class NativeRuntime {
|
|
|
10448
10447
|
};
|
|
10449
10448
|
await this.hooks;
|
|
10450
10449
|
this.validateScope(scope);
|
|
10451
|
-
let
|
|
10450
|
+
let target;
|
|
10452
10451
|
if (typeof args.tabId === "string") {
|
|
10453
10452
|
this.assertAgentControl(args.tabId, op);
|
|
10454
10453
|
const page = await this.claimPage(args.tabId, scope);
|
|
10455
10454
|
await this.track(page);
|
|
10456
10455
|
this.assertPageAvailable(page);
|
|
10457
10456
|
this.sessions?.noteTabUse(args.tabId);
|
|
10458
|
-
|
|
10457
|
+
target = page;
|
|
10459
10458
|
}
|
|
10460
10459
|
if (op === "session_end") {
|
|
10461
10460
|
await this.endSession(scope);
|
|
@@ -10475,8 +10474,8 @@ class NativeRuntime {
|
|
|
10475
10474
|
const operationEpoch = this.epochs.get(scopeKey(scope)) ?? 0;
|
|
10476
10475
|
const plugin = this.plugins.find((p) => p.operations.includes(op));
|
|
10477
10476
|
if (plugin) {
|
|
10478
|
-
if (
|
|
10479
|
-
this.engine.assertCrashAllows(
|
|
10477
|
+
if (target)
|
|
10478
|
+
this.engine.assertCrashAllows(target, op, args);
|
|
10480
10479
|
begin();
|
|
10481
10480
|
if (op === "cancel_transfer" && args.eventId && args.tabId)
|
|
10482
10481
|
return this.engine.execute("cancel_transfer", args, { operationId });
|
|
@@ -10515,12 +10514,12 @@ class NativeRuntime {
|
|
|
10515
10514
|
const result = await this.engine.execute(op, op === "open_tab" ? tabArgs : args, { sessionId: scopeKey(scope), operationId, beforeDispatch: begin, screenshotStage, onTabOpened, openIn: session?.context, revealHttpAuth });
|
|
10516
10515
|
if (this.disconnected || (this.epochs.get(scopeKey(scope)) ?? 0) !== operationEpoch)
|
|
10517
10516
|
throw new Error("Scope ended during execution; outcome uncertain");
|
|
10518
|
-
const
|
|
10517
|
+
const target = op === "capabilities" && typeof args.tabId === "string" ? await this.targetCapabilities(args.tabId, scope) : undefined;
|
|
10519
10518
|
if (this.disconnected || (this.epochs.get(scopeKey(scope)) ?? 0) !== operationEpoch)
|
|
10520
10519
|
throw new Error("Scope ended during execution; outcome uncertain");
|
|
10521
10520
|
if (op === "open_tab" && typeof result?.tab?.tabId === "string")
|
|
10522
10521
|
this.owners.set(result.tab.tabId, { ...scope });
|
|
10523
|
-
return
|
|
10522
|
+
return target ? { ...result, ...target } : result;
|
|
10524
10523
|
} catch (error) {
|
|
10525
10524
|
if (error instanceof RuntimeFault)
|
|
10526
10525
|
throw new RuntimeFault(error.code, error.recovery, !dispatched && error.beforeDispatch, error.details, error.definite);
|
|
@@ -10530,23 +10529,23 @@ class NativeRuntime {
|
|
|
10530
10529
|
}
|
|
10531
10530
|
}
|
|
10532
10531
|
async endSession(scope) {
|
|
10533
|
-
const
|
|
10534
|
-
this.ended.add(
|
|
10535
|
-
this.epochs.set(
|
|
10536
|
-
for (const controller of this.controllers.get(
|
|
10532
|
+
const key = scopeKey(scope);
|
|
10533
|
+
this.ended.add(key);
|
|
10534
|
+
this.epochs.set(key, (this.epochs.get(key) ?? 0) + 1);
|
|
10535
|
+
for (const controller of this.controllers.get(key) ?? [])
|
|
10537
10536
|
controller.abort(new Error("Runtime scope revoked"));
|
|
10538
10537
|
this.revocationEpoch++;
|
|
10539
10538
|
for (const [id, owner] of this.owners)
|
|
10540
|
-
if (scopeKey(owner) ===
|
|
10539
|
+
if (scopeKey(owner) === key) {
|
|
10541
10540
|
this.revokeOwnership(id);
|
|
10542
10541
|
this.engine.handHttpAuthToChrome("session_ended", id);
|
|
10543
10542
|
}
|
|
10544
10543
|
for (const [page, owner] of this.closedOwners)
|
|
10545
|
-
if (scopeKey(owner) ===
|
|
10544
|
+
if (scopeKey(owner) === key)
|
|
10546
10545
|
this.closedOwners.delete(page);
|
|
10547
10546
|
for (const p of this.plugins)
|
|
10548
10547
|
await p.onSessionEnd?.(scope);
|
|
10549
|
-
this.ended.delete(
|
|
10548
|
+
this.ended.delete(key);
|
|
10550
10549
|
}
|
|
10551
10550
|
async shutdown() {
|
|
10552
10551
|
await this.disconnect();
|
|
@@ -10629,9 +10628,9 @@ var locatorFields = ["ref", "selector", "role", "name", "text", "label", "placeh
|
|
|
10629
10628
|
var locatorStrategies = (allowName) => locatorFields.filter((field) => allowName || field !== "name").map((field) => ({
|
|
10630
10629
|
type: "object",
|
|
10631
10630
|
required: [field],
|
|
10632
|
-
properties: Object.fromEntries(locatorFields.map((
|
|
10633
|
-
|
|
10634
|
-
|
|
10631
|
+
properties: Object.fromEntries(locatorFields.map((key) => [
|
|
10632
|
+
key,
|
|
10633
|
+
key === field ? { type: "string" } : field === "role" && key === "name" ? { type: ["string", "null"] } : { type: "null" }
|
|
10635
10634
|
]))
|
|
10636
10635
|
}));
|
|
10637
10636
|
var snapshotTarget = {
|
|
@@ -10732,7 +10731,7 @@ var httpAuthNames = advertisedAs({
|
|
|
10732
10731
|
description: httpAuthNamesDescription
|
|
10733
10732
|
}, { type: "object", properties: { username: { type: "string" }, password: { type: "string" } }, description: httpAuthNamesDescription });
|
|
10734
10733
|
var advertisedLocatorFields = Object.fromEntries([
|
|
10735
|
-
...locatorFields.map((
|
|
10734
|
+
...locatorFields.map((key) => [key, { type: ["string", "null"] }]),
|
|
10736
10735
|
["exact", { type: ["boolean", "null"] }]
|
|
10737
10736
|
]);
|
|
10738
10737
|
|
|
@@ -10847,11 +10846,11 @@ function mediaURL(server) {
|
|
|
10847
10846
|
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
10848
10847
|
return url.href;
|
|
10849
10848
|
}
|
|
10850
|
-
function headerFrom(runtimeTabId, navSeq,
|
|
10849
|
+
function headerFrom(runtimeTabId, navSeq, frameSeq, m) {
|
|
10851
10850
|
return {
|
|
10852
10851
|
runtimeTabId,
|
|
10853
10852
|
navSeq,
|
|
10854
|
-
frameSeq
|
|
10853
|
+
frameSeq,
|
|
10855
10854
|
timestamp: m.timestamp === undefined ? Date.now() : m.timestamp * 1000,
|
|
10856
10855
|
deviceWidth: m.deviceWidth ?? 1,
|
|
10857
10856
|
deviceHeight: m.deviceHeight ?? 1,
|
|
@@ -10901,13 +10900,13 @@ class CaptureTimeout extends Error {
|
|
|
10901
10900
|
}
|
|
10902
10901
|
}
|
|
10903
10902
|
async function bounded3(stage, operation) {
|
|
10904
|
-
let
|
|
10903
|
+
let timer;
|
|
10905
10904
|
try {
|
|
10906
10905
|
return await Promise.race([operation, new Promise((_, reject) => {
|
|
10907
|
-
|
|
10906
|
+
timer = setTimeout(() => reject(new CaptureTimeout(stage)), STAGE_TIMEOUT_MS);
|
|
10908
10907
|
})]);
|
|
10909
10908
|
} finally {
|
|
10910
|
-
clearTimeout(
|
|
10909
|
+
clearTimeout(timer);
|
|
10911
10910
|
}
|
|
10912
10911
|
}
|
|
10913
10912
|
|
|
@@ -11017,11 +11016,11 @@ class NativeLiveProducer {
|
|
|
11017
11016
|
this.state("blocked", detail);
|
|
11018
11017
|
return;
|
|
11019
11018
|
}
|
|
11020
|
-
const
|
|
11019
|
+
const timer = setTimeout(() => {
|
|
11021
11020
|
if (generation === this.generation)
|
|
11022
11021
|
this.schedule();
|
|
11023
11022
|
}, 250 * ++this.retries);
|
|
11024
|
-
|
|
11023
|
+
timer.unref?.();
|
|
11025
11024
|
}
|
|
11026
11025
|
async teardown() {
|
|
11027
11026
|
clearInterval(this.heartbeat);
|
|
@@ -11090,14 +11089,14 @@ class NativeLiveProducer {
|
|
|
11090
11089
|
const ws = new WebSocket(this.options.mediaUrl, { maxPayload: 2048, perMessageDeflate: false });
|
|
11091
11090
|
this.socket = ws;
|
|
11092
11091
|
try {
|
|
11093
|
-
await new Promise((
|
|
11094
|
-
const
|
|
11092
|
+
await new Promise((resolve, reject) => {
|
|
11093
|
+
const timer = setTimeout(() => {
|
|
11095
11094
|
ws.terminate();
|
|
11096
11095
|
reject(new Error("Media timeout"));
|
|
11097
11096
|
}, 5000);
|
|
11098
11097
|
const done = (error) => {
|
|
11099
|
-
clearTimeout(
|
|
11100
|
-
error ? reject(error) :
|
|
11098
|
+
clearTimeout(timer);
|
|
11099
|
+
error ? reject(error) : resolve();
|
|
11101
11100
|
};
|
|
11102
11101
|
ws.once("open", () => ws.send(JSON.stringify({ type: "auth", token: this.options.token, instanceId: this.options.instanceId, credentialEpoch: this.options.credentialEpoch })));
|
|
11103
11102
|
ws.once("error", () => done(new Error("Media unavailable")));
|
|
@@ -11248,11 +11247,11 @@ var SHOW_INTERVAL_MS = 1000;
|
|
|
11248
11247
|
var DIALOG_TYPES2 = new Set(["alert", "confirm", "prompt", "beforeunload", "passkey", "http_auth"]);
|
|
11249
11248
|
var MODIFIERS = Object.entries(LIVE_MODIFIERS);
|
|
11250
11249
|
async function bounded4(work, ms) {
|
|
11251
|
-
let
|
|
11252
|
-
await Promise.race([work.catch(() => {}), new Promise((
|
|
11253
|
-
|
|
11250
|
+
let timer;
|
|
11251
|
+
await Promise.race([work.catch(() => {}), new Promise((resolve) => {
|
|
11252
|
+
timer = setTimeout(resolve, ms);
|
|
11254
11253
|
})]);
|
|
11255
|
-
clearTimeout(
|
|
11254
|
+
clearTimeout(timer);
|
|
11256
11255
|
}
|
|
11257
11256
|
|
|
11258
11257
|
class TakeoverInput {
|
|
@@ -11401,9 +11400,9 @@ class TakeoverInput {
|
|
|
11401
11400
|
this.reportDialog(tabId, dialog);
|
|
11402
11401
|
}));
|
|
11403
11402
|
this.report(group);
|
|
11404
|
-
const
|
|
11405
|
-
if (
|
|
11406
|
-
this.reportDialog(tabId,
|
|
11403
|
+
const open = events?.dialogDetails();
|
|
11404
|
+
if (open)
|
|
11405
|
+
this.reportDialog(tabId, open);
|
|
11407
11406
|
}
|
|
11408
11407
|
close(session) {
|
|
11409
11408
|
session.ended = true;
|
|
@@ -11414,8 +11413,8 @@ class TakeoverInput {
|
|
|
11414
11413
|
}
|
|
11415
11414
|
this.queue = this.queue.filter((item) => item.session !== session);
|
|
11416
11415
|
let finish;
|
|
11417
|
-
const released = new Promise((
|
|
11418
|
-
finish =
|
|
11416
|
+
const released = new Promise((resolve) => {
|
|
11417
|
+
finish = resolve;
|
|
11419
11418
|
});
|
|
11420
11419
|
this.releases.set(session.tabId, released);
|
|
11421
11420
|
released.then(() => {
|
|
@@ -11483,8 +11482,8 @@ class TakeoverInput {
|
|
|
11483
11482
|
return;
|
|
11484
11483
|
this.pumping = (async () => {
|
|
11485
11484
|
while (this.queue.length) {
|
|
11486
|
-
const
|
|
11487
|
-
const { session, event } =
|
|
11485
|
+
const item = this.queue.shift();
|
|
11486
|
+
const { session, event } = item;
|
|
11488
11487
|
try {
|
|
11489
11488
|
if (event.kind !== "release_all") {
|
|
11490
11489
|
if (session.ended)
|
|
@@ -11496,17 +11495,17 @@ class TakeoverInput {
|
|
|
11496
11495
|
}
|
|
11497
11496
|
await bounded4(this.dispatch(session, event), STEP_TIMEOUT_MS);
|
|
11498
11497
|
} finally {
|
|
11499
|
-
|
|
11498
|
+
item.done?.();
|
|
11500
11499
|
}
|
|
11501
11500
|
}
|
|
11502
11501
|
})().finally(() => {
|
|
11503
11502
|
this.pumping = undefined;
|
|
11504
11503
|
});
|
|
11505
11504
|
}
|
|
11506
|
-
keyName(
|
|
11505
|
+
keyName(key, mac) {
|
|
11507
11506
|
if (mac === this.options.hostMac)
|
|
11508
|
-
return
|
|
11509
|
-
return
|
|
11507
|
+
return key;
|
|
11508
|
+
return key === "Meta" ? "Control" : key === "Control" ? "Meta" : key;
|
|
11510
11509
|
}
|
|
11511
11510
|
modifierMask(mask, mac) {
|
|
11512
11511
|
if (mac === this.options.hostMac)
|
|
@@ -11568,8 +11567,8 @@ class TakeoverInput {
|
|
|
11568
11567
|
await page.mouse.wheel(event.deltaX, event.deltaY);
|
|
11569
11568
|
return;
|
|
11570
11569
|
case "key": {
|
|
11571
|
-
const
|
|
11572
|
-
const id = event.code ||
|
|
11570
|
+
const key = this.keyName(event.key, event.mac);
|
|
11571
|
+
const id = event.code || key;
|
|
11573
11572
|
if (event.type === "up") {
|
|
11574
11573
|
const pressed = session.keys.get(id);
|
|
11575
11574
|
if (pressed === undefined)
|
|
@@ -11578,13 +11577,13 @@ class TakeoverInput {
|
|
|
11578
11577
|
await page.keyboard.up(pressed);
|
|
11579
11578
|
return;
|
|
11580
11579
|
}
|
|
11581
|
-
session.keys.set(id,
|
|
11580
|
+
session.keys.set(id, key);
|
|
11582
11581
|
try {
|
|
11583
|
-
await page.keyboard.down(
|
|
11582
|
+
await page.keyboard.down(key);
|
|
11584
11583
|
} catch (error) {
|
|
11585
11584
|
session.keys.delete(id);
|
|
11586
|
-
if (error instanceof Error && /Unknown key/.test(error.message) && [...
|
|
11587
|
-
await page.keyboard.insertText(
|
|
11585
|
+
if (error instanceof Error && /Unknown key/.test(error.message) && [...key].length === 1)
|
|
11586
|
+
await page.keyboard.insertText(key);
|
|
11588
11587
|
}
|
|
11589
11588
|
return;
|
|
11590
11589
|
}
|
|
@@ -11677,7 +11676,7 @@ class TakeoverInput {
|
|
|
11677
11676
|
}
|
|
11678
11677
|
async syncModifiers(session, mask) {
|
|
11679
11678
|
for (const [name, bit] of MODIFIERS) {
|
|
11680
|
-
const held = [...session.keys].filter(([,
|
|
11679
|
+
const held = [...session.keys].filter(([, key]) => key === name);
|
|
11681
11680
|
if (mask & bit) {
|
|
11682
11681
|
if (held.length)
|
|
11683
11682
|
continue;
|
|
@@ -11727,16 +11726,16 @@ class TakeoverInput {
|
|
|
11727
11726
|
const at = Number.isFinite(local.x) && Number.isFinite(local.y) ? local : { x: 0, y: 0 };
|
|
11728
11727
|
if (route.drag?.data && route.buttons.size)
|
|
11729
11728
|
await route.target.drag("dragCancel", at, route.drag.data).catch(() => {});
|
|
11730
|
-
for (const
|
|
11731
|
-
route.buttons.delete(
|
|
11732
|
-
await route.target.release(at,
|
|
11729
|
+
for (const button of [...route.buttons]) {
|
|
11730
|
+
route.buttons.delete(button);
|
|
11731
|
+
await route.target.release(at, button, 1, buttonBits(route.buttons)).catch(() => {});
|
|
11733
11732
|
}
|
|
11734
11733
|
this.unroute(session);
|
|
11735
11734
|
}
|
|
11736
|
-
for (const
|
|
11737
|
-
await session.page.mouse.up({ button
|
|
11738
|
-
for (const
|
|
11739
|
-
await session.page.keyboard.up(
|
|
11735
|
+
for (const button of buttons)
|
|
11736
|
+
await session.page.mouse.up({ button }).catch(() => {});
|
|
11737
|
+
for (const key of keys)
|
|
11738
|
+
await session.page.keyboard.up(key).catch(() => {});
|
|
11740
11739
|
}
|
|
11741
11740
|
async answerDialog(events, event) {
|
|
11742
11741
|
if (!events)
|
|
@@ -11770,10 +11769,10 @@ function wireResult(op, value) {
|
|
|
11770
11769
|
const opaque = ["output", "inputSchema", "annotations", "originalAction"];
|
|
11771
11770
|
if (op === "run_js")
|
|
11772
11771
|
opaque.push("result");
|
|
11773
|
-
for (const
|
|
11774
|
-
if (output[
|
|
11775
|
-
output[`${
|
|
11776
|
-
delete output[
|
|
11772
|
+
for (const key of opaque)
|
|
11773
|
+
if (output[key] !== undefined) {
|
|
11774
|
+
output[`${key}Json`] = JSON.stringify(output[key]);
|
|
11775
|
+
delete output[key];
|
|
11777
11776
|
}
|
|
11778
11777
|
if (op === "webmcp_list" && Array.isArray(output.tools))
|
|
11779
11778
|
output.tools = output.tools.map((tool) => wireResult("tool-description", tool));
|
|
@@ -11785,9 +11784,9 @@ function wireResult(op, value) {
|
|
|
11785
11784
|
output.newRuntimeTabIds = output.newTabIds;
|
|
11786
11785
|
delete output.newTabIds;
|
|
11787
11786
|
}
|
|
11788
|
-
for (const
|
|
11789
|
-
if (output[
|
|
11790
|
-
output[
|
|
11787
|
+
for (const key of ["tab", "observation"])
|
|
11788
|
+
if (output[key])
|
|
11789
|
+
output[key] = wireResult("metadata", output[key]);
|
|
11791
11790
|
if (Array.isArray(output.tabs))
|
|
11792
11791
|
output.tabs = output.tabs.map((tab) => wireResult("metadata", tab));
|
|
11793
11792
|
if (op === "batch" && Array.isArray(output.results))
|
|
@@ -11820,27 +11819,27 @@ class Relay {
|
|
|
11820
11819
|
const quarantined = !!active && (active.timedOut || active.interrupted);
|
|
11821
11820
|
return { state: this.state, paused: this.paused, queueDepth: this.waiting.filter((w) => !scope || sameScope3(w.message.scope, scope)).length, queueDepthScope: scope ? "this_scope" : "runtime", queueLimits: QUEUE_LIMITS, admission: quarantined ? "blocked" : active || this.waiting.length ? "queueing" : "ready", quarantined, operation: active ? this.blocker(active, scope) : null, recent: this.recent.filter((r) => !scope || sameScope3(r.scope, scope)).map((r) => r.result) };
|
|
11822
11821
|
}
|
|
11823
|
-
interrupt(
|
|
11822
|
+
interrupt(code = "queue_interrupted") {
|
|
11824
11823
|
this.active?.interrupt();
|
|
11825
|
-
this.flushWaiting(
|
|
11824
|
+
this.flushWaiting(code, "The runtime was interrupted. Waiting work was never dispatched; reconnect and re-observe before submitting a fresh request.");
|
|
11826
11825
|
}
|
|
11827
|
-
rejectWaiting(entry,
|
|
11826
|
+
rejectWaiting(entry, code, message, recovery) {
|
|
11828
11827
|
const index = this.waiting.indexOf(entry);
|
|
11829
11828
|
if (index < 0)
|
|
11830
11829
|
return;
|
|
11831
11830
|
this.waiting.splice(index, 1);
|
|
11832
11831
|
clearTimeout(entry.timer);
|
|
11833
|
-
const result = { operationId: entry.message.id, category:
|
|
11834
|
-
entry.send({ type: "result", id: entry.message.id, ok: false, outcome: "not_dispatched", error: { code
|
|
11832
|
+
const result = { operationId: entry.message.id, category: code, executionState: "not_started", rejectedBeforeAdmission: true, retrySafe: true, cancellationConfirmed: true, quarantined: !!this.active && (this.active.timedOut || this.active.interrupted), recovery: recovery ?? "This request was never dispatched. Check browser_runtime_health and current target/authority before submitting a fresh request ID; never replay the blocking operation." };
|
|
11833
|
+
entry.send({ type: "result", id: entry.message.id, ok: false, outcome: "not_dispatched", error: { code, message }, result });
|
|
11835
11834
|
this.recent.push({ scope: entry.message.scope, result });
|
|
11836
11835
|
if (this.recent.length > 32)
|
|
11837
11836
|
this.recent.shift();
|
|
11838
11837
|
entry.finish();
|
|
11839
11838
|
}
|
|
11840
|
-
flushWaiting(
|
|
11839
|
+
flushWaiting(code, message, scope) {
|
|
11841
11840
|
for (const entry of [...this.waiting])
|
|
11842
11841
|
if (!scope || sameScope3(entry.message.scope, scope))
|
|
11843
|
-
this.rejectWaiting(entry,
|
|
11842
|
+
this.rejectWaiting(entry, code, message);
|
|
11844
11843
|
}
|
|
11845
11844
|
cancel(id, socket, reason) {
|
|
11846
11845
|
const entry = this.waiting.find((w) => w.message.id === id && w.socket === socket);
|
|
@@ -11938,14 +11937,14 @@ class Relay {
|
|
|
11938
11937
|
const active = this.active;
|
|
11939
11938
|
if (!active || active.settled || active.tabId !== tab || !INPUT_OPERATIONS.has(active.op))
|
|
11940
11939
|
return;
|
|
11941
|
-
let
|
|
11942
|
-
return Promise.race([active.done, new Promise((
|
|
11943
|
-
|
|
11944
|
-
})]).finally(() => clearTimeout(
|
|
11940
|
+
let timer;
|
|
11941
|
+
return Promise.race([active.done, new Promise((resolve) => {
|
|
11942
|
+
timer = setTimeout(resolve, Math.max(0, active.deadlineAt - Date.now()));
|
|
11943
|
+
})]).finally(() => clearTimeout(timer));
|
|
11945
11944
|
},
|
|
11946
|
-
onTabs: (tabs,
|
|
11945
|
+
onTabs: (tabs, current) => {
|
|
11947
11946
|
if (this.control)
|
|
11948
|
-
this.controlled(tabs,
|
|
11947
|
+
this.controlled(tabs, current);
|
|
11949
11948
|
},
|
|
11950
11949
|
sendEvent: (event) => {
|
|
11951
11950
|
const socket = this.socket;
|
|
@@ -11975,12 +11974,12 @@ class Relay {
|
|
|
11975
11974
|
}
|
|
11976
11975
|
this.drain();
|
|
11977
11976
|
}
|
|
11978
|
-
controlled(tabs,
|
|
11977
|
+
controlled(tabs, current) {
|
|
11979
11978
|
this.runtime.userControlledTabs = new Set(tabs);
|
|
11980
11979
|
for (const entry of [...this.waiting])
|
|
11981
11980
|
if (typeof entry.message.args?.tabId === "string" && this.runtime.userControlledTabs.has(entry.message.args.tabId) && entry.message.op !== "release_tab")
|
|
11982
11981
|
this.rejectWaiting(entry, "user_in_control", USER_IN_CONTROL_MESSAGE, USER_IN_CONTROL_RECOVERY);
|
|
11983
|
-
this.live?.setControl(
|
|
11982
|
+
this.live?.setControl(current).catch(() => {});
|
|
11984
11983
|
}
|
|
11985
11984
|
async start() {
|
|
11986
11985
|
while (!this.stopping) {
|
|
@@ -12004,12 +12003,12 @@ class Relay {
|
|
|
12004
12003
|
u.protocol = u.protocol === "https:" ? "wss:" : "ws:";
|
|
12005
12004
|
const socket = new WebSocket2(u, { maxPayload: LIMIT, handshakeTimeout: 15000, followRedirects: false });
|
|
12006
12005
|
this.socket = socket;
|
|
12007
|
-
await new Promise((
|
|
12006
|
+
await new Promise((resolve, reject) => {
|
|
12008
12007
|
socket.once("error", reject);
|
|
12009
12008
|
socket.once("close", () => {
|
|
12010
12009
|
this.interrupt("queue_disconnected");
|
|
12011
12010
|
clearInterval(heartbeat);
|
|
12012
|
-
|
|
12011
|
+
resolve();
|
|
12013
12012
|
});
|
|
12014
12013
|
const heartbeat = setInterval(() => {
|
|
12015
12014
|
if (socket.readyState === WebSocket2.OPEN)
|
|
@@ -12020,7 +12019,7 @@ class Relay {
|
|
|
12020
12019
|
if (this.paused || this.stopping || socket !== this.socket || socket.readyState !== WebSocket2.OPEN)
|
|
12021
12020
|
return;
|
|
12022
12021
|
this.state = "authenticating";
|
|
12023
|
-
socket.send(JSON.stringify({ type: "auth", token: this.token, client: { protocol: 3, version:
|
|
12022
|
+
socket.send(JSON.stringify({ type: "auth", token: this.token, client: { protocol: 3, version: CLI_VERSION2, instanceId: this.runtime.instanceId, operations: [...BROWSER_OPERATIONS, ...this.runtime.plugins.flatMap((p) => p.operations), "session_end", "release_tab", "runtime_health", "runtime_recover"], capabilities: ["runtime-queue.v1", "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", "live-control.v1", "live-navigate.v1", CAPABILITIES.liveFit, BROWSER_SESSIONS_CAPABILITY, "outline-views.v1", CAPABILITIES.webmcpCallByName, CAPABILITIES.runJsRead, CAPABILITIES.actionTargets, CAPABILITIES.screenshotDelivery, CAPABILITIES.waitConditions, CAPABILITIES.httpAuth], liveView: { enabled: this.liveEnabled } } }));
|
|
12024
12023
|
});
|
|
12025
12024
|
socket.on("message", (bytes, binary) => {
|
|
12026
12025
|
if (binary || Buffer.byteLength(bytes.toString()) > LIMIT) {
|
|
@@ -12154,7 +12153,7 @@ class Relay {
|
|
|
12154
12153
|
send({ type: "result", id: message.id, ok: true, result: { ended: true }, outcome: "completed" });
|
|
12155
12154
|
return;
|
|
12156
12155
|
}
|
|
12157
|
-
const reject = (
|
|
12156
|
+
const reject = (code, text, extra = {}) => send({ type: "result", id: message.id, ok: false, outcome: "not_dispatched", error: { code, message: text }, result: { operationId: message.id, category: code, executionState: "not_started", rejectedBeforeAdmission: true, retrySafe: true, quarantined: false, ...extra } });
|
|
12158
12157
|
if (this.active && (this.active.timedOut || this.active.interrupted)) {
|
|
12159
12158
|
reject("blocked_by_prior_operation", "A prior operation is quarantined. No action was queued or dispatched.", { category: "runtime_quarantined", blocker: this.blocker(this.active, message.scope), quarantined: true, recovery: "Call browser_runtime_health. Never replay the prior mutation; wait for natural late settlement or request approved recovery." });
|
|
12160
12159
|
return;
|
|
@@ -12199,11 +12198,11 @@ class Relay {
|
|
|
12199
12198
|
async execute(entry) {
|
|
12200
12199
|
const { message, socket, send } = entry;
|
|
12201
12200
|
let finish, interrupt, expire;
|
|
12202
|
-
const active = { id: message.id, scope: { ...message.scope }, socket, tabId: typeof message.args.tabId === "string" ? message.args.tabId : undefined, op: message.op, startedAt: Date.now(), deadlineAt: Math.min(entry.deadlineAt, Date.now() + entry.timeoutMs), timedOut: false, interrupted: false, settled: false, recovering: false, dispatched: false, done: new Promise((
|
|
12203
|
-
finish =
|
|
12201
|
+
const active = { id: message.id, scope: { ...message.scope }, socket, tabId: typeof message.args.tabId === "string" ? message.args.tabId : undefined, op: message.op, startedAt: Date.now(), deadlineAt: Math.min(entry.deadlineAt, Date.now() + entry.timeoutMs), timedOut: false, interrupted: false, settled: false, recovering: false, dispatched: false, done: new Promise((resolve) => {
|
|
12202
|
+
finish = resolve;
|
|
12204
12203
|
}), interrupt: () => interrupt(), expire: () => expire() };
|
|
12205
12204
|
this.active = active;
|
|
12206
|
-
let stage = message.op === "screenshot" ? "screenshot_prepare" : "execute", stageStartedAt = Date.now(),
|
|
12205
|
+
let stage = message.op === "screenshot" ? "screenshot_prepare" : "execute", stageStartedAt = Date.now(), timer;
|
|
12207
12206
|
const screenshotStage = message.op === "screenshot" ? (next) => {
|
|
12208
12207
|
stage = next;
|
|
12209
12208
|
stageStartedAt = Date.now();
|
|
@@ -12212,7 +12211,7 @@ class Relay {
|
|
|
12212
12211
|
screenshotStage?.("screenshot_prepare");
|
|
12213
12212
|
const timing = () => message.op === "screenshot" ? { elapsedMs: Math.max(0, Date.now() - active.startedAt), stageElapsedMs: Math.max(0, Date.now() - stageStartedAt) } : undefined;
|
|
12214
12213
|
const screenshotUpload = new AbortController;
|
|
12215
|
-
const expired = new Promise((
|
|
12214
|
+
const expired = new Promise((resolve) => {
|
|
12216
12215
|
const terminal = (cancelled) => {
|
|
12217
12216
|
if (active.interrupted || active.settled)
|
|
12218
12217
|
return;
|
|
@@ -12227,7 +12226,7 @@ class Relay {
|
|
|
12227
12226
|
active.interrupted = true;
|
|
12228
12227
|
else
|
|
12229
12228
|
active.timedOut = true;
|
|
12230
|
-
clearTimeout(
|
|
12229
|
+
clearTimeout(timer);
|
|
12231
12230
|
screenshotUpload.abort();
|
|
12232
12231
|
if (message.op === "screenshot")
|
|
12233
12232
|
console.error(JSON.stringify({ event: "runtime_failure", diagnosticId: active.id, operationId: active.id, operation: message.op, stage, code: cancelled ? "runtime_interrupted" : "runtime_timeout", outcome: active.dispatched ? "failed" : "not_dispatched", ...timing() }));
|
|
@@ -12235,11 +12234,11 @@ class Relay {
|
|
|
12235
12234
|
this.flushWaiting("blocked_by_prior_operation", "A prior operation timed out or was interrupted. This waiting request was never dispatched.");
|
|
12236
12235
|
if (cancelled)
|
|
12237
12236
|
this.runtime.cancelOperation(active.id);
|
|
12238
|
-
|
|
12237
|
+
resolve();
|
|
12239
12238
|
};
|
|
12240
12239
|
interrupt = () => terminal(true);
|
|
12241
12240
|
expire = () => terminal(false);
|
|
12242
|
-
|
|
12241
|
+
timer = setTimeout(expire, Math.max(1, active.deadlineAt - Date.now()));
|
|
12243
12242
|
});
|
|
12244
12243
|
const task = (async () => {
|
|
12245
12244
|
let response;
|
|
@@ -12300,8 +12299,8 @@ class Relay {
|
|
|
12300
12299
|
delete item.downloadId;
|
|
12301
12300
|
}
|
|
12302
12301
|
if (message.op === "run_js" && Array.isArray(result?.artifacts)) {
|
|
12303
|
-
for (const
|
|
12304
|
-
blobs.push(await this.upload(
|
|
12302
|
+
for (const artifact of result.artifacts)
|
|
12303
|
+
blobs.push(await this.upload(artifact.base64 !== undefined ? Buffer.from(artifact.base64, "base64") : Buffer.from(artifact.content), "artifact", path10.basename(artifact.filename), artifact.mimeType ?? "text/plain"));
|
|
12305
12304
|
result.artifacts = result.artifacts.map((a) => ({ filename: path10.basename(a.filename) }));
|
|
12306
12305
|
}
|
|
12307
12306
|
if (Buffer.byteLength(JSON.stringify(result)) > 1800000)
|
|
@@ -12325,7 +12324,7 @@ class Relay {
|
|
|
12325
12324
|
response = { type: "result", id: message.id, ok: false, ...failure };
|
|
12326
12325
|
}
|
|
12327
12326
|
} finally {
|
|
12328
|
-
clearTimeout(
|
|
12327
|
+
clearTimeout(timer);
|
|
12329
12328
|
active.settled = true;
|
|
12330
12329
|
finish();
|
|
12331
12330
|
if (active.timedOut || active.interrupted)
|
|
@@ -12341,7 +12340,7 @@ class Relay {
|
|
|
12341
12340
|
}
|
|
12342
12341
|
async recover(message, send) {
|
|
12343
12342
|
const active = this.active;
|
|
12344
|
-
const reject = (
|
|
12343
|
+
const reject = (code, messageText) => send({ type: "result", id: message.id, ok: false, outcome: "not_dispatched", error: { code, message: messageText } });
|
|
12345
12344
|
if (!active || active.id !== message.args.operationId || !sameScope3(active.scope, message.scope))
|
|
12346
12345
|
return reject("recovery_unavailable", "No matching blocked operation belongs to this session.");
|
|
12347
12346
|
if (!(active.timedOut || active.interrupted) || !active.tabId || active.recovering)
|
|
@@ -12358,16 +12357,16 @@ class Relay {
|
|
|
12358
12357
|
this.active = undefined;
|
|
12359
12358
|
return { recovered: true, operationId: active.id, executionState: "target_closed", terminationConfirmed: true, originalOutcome: "unknown", retrySafe: false, replayed: false, profilePreserved: true };
|
|
12360
12359
|
})();
|
|
12361
|
-
let
|
|
12360
|
+
let timer;
|
|
12362
12361
|
try {
|
|
12363
|
-
const result = await Promise.race([work, new Promise((_,
|
|
12364
|
-
|
|
12362
|
+
const result = await Promise.race([work, new Promise((_, reject) => {
|
|
12363
|
+
timer = setTimeout(() => reject(new Error("Recovery timeout")), 5000);
|
|
12365
12364
|
})]);
|
|
12366
12365
|
send({ type: "result", id: message.id, ok: true, result, outcome: "completed" });
|
|
12367
12366
|
} catch {
|
|
12368
12367
|
send({ type: "result", id: message.id, ok: false, outcome: "unknown", error: { code: "recovery_uncertain", message: "Recovery completion is unconfirmed. Do not repeat it; query browser_runtime_health or ask the user to stop and restart this dedicated runtime." }, result: { operationId: active.id, retrySafe: false, cancellationConfirmed: false } });
|
|
12369
12368
|
} finally {
|
|
12370
|
-
clearTimeout(
|
|
12369
|
+
clearTimeout(timer);
|
|
12371
12370
|
}
|
|
12372
12371
|
}
|
|
12373
12372
|
async upload(bytes, role, name, mimeType, signal = AbortSignal.timeout(30000)) {
|
|
@@ -12431,38 +12430,38 @@ class SecretVault {
|
|
|
12431
12430
|
metadata(e) {
|
|
12432
12431
|
return { vaultId: e.id, names: Object.keys(e.values), count: Object.keys(e.values).length, expiresAt: e.expiresAt, runtimeTabId: e.tabId, generation: e.generation };
|
|
12433
12432
|
}
|
|
12434
|
-
async capture(scope, tabId,
|
|
12435
|
-
if (
|
|
12433
|
+
async capture(scope, tabId, code, frames) {
|
|
12434
|
+
if (code.length > 65536)
|
|
12436
12435
|
throw new Error("Capture rejected");
|
|
12437
|
-
const epoch = this.epoch,
|
|
12436
|
+
const epoch = this.epoch, target = await this.access.resolveTarget(tabId, scope, frames);
|
|
12438
12437
|
try {
|
|
12439
|
-
let
|
|
12440
|
-
const values = await Promise.race([this.access.suppressDiagnostics(tabId, () =>
|
|
12441
|
-
const
|
|
12438
|
+
let timer;
|
|
12439
|
+
const values = await Promise.race([this.access.suppressDiagnostics(tabId, () => target.frame.evaluate(async ({ code, limits }) => {
|
|
12440
|
+
const values = Object.create(null);
|
|
12442
12441
|
let bytes = 0;
|
|
12443
12442
|
const helper = Object.freeze({ secrets: Object.freeze({ set: async (name, value) => {
|
|
12444
|
-
if (typeof name !== "string" || name.length > 128 || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) || typeof value !== "string" || Object.hasOwn(
|
|
12443
|
+
if (typeof name !== "string" || name.length > 128 || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) || typeof value !== "string" || Object.hasOwn(values, name) || Object.keys(values).length >= limits.count)
|
|
12445
12444
|
throw new Error("Capture rejected");
|
|
12446
12445
|
const size = new TextEncoder().encode(value).length;
|
|
12447
12446
|
if (size > limits.value || (bytes += size + name.length + 64) > limits.secret)
|
|
12448
12447
|
throw new Error("Capture rejected");
|
|
12449
|
-
|
|
12448
|
+
values[name] = value;
|
|
12450
12449
|
} }) });
|
|
12451
12450
|
const AsyncFunction = Object.getPrototypeOf(async function() {}).constructor;
|
|
12452
12451
|
try {
|
|
12453
|
-
await new AsyncFunction("browserMcp",
|
|
12454
|
-
return
|
|
12452
|
+
await new AsyncFunction("browserMcp", code)(helper);
|
|
12453
|
+
return values;
|
|
12455
12454
|
} catch {
|
|
12456
12455
|
throw new Error("Capture failed");
|
|
12457
12456
|
}
|
|
12458
|
-
}, { code
|
|
12459
|
-
|
|
12460
|
-
|
|
12457
|
+
}, { code, limits: LIMITS })), new Promise((_resolve, reject) => {
|
|
12458
|
+
timer = setTimeout(() => reject(new Error("Capture timeout")), 15000);
|
|
12459
|
+
timer.unref?.();
|
|
12461
12460
|
})]).finally(() => {
|
|
12462
|
-
if (
|
|
12463
|
-
clearTimeout(
|
|
12461
|
+
if (timer)
|
|
12462
|
+
clearTimeout(timer);
|
|
12464
12463
|
});
|
|
12465
|
-
|
|
12464
|
+
target.assertCurrent();
|
|
12466
12465
|
if (epoch !== this.epoch)
|
|
12467
12466
|
throw new Error("Capture invalidated");
|
|
12468
12467
|
this.sweep();
|
|
@@ -12482,7 +12481,7 @@ class SecretVault {
|
|
|
12482
12481
|
}
|
|
12483
12482
|
if (!Object.keys(clean).length || Object.keys(clean).length > LIMITS.count || total + 1024 > LIMITS.secret)
|
|
12484
12483
|
throw new Error("Vault quota exceeded");
|
|
12485
|
-
const entry = { id: randomUUID6(), scope: { ...scope }, tabId, document:
|
|
12484
|
+
const entry = { id: randomUUID6(), scope: { ...scope }, tabId, document: target.document, generation: target.generation, origin: new URL(target.frame.url()).origin, expiresAt: Date.now() + LIMITS.ttl, values: clean };
|
|
12486
12485
|
this.entries.set(entry.id, entry);
|
|
12487
12486
|
return this.metadata(entry);
|
|
12488
12487
|
} catch {
|
|
@@ -12507,11 +12506,11 @@ class SecretVault {
|
|
|
12507
12506
|
const e = this.entries.get(id);
|
|
12508
12507
|
if (!e || !sameScope(e.scope, scope) || !names.length || new Set(names).size !== names.length)
|
|
12509
12508
|
throw new Error("Unknown secret selection");
|
|
12510
|
-
const
|
|
12511
|
-
|
|
12509
|
+
const target = await this.access.resolveDocument(e.tabId, scope, e.document);
|
|
12510
|
+
target.assertCurrent();
|
|
12512
12511
|
if (epoch !== this.epoch || this.entries.get(id) !== e || e.expiresAt <= Date.now())
|
|
12513
12512
|
throw new Error("Secret export invalidated");
|
|
12514
|
-
if (new URL(
|
|
12513
|
+
if (new URL(target.frame.url()).origin !== e.origin)
|
|
12515
12514
|
throw new Error("Stale secret document");
|
|
12516
12515
|
const selected = Object.create(null);
|
|
12517
12516
|
for (const name of names) {
|
|
@@ -12520,7 +12519,7 @@ class SecretVault {
|
|
|
12520
12519
|
selected[name] = e.values[name];
|
|
12521
12520
|
}
|
|
12522
12521
|
return { bytes: Buffer.from(serializeSecrets(selected, format)), tabId: e.tabId, document: e.document, assertCurrent: () => {
|
|
12523
|
-
|
|
12522
|
+
target.assertCurrent();
|
|
12524
12523
|
if (epoch !== this.epoch || this.entries.get(id) !== e || e.expiresAt <= Date.now())
|
|
12525
12524
|
throw new Error("Secret export invalidated");
|
|
12526
12525
|
} };
|
|
@@ -12531,11 +12530,11 @@ class SecretVault {
|
|
|
12531
12530
|
const e = this.entries.get(id);
|
|
12532
12531
|
if (!e || !sameScope(e.scope, scope) || !Object.hasOwn(e.values, names.username) || !Object.hasOwn(e.values, names.password))
|
|
12533
12532
|
throw new Error("Unknown secret selection");
|
|
12534
|
-
const
|
|
12535
|
-
|
|
12533
|
+
const target = await this.access.resolveDocument(e.tabId, scope, e.document);
|
|
12534
|
+
target.assertCurrent();
|
|
12536
12535
|
if (epoch !== this.epoch || this.entries.get(id) !== e || e.expiresAt <= Date.now())
|
|
12537
12536
|
throw new Error("Secret selection invalidated");
|
|
12538
|
-
if (new URL(
|
|
12537
|
+
if (new URL(target.frame.url()).origin !== e.origin)
|
|
12539
12538
|
throw new Error("Stale secret document");
|
|
12540
12539
|
return { username: e.values[names.username], password: e.values[names.password] };
|
|
12541
12540
|
}
|
|
@@ -12560,15 +12559,15 @@ var SETTLEMENT_WAIT_MS = 5000;
|
|
|
12560
12559
|
function within(promise, ms) {
|
|
12561
12560
|
if (!promise)
|
|
12562
12561
|
return Promise.resolve(undefined);
|
|
12563
|
-
return new Promise((
|
|
12564
|
-
const
|
|
12565
|
-
|
|
12562
|
+
return new Promise((resolve) => {
|
|
12563
|
+
const timer = setTimeout(() => resolve(undefined), ms);
|
|
12564
|
+
timer.unref?.();
|
|
12566
12565
|
promise.then((value) => {
|
|
12567
|
-
clearTimeout(
|
|
12568
|
-
|
|
12566
|
+
clearTimeout(timer);
|
|
12567
|
+
resolve(value);
|
|
12569
12568
|
}, () => {
|
|
12570
|
-
clearTimeout(
|
|
12571
|
-
|
|
12569
|
+
clearTimeout(timer);
|
|
12570
|
+
resolve(undefined);
|
|
12572
12571
|
});
|
|
12573
12572
|
});
|
|
12574
12573
|
}
|
|
@@ -12578,8 +12577,8 @@ function captureEvidence() {
|
|
|
12578
12577
|
function reasonFor(error) {
|
|
12579
12578
|
if (error instanceof CaptureError)
|
|
12580
12579
|
return error.reason;
|
|
12581
|
-
const
|
|
12582
|
-
return typeof
|
|
12580
|
+
const code = error?.code;
|
|
12581
|
+
return typeof code === "string" && filesystemReasons.has(code) ? code : "unknown";
|
|
12583
12582
|
}
|
|
12584
12583
|
async function sourceAvailability(source) {
|
|
12585
12584
|
if (!source.path)
|
|
@@ -12601,9 +12600,9 @@ async function sourceAvailability(source) {
|
|
|
12601
12600
|
class CaptureError extends Error {
|
|
12602
12601
|
code;
|
|
12603
12602
|
reason;
|
|
12604
|
-
constructor(
|
|
12605
|
-
super(
|
|
12606
|
-
this.code =
|
|
12603
|
+
constructor(code, reason = "unknown") {
|
|
12604
|
+
super(code);
|
|
12605
|
+
this.code = code;
|
|
12607
12606
|
this.reason = reason;
|
|
12608
12607
|
}
|
|
12609
12608
|
}
|
|
@@ -12641,7 +12640,7 @@ async function captureDownload(browserSource, destination, signal, evidence) {
|
|
|
12641
12640
|
const hooks = browserSource.hooks ?? {};
|
|
12642
12641
|
let operation = "completion";
|
|
12643
12642
|
let source;
|
|
12644
|
-
let
|
|
12643
|
+
let retained;
|
|
12645
12644
|
try {
|
|
12646
12645
|
const failure = await duringCapture(download.failure(), signal);
|
|
12647
12646
|
evidence.browserCompletion = failure === null ? "completed" : "failed";
|
|
@@ -12649,20 +12648,20 @@ async function captureDownload(browserSource, destination, signal, evidence) {
|
|
|
12649
12648
|
throw new CaptureError("download_capture_browser_failed", "browser-failed");
|
|
12650
12649
|
hooks.completed?.();
|
|
12651
12650
|
operation = "path";
|
|
12652
|
-
const
|
|
12651
|
+
const path = await duringCapture(download.path(), signal);
|
|
12653
12652
|
signal.throwIfAborted();
|
|
12654
12653
|
evidence.stage = "browser-file";
|
|
12655
|
-
if (dirname2(resolve2(
|
|
12654
|
+
if (dirname2(resolve2(path)) !== resolve2(browserSource.directory) || browserSource.path && path !== browserSource.path)
|
|
12656
12655
|
throw new CaptureError("download_capture_source_unavailable", "unsafe-path");
|
|
12657
|
-
browserSource.path =
|
|
12658
|
-
const guid = basename(
|
|
12656
|
+
browserSource.path = path;
|
|
12657
|
+
const guid = basename(path);
|
|
12659
12658
|
if (hooks.claim && !hooks.claim(guid))
|
|
12660
12659
|
throw new CaptureError("download_capture_source_unavailable", "source-changed");
|
|
12661
12660
|
const settled = await duringCapture(within(hooks.settlement?.(guid), SETTLEMENT_WAIT_MS), signal);
|
|
12662
12661
|
if (settled?.state === "completed" && settled.filePath && hooks.isSpoolPath && !hooks.isSpoolPath(settled.filePath, guid))
|
|
12663
12662
|
throw new CaptureError("download_capture_source_unavailable", "outside-spool");
|
|
12664
12663
|
operation = "open";
|
|
12665
|
-
source = await open2(
|
|
12664
|
+
source = await open2(path, constants3.O_RDONLY | constants3.O_NOFOLLOW | constants3.O_NONBLOCK);
|
|
12666
12665
|
operation = "stat";
|
|
12667
12666
|
const before = await source.stat();
|
|
12668
12667
|
if (!before.isFile())
|
|
@@ -12693,13 +12692,13 @@ async function captureDownload(browserSource, destination, signal, evidence) {
|
|
|
12693
12692
|
evidence.browser.sha256 = sourceHash;
|
|
12694
12693
|
evidence.stage = "verification";
|
|
12695
12694
|
operation = "verification";
|
|
12696
|
-
|
|
12697
|
-
const disk = await
|
|
12695
|
+
retained = await open2(destination, constants3.O_RDONLY | constants3.O_NOFOLLOW);
|
|
12696
|
+
const disk = await retained.stat();
|
|
12698
12697
|
if (!disk.isFile() || disk.size > LIMITS.file)
|
|
12699
12698
|
throw new CaptureError("download_capture_mismatch");
|
|
12700
12699
|
let diskSize = 0;
|
|
12701
12700
|
const diskHash = createHash6("sha256");
|
|
12702
|
-
for await (const chunk of
|
|
12701
|
+
for await (const chunk of retained.createReadStream({ start: 0, autoClose: false, signal })) {
|
|
12703
12702
|
diskSize += chunk.length;
|
|
12704
12703
|
if (diskSize > LIMITS.file)
|
|
12705
12704
|
throw new CaptureError("download_quota_exceeded", "quota-exceeded");
|
|
@@ -12707,7 +12706,7 @@ async function captureDownload(browserSource, destination, signal, evidence) {
|
|
|
12707
12706
|
}
|
|
12708
12707
|
evidence.retained = { size: diskSize, sha256: diskHash.digest("hex") };
|
|
12709
12708
|
const after = await source.stat();
|
|
12710
|
-
const diskAfter = await
|
|
12709
|
+
const diskAfter = await retained.stat();
|
|
12711
12710
|
if (size !== before.size || disk.size !== size || diskSize !== size || evidence.retained.sha256 !== sourceHash || after.size !== before.size || after.mtimeMs !== before.mtimeMs || after.ctimeMs !== before.ctimeMs || diskAfter.size !== disk.size || diskAfter.mtimeMs !== disk.mtimeMs || diskAfter.ctimeMs !== disk.ctimeMs) {
|
|
12712
12711
|
evidence.comparison = "mismatched";
|
|
12713
12712
|
throw new CaptureError("download_capture_mismatch", "source-changed");
|
|
@@ -12722,24 +12721,24 @@ async function captureDownload(browserSource, destination, signal, evidence) {
|
|
|
12722
12721
|
evidence.sourceAvailability = ["unsafe-path", "source-changed", "not-regular-file", "ELOOP"].includes(reason) ? "unsafe" : await sourceAvailability(browserSource);
|
|
12723
12722
|
throw error instanceof CaptureError ? error : new CaptureError(signal.aborted ? "download_capture_cancelled" : ["path", "open", "stat"].includes(operation) ? "download_capture_source_unavailable" : "download_capture_failed", reason);
|
|
12724
12723
|
} finally {
|
|
12725
|
-
await
|
|
12724
|
+
await retained?.close().catch(() => {});
|
|
12726
12725
|
await source?.close().catch(() => {});
|
|
12727
12726
|
}
|
|
12728
12727
|
}
|
|
12729
12728
|
async function cleanupDownload(source, evidence) {
|
|
12730
12729
|
const hooks = source.hooks ?? {};
|
|
12731
|
-
let
|
|
12730
|
+
let timer;
|
|
12732
12731
|
try {
|
|
12733
12732
|
const outcome = await Promise.race([
|
|
12734
12733
|
(async () => {
|
|
12735
12734
|
let failed = false;
|
|
12736
12735
|
if (!source.path) {
|
|
12737
|
-
const
|
|
12736
|
+
const path = await source.download.path().catch(() => {
|
|
12738
12737
|
failed = true;
|
|
12739
12738
|
return;
|
|
12740
12739
|
});
|
|
12741
|
-
if (
|
|
12742
|
-
source.path =
|
|
12740
|
+
if (path && dirname2(resolve2(path)) === resolve2(source.directory))
|
|
12741
|
+
source.path = path;
|
|
12743
12742
|
}
|
|
12744
12743
|
if (source.path && hooks.claim && !hooks.claim(basename(source.path)))
|
|
12745
12744
|
return true;
|
|
@@ -12758,9 +12757,9 @@ async function cleanupDownload(source, evidence) {
|
|
|
12758
12757
|
return reasonFor(error) === "ENOENT";
|
|
12759
12758
|
}
|
|
12760
12759
|
})(),
|
|
12761
|
-
new Promise((
|
|
12762
|
-
|
|
12763
|
-
|
|
12760
|
+
new Promise((resolve) => {
|
|
12761
|
+
timer = setTimeout(() => resolve("timeout"), 2000);
|
|
12762
|
+
timer.unref?.();
|
|
12764
12763
|
})
|
|
12765
12764
|
]);
|
|
12766
12765
|
const deleted = outcome === "timeout" ? !source.path && !!hooks.release : outcome;
|
|
@@ -12768,7 +12767,7 @@ async function cleanupDownload(source, evidence) {
|
|
|
12768
12767
|
evidence.cleanup = deleted ? "deleted" : "browser-context";
|
|
12769
12768
|
return deleted;
|
|
12770
12769
|
} finally {
|
|
12771
|
-
clearTimeout(
|
|
12770
|
+
clearTimeout(timer);
|
|
12772
12771
|
}
|
|
12773
12772
|
}
|
|
12774
12773
|
|
|
@@ -12915,8 +12914,8 @@ async function createDataPlugin(access, options) {
|
|
|
12915
12914
|
await Promise.all([...resources.values()].filter(predicate).map(remove));
|
|
12916
12915
|
}
|
|
12917
12916
|
async function transfer(r, g) {
|
|
12918
|
-
const
|
|
12919
|
-
|
|
12917
|
+
const timer = setTimeout(() => r.abort.abort(), LIMITS.duration);
|
|
12918
|
+
timer.unref?.();
|
|
12920
12919
|
r.state = "transferring";
|
|
12921
12920
|
try {
|
|
12922
12921
|
if (r.purpose === "upload") {
|
|
@@ -12975,7 +12974,7 @@ async function createDataPlugin(access, options) {
|
|
|
12975
12974
|
owned.delete(r.path);
|
|
12976
12975
|
}
|
|
12977
12976
|
} finally {
|
|
12978
|
-
clearTimeout(
|
|
12977
|
+
clearTimeout(timer);
|
|
12979
12978
|
if (r.purpose === "secret-export") {
|
|
12980
12979
|
r.bytes?.fill(0);
|
|
12981
12980
|
r.bytes = undefined;
|
|
@@ -13013,14 +13012,14 @@ async function createDataPlugin(access, options) {
|
|
|
13013
13012
|
source.download.cancel().catch(() => {});
|
|
13014
13013
|
};
|
|
13015
13014
|
r.abort.signal.addEventListener("abort", cancel, { once: true });
|
|
13016
|
-
let
|
|
13015
|
+
let timeout;
|
|
13017
13016
|
const arm = (ms) => {
|
|
13018
|
-
clearTimeout(
|
|
13019
|
-
|
|
13017
|
+
clearTimeout(timeout);
|
|
13018
|
+
timeout = setTimeout(() => {
|
|
13020
13019
|
r.terminalCode ??= "download_capture_timeout";
|
|
13021
13020
|
r.abort.abort();
|
|
13022
13021
|
}, Math.max(1, ms));
|
|
13023
|
-
|
|
13022
|
+
timeout.unref?.();
|
|
13024
13023
|
};
|
|
13025
13024
|
arm(r.completedAt === undefined ? r.expiresAt - Date.now() : Math.min(LIMITS.duration, r.expiresAt - Date.now()));
|
|
13026
13025
|
source.hooks = { ...source.hooks, completed: () => {
|
|
@@ -13033,10 +13032,10 @@ async function createDataPlugin(access, options) {
|
|
|
13033
13032
|
const task = (async () => {
|
|
13034
13033
|
try {
|
|
13035
13034
|
await discardCopy(r);
|
|
13036
|
-
const
|
|
13037
|
-
r.path =
|
|
13038
|
-
owned.add(
|
|
13039
|
-
const verified = await captureDownload(source,
|
|
13035
|
+
const path = join2(options.directory, r.id);
|
|
13036
|
+
r.path = path;
|
|
13037
|
+
owned.add(path);
|
|
13038
|
+
const verified = await captureDownload(source, path, r.abort.signal, r.capture);
|
|
13040
13039
|
if (!valid())
|
|
13041
13040
|
throw new CaptureError("download_capture_cancelled", "cancelled");
|
|
13042
13041
|
r.size = verified.size;
|
|
@@ -13066,7 +13065,7 @@ async function createDataPlugin(access, options) {
|
|
|
13066
13065
|
} else
|
|
13067
13066
|
r.state = "cancelled";
|
|
13068
13067
|
} finally {
|
|
13069
|
-
clearTimeout(
|
|
13068
|
+
clearTimeout(timeout);
|
|
13070
13069
|
r.abort.signal.removeEventListener("abort", cancel);
|
|
13071
13070
|
}
|
|
13072
13071
|
})();
|
|
@@ -13079,7 +13078,7 @@ async function createDataPlugin(access, options) {
|
|
|
13079
13078
|
function spoolHooks(download, spool = guard) {
|
|
13080
13079
|
if (!spool)
|
|
13081
13080
|
return {};
|
|
13082
|
-
return { claim: (guid) => spool.claim(guid, download), release: () => spool.release(download), settlement: (guid) => spool.settlement(guid), isSpoolPath: (
|
|
13081
|
+
return { claim: (guid) => spool.claim(guid, download), release: () => spool.release(download), settlement: (guid) => spool.settlement(guid), isSpoolPath: (path, guid) => spool.isSpoolPath(path, guid) };
|
|
13083
13082
|
}
|
|
13084
13083
|
async function admit(download, name, scope, tabId, downloadId, hooks, directory = downloadDirectory) {
|
|
13085
13084
|
const shared = !scope, owner = scope ?? USER_SCOPE;
|
|
@@ -13137,7 +13136,7 @@ async function createDataPlugin(access, options) {
|
|
|
13137
13136
|
await admit(handle, entry.suggestedFilename, undefined, undefined, randomUUID8(), {
|
|
13138
13137
|
claim: () => true,
|
|
13139
13138
|
settlement: (guid) => spool.settlement(guid),
|
|
13140
|
-
isSpoolPath: (
|
|
13139
|
+
isSpoolPath: (path, guid) => spool.isSpoolPath(path, guid)
|
|
13141
13140
|
}, spool.directory).catch(() => {});
|
|
13142
13141
|
}
|
|
13143
13142
|
const follow = (spool) => spool.onUnattributed((entry) => {
|
|
@@ -13214,26 +13213,26 @@ async function createDataPlugin(access, options) {
|
|
|
13214
13213
|
const files = ids.map((id) => lookup(scope, id));
|
|
13215
13214
|
if (files.some((r) => r.purpose !== "upload" || r.state !== "ready" || !r.path))
|
|
13216
13215
|
throw new RuntimeFault("upload_not_ready", "Nothing was attached. Wait until browser_transfer_status reports state ready for every fileId (a staged upload whose bytes were sent), then attach again.", true);
|
|
13217
|
-
const
|
|
13216
|
+
const target = await access.resolveUploadTarget(String(args.tabId), args, scope);
|
|
13218
13217
|
try {
|
|
13219
13218
|
try {
|
|
13220
|
-
|
|
13219
|
+
target.assertCurrent();
|
|
13221
13220
|
} catch {
|
|
13222
13221
|
throw uploadRefusal.changed();
|
|
13223
13222
|
}
|
|
13224
13223
|
for (const r of files) {
|
|
13225
13224
|
r.state = "attached";
|
|
13226
|
-
r.tabId =
|
|
13227
|
-
r.document =
|
|
13225
|
+
r.tabId = target.tabId;
|
|
13226
|
+
r.document = target.document;
|
|
13228
13227
|
}
|
|
13229
13228
|
try {
|
|
13230
|
-
await
|
|
13229
|
+
await target.element.setInputFiles(files.map((r) => r.path));
|
|
13231
13230
|
} finally {
|
|
13232
|
-
access.noteAction(
|
|
13231
|
+
access.noteAction(target.tabId, "upload_files");
|
|
13233
13232
|
}
|
|
13234
13233
|
return { files: files.map(meta), attached: true };
|
|
13235
13234
|
} finally {
|
|
13236
|
-
await
|
|
13235
|
+
await target.release();
|
|
13237
13236
|
}
|
|
13238
13237
|
}
|
|
13239
13238
|
if (op === "capture_secrets")
|
|
@@ -13396,13 +13395,13 @@ var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
|
13396
13395
|
var CLOSE_GRACE_MS = 2000;
|
|
13397
13396
|
var WRITE_DELAY_MS = 500;
|
|
13398
13397
|
var REPORT_TIMEOUT_MS = 5000;
|
|
13399
|
-
var unref = (
|
|
13400
|
-
|
|
13401
|
-
return
|
|
13398
|
+
var unref = (timer) => {
|
|
13399
|
+
timer.unref?.();
|
|
13400
|
+
return timer;
|
|
13402
13401
|
};
|
|
13403
13402
|
var errno = (error) => {
|
|
13404
|
-
const
|
|
13405
|
-
return typeof
|
|
13403
|
+
const code = error?.code;
|
|
13404
|
+
return typeof code === "string" && /^[A-Z0-9_]{1,32}$/.test(code) ? code : "operation-failed";
|
|
13406
13405
|
};
|
|
13407
13406
|
var tabCount = (count) => `${count} tab${count === 1 ? "" : "s"}`;
|
|
13408
13407
|
function restorableUrl(value) {
|
|
@@ -13423,8 +13422,8 @@ async function readSavedTabs(profileDir) {
|
|
|
13423
13422
|
try {
|
|
13424
13423
|
handle = await fs11.open(path11.join(profileDir, OPEN_TABS_FILE), constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK);
|
|
13425
13424
|
} catch (error) {
|
|
13426
|
-
const
|
|
13427
|
-
return
|
|
13425
|
+
const code = errno(error);
|
|
13426
|
+
return code === "ENOENT" ? { urls: [] } : { urls: [], problem: code === "ELOOP" ? "unsafe" : "unreadable" };
|
|
13428
13427
|
}
|
|
13429
13428
|
try {
|
|
13430
13429
|
const stat = await handle.stat();
|
|
@@ -13475,9 +13474,9 @@ async function writeSavedTabs(profileDir, urls) {
|
|
|
13475
13474
|
await directory?.sync().catch(() => {});
|
|
13476
13475
|
await directory?.close().catch(() => {});
|
|
13477
13476
|
}
|
|
13478
|
-
function tabsToReopen(saved,
|
|
13477
|
+
function tabsToReopen(saved, open) {
|
|
13479
13478
|
const remaining = new Map;
|
|
13480
|
-
for (const url of
|
|
13479
|
+
for (const url of open)
|
|
13481
13480
|
remaining.set(url, (remaining.get(url) ?? 0) + 1);
|
|
13482
13481
|
return saved.filter((url) => {
|
|
13483
13482
|
const count = remaining.get(url) ?? 0;
|
|
@@ -13545,7 +13544,7 @@ class OpenTabsRecorder {
|
|
|
13545
13544
|
async reported(count) {
|
|
13546
13545
|
const deadline = Date.now() + REPORT_TIMEOUT_MS;
|
|
13547
13546
|
while (!this.frozen && this.openUrls().length < count && Date.now() < deadline)
|
|
13548
|
-
await new Promise((
|
|
13547
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
13549
13548
|
}
|
|
13550
13549
|
seen(info) {
|
|
13551
13550
|
if (this.frozen || info.type !== "page" || info.subtype)
|
|
@@ -13651,7 +13650,7 @@ async function restoreTabs(recorder, options) {
|
|
|
13651
13650
|
return result(saved.urls.length ? `Not reopening the ${tabCount(saved.urls.length)} saved by profile ${profile} (--no-restore-tabs). The tabs open when this browser stops are saved instead.` : undefined);
|
|
13652
13651
|
return result(saved.problem ? `The saved tabs of profile ${profile} could not be read (${saved.problem}); starting without them.` : undefined);
|
|
13653
13652
|
}
|
|
13654
|
-
const
|
|
13653
|
+
const open = recorder.openUrls(), urls = tabsToReopen(saved.urls, open);
|
|
13655
13654
|
let reopened = 0, failed = 0;
|
|
13656
13655
|
for (const url of urls) {
|
|
13657
13656
|
signal.throwIfAborted();
|
|
@@ -13665,7 +13664,7 @@ async function restoreTabs(recorder, options) {
|
|
|
13665
13664
|
}
|
|
13666
13665
|
if (failed && !reopened)
|
|
13667
13666
|
return result(`Could not reopen the ${tabCount(failed)} saved by profile ${profile}. They are kept for the next start, and the tabs opened now are not saved.`);
|
|
13668
|
-
recorder.reported(
|
|
13667
|
+
recorder.reported(open.length + reopened).then(() => recorder.startSaving()).catch(() => {});
|
|
13669
13668
|
const already = saved.urls.length - urls.length;
|
|
13670
13669
|
if (!reopened)
|
|
13671
13670
|
return result(`The ${tabCount(already)} saved by profile ${profile} ${already === 1 ? "was" : "were"} already open.`);
|
|
@@ -13688,31 +13687,31 @@ var ISO = (value) => typeof value === "string" && value.length <= 40 && Number.i
|
|
|
13688
13687
|
var message = (error) => error instanceof Error ? error.message : String(error);
|
|
13689
13688
|
var errno2 = (error) => error?.code;
|
|
13690
13689
|
function parseRegistry(value) {
|
|
13691
|
-
const
|
|
13690
|
+
const fail = () => {
|
|
13692
13691
|
throw new Error("it does not hold browser sessions");
|
|
13693
13692
|
};
|
|
13694
13693
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
13695
|
-
|
|
13694
|
+
fail();
|
|
13696
13695
|
const record = value;
|
|
13697
13696
|
if (record.version !== 1 || !Array.isArray(record.sessions) || record.sessions.length > MAX_BROWSER_SESSIONS)
|
|
13698
|
-
|
|
13697
|
+
fail();
|
|
13699
13698
|
const defaults = record.defaultSession ?? {};
|
|
13700
13699
|
if (!defaults || typeof defaults !== "object" || Array.isArray(defaults))
|
|
13701
|
-
|
|
13700
|
+
fail();
|
|
13702
13701
|
const defaultUse = defaults.lastUsedAt;
|
|
13703
13702
|
if (defaultUse !== undefined && !ISO(defaultUse))
|
|
13704
|
-
|
|
13703
|
+
fail();
|
|
13705
13704
|
const sessions = record.sessions.map((item) => {
|
|
13706
13705
|
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
13707
|
-
return
|
|
13706
|
+
return fail();
|
|
13708
13707
|
const { id, name, color, createdAt, lastUsedAt, ...rest } = item;
|
|
13709
13708
|
if (Object.keys(rest).length || !isBrowserSessionId(id) || typeof name !== "string" || !NAME2.test(name) || typeof color !== "string" || !/^#[0-9a-f]{6}$/.test(color) || !ISO(createdAt) || lastUsedAt !== undefined && !ISO(lastUsedAt))
|
|
13710
|
-
return
|
|
13709
|
+
return fail();
|
|
13711
13710
|
return { id, name, color, createdAt, ...lastUsedAt ? { lastUsedAt } : {} };
|
|
13712
13711
|
});
|
|
13713
13712
|
const ids = new Set(sessions.map((session) => session.id)), names = new Set(sessions.map((session) => session.name.toLowerCase()));
|
|
13714
13713
|
if (ids.size !== sessions.length || names.size !== sessions.length)
|
|
13715
|
-
|
|
13714
|
+
fail();
|
|
13716
13715
|
return { version: 1, defaultSession: defaultUse ? { lastUsedAt: defaultUse } : {}, sessions };
|
|
13717
13716
|
}
|
|
13718
13717
|
async function readRegistry(file) {
|
|
@@ -13823,10 +13822,10 @@ class BrowserSessions {
|
|
|
13823
13822
|
});
|
|
13824
13823
|
}
|
|
13825
13824
|
used(id) {
|
|
13826
|
-
const
|
|
13827
|
-
if (!
|
|
13825
|
+
const target = id === DEFAULT_BROWSER_SESSION ? this.registry.defaultSession : this.registry.sessions.find((session) => session.id === id);
|
|
13826
|
+
if (!target)
|
|
13828
13827
|
return;
|
|
13829
|
-
|
|
13828
|
+
target.lastUsedAt = new Date().toISOString();
|
|
13830
13829
|
this.usageChanged = true;
|
|
13831
13830
|
if (Date.now() - this.usageWrittenAt >= USAGE_WRITE_INTERVAL_MS)
|
|
13832
13831
|
this.flush();
|
|
@@ -13860,7 +13859,7 @@ class BrowserSessions {
|
|
|
13860
13859
|
return [this.view(DEFAULT_BROWSER_SESSION), ...this.registry.sessions.map((session) => this.view(session.id))];
|
|
13861
13860
|
}
|
|
13862
13861
|
summary() {
|
|
13863
|
-
return this.list().map(({ name, running, tabCount
|
|
13862
|
+
return this.list().map(({ name, running, tabCount }) => ({ name, running, tabCount }));
|
|
13864
13863
|
}
|
|
13865
13864
|
resolve(reference) {
|
|
13866
13865
|
const wanted = String(reference ?? DEFAULT_BROWSER_SESSION);
|
|
@@ -14138,30 +14137,30 @@ var MIN_SCREENSHOT_EDGE = 512;
|
|
|
14138
14137
|
function parse2(args) {
|
|
14139
14138
|
const options = { profiles: [] };
|
|
14140
14139
|
for (let i = 0;i < args.length; i++) {
|
|
14141
|
-
const
|
|
14142
|
-
if (
|
|
14140
|
+
const key = args[i];
|
|
14141
|
+
if (key === "--ephemeral")
|
|
14143
14142
|
options.ephemeral = true;
|
|
14144
|
-
else if (
|
|
14143
|
+
else if (key === "--live-view")
|
|
14145
14144
|
options.liveView = true;
|
|
14146
|
-
else if (
|
|
14145
|
+
else if (key === "--no-passkey-detection")
|
|
14147
14146
|
options.passkeyDetection = false;
|
|
14148
|
-
else if (
|
|
14147
|
+
else if (key === "--no-restore-tabs")
|
|
14149
14148
|
options.restoreTabs = false;
|
|
14150
|
-
else if (
|
|
14149
|
+
else if (key === "--profile" || key === "--server" || key === "--chrome-path" || key === "--screenshot-max-edge") {
|
|
14151
14150
|
if (!args[i + 1] || args[i + 1].startsWith("--"))
|
|
14152
|
-
throw new Error(`Missing ${
|
|
14151
|
+
throw new Error(`Missing ${key} value`);
|
|
14153
14152
|
const value = args[++i];
|
|
14154
|
-
if (
|
|
14153
|
+
if (key === "--profile")
|
|
14155
14154
|
options.profiles.push(value);
|
|
14156
|
-
else if (
|
|
14155
|
+
else if (key === "--screenshot-max-edge") {
|
|
14157
14156
|
const edge = Number(value);
|
|
14158
14157
|
if (!/^\d+$/.test(value) || edge < MIN_SCREENSHOT_EDGE || edge > MAX_IMAGE_DIMENSION)
|
|
14159
14158
|
throw new Error(`--screenshot-max-edge must be a whole number of pixels from ${MIN_SCREENSHOT_EDGE} to ${MAX_IMAGE_DIMENSION}`);
|
|
14160
14159
|
options.screenshotMaxEdge = edge;
|
|
14161
14160
|
} else
|
|
14162
|
-
options[
|
|
14161
|
+
options[key === "--server" ? "server" : "chrome-path"] = value;
|
|
14163
14162
|
} else
|
|
14164
|
-
throw new Error(`Unknown browser option ${
|
|
14163
|
+
throw new Error(`Unknown browser option ${key}`);
|
|
14165
14164
|
}
|
|
14166
14165
|
return options;
|
|
14167
14166
|
}
|
|
@@ -14204,7 +14203,7 @@ Dedicated Chrome only. Foreground lifecycle with loopback CDP: stopping the CLI
|
|
|
14204
14203
|
console.log(`Verified stale lock/socket cleanup complete for profile ${profile}${sessionLocks ? ` and ${sessionLocks} of its browser sessions` : ""}; profile data retained.`);
|
|
14205
14204
|
return;
|
|
14206
14205
|
}
|
|
14207
|
-
await new Promise((
|
|
14206
|
+
await new Promise((resolve, reject) => {
|
|
14208
14207
|
const socket = net3.connect(controlPath);
|
|
14209
14208
|
socket.setTimeout(5000, () => socket.destroy(new Error("Local control timeout")));
|
|
14210
14209
|
socket.once("connect", () => socket.write(JSON.stringify({ command }) + `
|
|
@@ -14212,7 +14211,7 @@ Dedicated Chrome only. Foreground lifecycle with loopback CDP: stopping the CLI
|
|
|
14212
14211
|
socket.once("data", (data) => {
|
|
14213
14212
|
console.log(data.toString().trim());
|
|
14214
14213
|
socket.end();
|
|
14215
|
-
|
|
14214
|
+
resolve();
|
|
14216
14215
|
});
|
|
14217
14216
|
socket.once("error", (error) => reject(controlFailure("control-connect", error)));
|
|
14218
14217
|
});
|
|
@@ -14366,7 +14365,7 @@ async function startProfile(root, server, profile, options, groupSignal) {
|
|
|
14366
14365
|
return;
|
|
14367
14366
|
} else if (cmd !== "status")
|
|
14368
14367
|
throw new Error("Invalid command");
|
|
14369
|
-
socket.end(JSON.stringify({ ...relay.health(), instanceId: session.instanceId, profile, version:
|
|
14368
|
+
socket.end(JSON.stringify({ ...relay.health(), instanceId: session.instanceId, profile, version: CLI_VERSION2, protocol: 3, ...sessions ? { browserSessions: sessions.summary() } : {} }) + `
|
|
14370
14369
|
`);
|
|
14371
14370
|
})().catch(() => socket.destroy());
|
|
14372
14371
|
});
|