@vforsh/argus 0.4.0 → 0.5.1
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/dist/.tsbuildinfo +1 -1
- package/dist/argus.js +1141 -561
- package/dist/cli/program.d.ts +11 -1
- package/dist/cli/program.d.ts.map +1 -1
- package/dist/cli/program.js +14 -9
- package/dist/cli/program.js.map +1 -1
- package/dist/cli/register/index.d.ts.map +1 -1
- package/dist/cli/register/index.js +2 -0
- package/dist/cli/register/index.js.map +1 -1
- package/dist/cli/register/keydownCommand.d.ts.map +1 -1
- package/dist/cli/register/keydownCommand.js +2 -1
- package/dist/cli/register/keydownCommand.js.map +1 -1
- package/dist/cli/register/sessionCommands.d.ts +3 -0
- package/dist/cli/register/sessionCommands.d.ts.map +1 -0
- package/dist/cli/register/sessionCommands.js +24 -0
- package/dist/cli/register/sessionCommands.js.map +1 -0
- package/dist/output/io.d.ts +7 -0
- package/dist/output/io.d.ts.map +1 -1
- package/dist/output/io.js +21 -2
- package/dist/output/io.js.map +1 -1
- package/dist/session/runSession.d.ts +15 -0
- package/dist/session/runSession.d.ts.map +1 -0
- package/dist/session/runSession.js +184 -0
- package/dist/session/runSession.js.map +1 -0
- package/dist/session/sessionArgv.d.ts +42 -0
- package/dist/session/sessionArgv.d.ts.map +1 -0
- package/dist/session/sessionArgv.js +224 -0
- package/dist/session/sessionArgv.js.map +1 -0
- package/dist/session/sessionDispatch.d.ts +21 -0
- package/dist/session/sessionDispatch.d.ts.map +1 -0
- package/dist/session/sessionDispatch.js +137 -0
- package/dist/session/sessionDispatch.js.map +1 -0
- package/dist/session/stdioCapture.d.ts +33 -0
- package/dist/session/stdioCapture.d.ts.map +1 -0
- package/dist/session/stdioCapture.js +56 -0
- package/dist/session/stdioCapture.js.map +1 -0
- package/dist/skill/argus/SKILL.md +30 -0
- package/dist/skill/argus/reference/INSPECT.md +4 -0
- package/dist/skill/argus/reference/SESSION.md +153 -0
- package/package.json +5 -5
package/dist/argus.js
CHANGED
|
@@ -2130,7 +2130,7 @@ var {
|
|
|
2130
2130
|
// package.json
|
|
2131
2131
|
var package_default = {
|
|
2132
2132
|
name: "@vforsh/argus",
|
|
2133
|
-
version: "0.
|
|
2133
|
+
version: "0.5.1",
|
|
2134
2134
|
repository: {
|
|
2135
2135
|
type: "git",
|
|
2136
2136
|
url: "git+https://github.com/vforsh/argus.git",
|
|
@@ -2160,10 +2160,10 @@ var package_default = {
|
|
|
2160
2160
|
access: "public"
|
|
2161
2161
|
},
|
|
2162
2162
|
dependencies: {
|
|
2163
|
-
"@vforsh/argus-client": "^0.
|
|
2164
|
-
"@vforsh/argus-core": "^0.
|
|
2165
|
-
"@vforsh/argus-plugin-api": "^0.
|
|
2166
|
-
"@vforsh/argus-watcher": "^0.
|
|
2163
|
+
"@vforsh/argus-client": "^0.5.0",
|
|
2164
|
+
"@vforsh/argus-core": "^0.5.0",
|
|
2165
|
+
"@vforsh/argus-plugin-api": "^0.5.0",
|
|
2166
|
+
"@vforsh/argus-watcher": "^0.5.0",
|
|
2167
2167
|
commander: "14.0.2",
|
|
2168
2168
|
esbuild: "0.25.12",
|
|
2169
2169
|
prettier: "3.7.4"
|
|
@@ -2178,19 +2178,23 @@ var package_default = {
|
|
|
2178
2178
|
};
|
|
2179
2179
|
|
|
2180
2180
|
// dist/cli/program.js
|
|
2181
|
-
function createProgram() {
|
|
2181
|
+
function createProgram(options = {}) {
|
|
2182
2182
|
const program2 = new Command;
|
|
2183
2183
|
program2.name("argus").description("Argus CLI for local watcher servers").version(package_default.version).option("--plugin <specifier>", "Load an extra CLI plugin for this invocation", collectPluginOption, []).configureOutput({
|
|
2184
2184
|
outputError: (str, write) => write(str)
|
|
2185
|
-
}).showSuggestionAfterError(true).enablePositionalOptions().exitOverride(
|
|
2186
|
-
if (error.code === "commander.helpDisplayed" || error.code === "commander.version") {
|
|
2187
|
-
process.exit(0);
|
|
2188
|
-
}
|
|
2189
|
-
console.error(error.message);
|
|
2190
|
-
process.exit(2);
|
|
2191
|
-
});
|
|
2185
|
+
}).showSuggestionAfterError(true).enablePositionalOptions().exitOverride(options.mode === "session" ? throwOnExit : exitProcess);
|
|
2192
2186
|
return program2;
|
|
2193
2187
|
}
|
|
2188
|
+
var throwOnExit = (error) => {
|
|
2189
|
+
throw error;
|
|
2190
|
+
};
|
|
2191
|
+
var exitProcess = (error) => {
|
|
2192
|
+
if (error.code === "commander.helpDisplayed" || error.code === "commander.version") {
|
|
2193
|
+
process.exit(0);
|
|
2194
|
+
}
|
|
2195
|
+
console.error(error.message);
|
|
2196
|
+
process.exit(2);
|
|
2197
|
+
};
|
|
2194
2198
|
var collectPluginOption = (value, previous) => [...previous, value];
|
|
2195
2199
|
|
|
2196
2200
|
// dist/cli/defineCommand.js
|
|
@@ -3571,6 +3575,11 @@ var ARGUS_ERROR_CODES = [
|
|
|
3571
3575
|
"not_interactable",
|
|
3572
3576
|
"nth_out_of_range",
|
|
3573
3577
|
"payload_too_large",
|
|
3578
|
+
"session_command_failed",
|
|
3579
|
+
"session_command_rejected",
|
|
3580
|
+
"session_invalid_request",
|
|
3581
|
+
"session_request_timeout",
|
|
3582
|
+
"session_unknown_command",
|
|
3574
3583
|
"unexpected_matches",
|
|
3575
3584
|
"unsupported_platform"
|
|
3576
3585
|
];
|
|
@@ -3640,6 +3649,53 @@ var describeProtocolMismatch = (protocolVersion, watcherVersion) => {
|
|
|
3640
3649
|
};
|
|
3641
3650
|
// ../argus-core/dist/protocol/native-messaging.js
|
|
3642
3651
|
var NATIVE_MESSAGING_PROTOCOL_VERSION = 2;
|
|
3652
|
+
// ../argus-core/dist/protocol/session.js
|
|
3653
|
+
var SESSION_PROTOCOL_VERSION = 1;
|
|
3654
|
+
var optionalRequestId = (source, key) => {
|
|
3655
|
+
const field = source[key];
|
|
3656
|
+
if (field == null) {
|
|
3657
|
+
return;
|
|
3658
|
+
}
|
|
3659
|
+
if (typeof field === "string") {
|
|
3660
|
+
return field;
|
|
3661
|
+
}
|
|
3662
|
+
if (typeof field === "number" && Number.isFinite(field)) {
|
|
3663
|
+
return field;
|
|
3664
|
+
}
|
|
3665
|
+
return fieldError(`${key} must be a string or a finite number`);
|
|
3666
|
+
};
|
|
3667
|
+
var optionalTimeout = (source, key) => {
|
|
3668
|
+
const field = source[key];
|
|
3669
|
+
if (field == null) {
|
|
3670
|
+
return;
|
|
3671
|
+
}
|
|
3672
|
+
if (typeof field === "string") {
|
|
3673
|
+
return field;
|
|
3674
|
+
}
|
|
3675
|
+
if (typeof field === "number" && Number.isFinite(field) && field > 0) {
|
|
3676
|
+
return field;
|
|
3677
|
+
}
|
|
3678
|
+
return fieldError(`${key} must be a duration string or a positive number of milliseconds`);
|
|
3679
|
+
};
|
|
3680
|
+
var SESSION_REQUEST_SCHEMA = defineProtocolSchema((value) => {
|
|
3681
|
+
const invalid = requireObject(value);
|
|
3682
|
+
if (invalid)
|
|
3683
|
+
return invalid;
|
|
3684
|
+
const source = value;
|
|
3685
|
+
const fields = readFields(source, {
|
|
3686
|
+
id: optionalRequestId,
|
|
3687
|
+
cmd: requiredString,
|
|
3688
|
+
args: optionalRecord,
|
|
3689
|
+
argv: optionalStringArray,
|
|
3690
|
+
timeout: optionalTimeout
|
|
3691
|
+
});
|
|
3692
|
+
if (!fields.ok)
|
|
3693
|
+
return fields;
|
|
3694
|
+
if (fields.value.args && fields.value.argv) {
|
|
3695
|
+
return invalidProtocolPayload("args and argv are mutually exclusive");
|
|
3696
|
+
}
|
|
3697
|
+
return { ok: true, value: compact(fields.value) };
|
|
3698
|
+
});
|
|
3643
3699
|
// ../argus-core/dist/registry/registry.js
|
|
3644
3700
|
import fs2 from "node:fs/promises";
|
|
3645
3701
|
import path3 from "node:path";
|
|
@@ -4408,9 +4464,16 @@ var ensureTrailingNewline = (value) => value.endsWith(`
|
|
|
4408
4464
|
`) ? value : `${value}
|
|
4409
4465
|
`;
|
|
4410
4466
|
var configureMachineSafeConsole = (argv) => {
|
|
4411
|
-
if (
|
|
4412
|
-
|
|
4467
|
+
if (argv.includes("--json") || argv.includes("--json-full") || isMachineOnlyCommand(argv)) {
|
|
4468
|
+
routeConsoleToStderr();
|
|
4413
4469
|
}
|
|
4470
|
+
};
|
|
4471
|
+
var MACHINE_ONLY_COMMANDS = new Set(["session"]);
|
|
4472
|
+
var isMachineOnlyCommand = (argv) => {
|
|
4473
|
+
const command = argv.find((token, index) => !token.startsWith("-") && argv[index - 1] !== "--plugin");
|
|
4474
|
+
return command != null && MACHINE_ONLY_COMMANDS.has(command);
|
|
4475
|
+
};
|
|
4476
|
+
var routeConsoleToStderr = () => {
|
|
4414
4477
|
const writeConsoleError = console.error.bind(console);
|
|
4415
4478
|
console.log = writeConsoleError;
|
|
4416
4479
|
console.info = writeConsoleError;
|
|
@@ -7211,7 +7274,7 @@ var normalizeTimeout = (value) => {
|
|
|
7211
7274
|
// ../argus-watcher/package.json
|
|
7212
7275
|
var package_default2 = {
|
|
7213
7276
|
name: "@vforsh/argus-watcher",
|
|
7214
|
-
version: "0.
|
|
7277
|
+
version: "0.5.1",
|
|
7215
7278
|
repository: {
|
|
7216
7279
|
type: "git",
|
|
7217
7280
|
url: "git+https://github.com/vforsh/argus.git",
|
|
@@ -7238,7 +7301,7 @@ var package_default2 = {
|
|
|
7238
7301
|
},
|
|
7239
7302
|
dependencies: {
|
|
7240
7303
|
"@jridgewell/trace-mapping": "^0.3.31",
|
|
7241
|
-
"@vforsh/argus-core": "^0.
|
|
7304
|
+
"@vforsh/argus-core": "^0.5.0",
|
|
7242
7305
|
emittery: "^1.2.0"
|
|
7243
7306
|
},
|
|
7244
7307
|
scripts: {
|
|
@@ -8299,9 +8362,9 @@ var netMockRoutes = [
|
|
|
8299
8362
|
];
|
|
8300
8363
|
|
|
8301
8364
|
// ../argus-watcher/dist/cdp/pageState.js
|
|
8302
|
-
var evaluateInPage = async (
|
|
8365
|
+
var evaluateInPage = async (session2, expression, options = {}) => {
|
|
8303
8366
|
const { failureMessage, awaitPromise, ...sendOptions } = options;
|
|
8304
|
-
const payload = await
|
|
8367
|
+
const payload = await session2.sendAndWait("Runtime.evaluate", {
|
|
8305
8368
|
expression,
|
|
8306
8369
|
awaitPromise: awaitPromise ?? false,
|
|
8307
8370
|
returnByValue: true
|
|
@@ -8311,17 +8374,17 @@ var evaluateInPage = async (session, expression, options = {}) => {
|
|
|
8311
8374
|
}
|
|
8312
8375
|
return payload.result?.value;
|
|
8313
8376
|
};
|
|
8314
|
-
var tryEvaluateInPage = async (
|
|
8377
|
+
var tryEvaluateInPage = async (session2, expression, options = {}) => {
|
|
8315
8378
|
try {
|
|
8316
|
-
return await evaluateInPage(
|
|
8379
|
+
return await evaluateInPage(session2, expression, options);
|
|
8317
8380
|
} catch {
|
|
8318
8381
|
return;
|
|
8319
8382
|
}
|
|
8320
8383
|
};
|
|
8321
8384
|
var formatPageException = (details, fallback = "Page evaluation failed") => details.exception?.description ?? details.text ?? fallback;
|
|
8322
|
-
var callFunctionOnNode = async (
|
|
8385
|
+
var callFunctionOnNode = async (session2, node, fn, options = {}) => {
|
|
8323
8386
|
const { onUnresolved, ...sendOptions } = options;
|
|
8324
|
-
const resolved = await
|
|
8387
|
+
const resolved = await session2.sendAndWait("DOM.resolveNode", node, sendOptions);
|
|
8325
8388
|
const objectId = resolved.object?.objectId;
|
|
8326
8389
|
if (!objectId) {
|
|
8327
8390
|
if (onUnresolved) {
|
|
@@ -8329,7 +8392,7 @@ var callFunctionOnNode = async (session, node, fn, options = {}) => {
|
|
|
8329
8392
|
}
|
|
8330
8393
|
return;
|
|
8331
8394
|
}
|
|
8332
|
-
const result = await
|
|
8395
|
+
const result = await session2.sendAndWait("Runtime.callFunctionOn", {
|
|
8333
8396
|
objectId,
|
|
8334
8397
|
functionDeclaration: fn.code,
|
|
8335
8398
|
arguments: fn.args,
|
|
@@ -8343,8 +8406,8 @@ var callFunctionOnNode = async (session, node, fn, options = {}) => {
|
|
|
8343
8406
|
};
|
|
8344
8407
|
|
|
8345
8408
|
// ../argus-watcher/dist/cdp/authPageState.js
|
|
8346
|
-
var inspectPageState = async (
|
|
8347
|
-
const state2 = await evaluateInPage(
|
|
8409
|
+
var inspectPageState = async (session2) => {
|
|
8410
|
+
const state2 = await evaluateInPage(session2, `(() => {
|
|
8348
8411
|
try {
|
|
8349
8412
|
const url = String(location.href)
|
|
8350
8413
|
const origin = new URL(url).origin
|
|
@@ -8567,9 +8630,9 @@ var normalizeSetCookieInput = (cookie) => ({
|
|
|
8567
8630
|
var normalizeCookieExpires = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
8568
8631
|
|
|
8569
8632
|
// ../argus-watcher/dist/cdp/authCookies.js
|
|
8570
|
-
var inspectAuthCookies = async (
|
|
8571
|
-
const { origin } = await inspectPageState(
|
|
8572
|
-
const raw = await readRawCookies(
|
|
8633
|
+
var inspectAuthCookies = async (session2, options) => {
|
|
8634
|
+
const { origin } = await inspectPageState(session2);
|
|
8635
|
+
const raw = await readRawCookies(session2);
|
|
8573
8636
|
const cookies2 = raw.map((cookie) => toAuthCookie(toStateCookie(cookie), options.includeValues === true)).sort(compareCookieIdentity);
|
|
8574
8637
|
const normalizedDomain = normalizeCookieDomainFilter(options.domain);
|
|
8575
8638
|
return {
|
|
@@ -8578,19 +8641,19 @@ var inspectAuthCookies = async (session, options) => {
|
|
|
8578
8641
|
cookies: cookies2.filter((cookie) => matchesCookieDomain(cookie.domain, normalizedDomain))
|
|
8579
8642
|
};
|
|
8580
8643
|
};
|
|
8581
|
-
var inspectAuthCookie = async (
|
|
8582
|
-
const pageState = await inspectPageState(
|
|
8583
|
-
const cookie = await findContextCookie(
|
|
8644
|
+
var inspectAuthCookie = async (session2, options) => {
|
|
8645
|
+
const pageState = await inspectPageState(session2);
|
|
8646
|
+
const cookie = await findContextCookie(session2, pageState, options, options.readBrowserCookies);
|
|
8584
8647
|
return {
|
|
8585
8648
|
ok: true,
|
|
8586
8649
|
origin: pageState.origin,
|
|
8587
8650
|
cookie: cookie ? toAuthCookie(cookie, options.includeValue === true) : null
|
|
8588
8651
|
};
|
|
8589
8652
|
};
|
|
8590
|
-
var setAuthCookie = async (
|
|
8591
|
-
const pageState = await inspectPageState(
|
|
8653
|
+
var setAuthCookie = async (session2, options) => {
|
|
8654
|
+
const pageState = await inspectPageState(session2);
|
|
8592
8655
|
const cookie = normalizeSetCookieInput(options.cookie);
|
|
8593
|
-
const payload = await
|
|
8656
|
+
const payload = await session2.sendAndWait("Network.setCookie", {
|
|
8594
8657
|
name: cookie.name,
|
|
8595
8658
|
value: cookie.value,
|
|
8596
8659
|
domain: cookie.domain,
|
|
@@ -8603,16 +8666,16 @@ var setAuthCookie = async (session, options) => {
|
|
|
8603
8666
|
if (payload.success === false) {
|
|
8604
8667
|
throw new Error(`Chrome rejected cookie ${cookie.name}`);
|
|
8605
8668
|
}
|
|
8606
|
-
const stored = await findContextCookie(
|
|
8669
|
+
const stored = await findContextCookie(session2, pageState, cookie, options.readBrowserCookies);
|
|
8607
8670
|
return {
|
|
8608
8671
|
ok: true,
|
|
8609
8672
|
origin: pageState.origin,
|
|
8610
8673
|
cookie: toAuthCookie(stored ?? cookie, false)
|
|
8611
8674
|
};
|
|
8612
8675
|
};
|
|
8613
|
-
var deleteAuthCookie = async (
|
|
8614
|
-
const pageState = await inspectPageState(
|
|
8615
|
-
const existing = await findContextCookie(
|
|
8676
|
+
var deleteAuthCookie = async (session2, options) => {
|
|
8677
|
+
const pageState = await inspectPageState(session2);
|
|
8678
|
+
const existing = await findContextCookie(session2, pageState, options, options.readBrowserCookies);
|
|
8616
8679
|
if (!existing) {
|
|
8617
8680
|
return {
|
|
8618
8681
|
ok: true,
|
|
@@ -8621,7 +8684,7 @@ var deleteAuthCookie = async (session, options) => {
|
|
|
8621
8684
|
cookie: toCookieIdentity(options)
|
|
8622
8685
|
};
|
|
8623
8686
|
}
|
|
8624
|
-
await deleteCookie(
|
|
8687
|
+
await deleteCookie(session2, existing);
|
|
8625
8688
|
return {
|
|
8626
8689
|
ok: true,
|
|
8627
8690
|
origin: pageState.origin,
|
|
@@ -8629,13 +8692,13 @@ var deleteAuthCookie = async (session, options) => {
|
|
|
8629
8692
|
cookie: toCookieIdentity(existing)
|
|
8630
8693
|
};
|
|
8631
8694
|
};
|
|
8632
|
-
var clearAuthCookies = async (
|
|
8633
|
-
const pageState = await inspectPageState(
|
|
8634
|
-
const cookies2 = await readStateCookies(
|
|
8695
|
+
var clearAuthCookies = async (session2, options) => {
|
|
8696
|
+
const pageState = await inspectPageState(session2);
|
|
8697
|
+
const cookies2 = await readStateCookies(session2, options.readBrowserCookies, { url: pageState.url });
|
|
8635
8698
|
const matcher = createClearCookieMatcher(pageState, options);
|
|
8636
8699
|
const targets = cookies2.filter((cookie) => matcher(cookie) && matchesCookieClearFilters(cookie, options));
|
|
8637
8700
|
for (const cookie of targets) {
|
|
8638
|
-
await deleteCookie(
|
|
8701
|
+
await deleteCookie(session2, cookie);
|
|
8639
8702
|
}
|
|
8640
8703
|
return {
|
|
8641
8704
|
ok: true,
|
|
@@ -8648,30 +8711,30 @@ var clearAuthCookies = async (session, options) => {
|
|
|
8648
8711
|
cookies: targets.map((cookie) => toCookieIdentity(cookie)).sort(compareCookieIdentity)
|
|
8649
8712
|
};
|
|
8650
8713
|
};
|
|
8651
|
-
var readStateCookies = async (
|
|
8714
|
+
var readStateCookies = async (session2, readBrowserCookiesFromSource, query2) => {
|
|
8652
8715
|
const [browserCookies, pageCookies] = await Promise.all([
|
|
8653
|
-
readBrowserCookiesFromSource ? readBrowserCookiesFromSource(query2) : readBrowserCookiesFromSession(
|
|
8654
|
-
readRawCookies(
|
|
8716
|
+
readBrowserCookiesFromSource ? readBrowserCookiesFromSource(query2) : readBrowserCookiesFromSession(session2),
|
|
8717
|
+
readRawCookies(session2)
|
|
8655
8718
|
]);
|
|
8656
8719
|
return mergeStateCookies(browserCookies, pageCookies.map(toStateCookie)).filter((cookie) => matchesCookieDomain(cookie.domain, query2.domain ?? null)).sort(compareCookieIdentity);
|
|
8657
8720
|
};
|
|
8658
|
-
var findContextCookie = async (
|
|
8659
|
-
const cookies2 = await readStateCookies(
|
|
8721
|
+
var findContextCookie = async (session2, pageState, identity, readBrowserCookiesFromSource) => {
|
|
8722
|
+
const cookies2 = await readStateCookies(session2, readBrowserCookiesFromSource, { url: pageState.url });
|
|
8660
8723
|
return cookies2.find((cookie) => matchesCookieIdentity(cookie, identity)) ?? null;
|
|
8661
8724
|
};
|
|
8662
|
-
var deleteCookie = async (
|
|
8663
|
-
await
|
|
8725
|
+
var deleteCookie = async (session2, cookie) => {
|
|
8726
|
+
await session2.sendAndWait("Network.deleteCookies", { name: cookie.name, domain: cookie.domain, path: cookie.path }, { timeoutMs: 5000 });
|
|
8664
8727
|
};
|
|
8665
|
-
var readRawCookies = async (
|
|
8666
|
-
const payload = await
|
|
8728
|
+
var readRawCookies = async (session2) => {
|
|
8729
|
+
const payload = await session2.sendAndWait("Network.getCookies", {}, { timeoutMs: 5000 });
|
|
8667
8730
|
return payload.cookies ?? [];
|
|
8668
8731
|
};
|
|
8669
|
-
var readBrowserCookiesFromSession = async (
|
|
8732
|
+
var readBrowserCookiesFromSession = async (session2) => {
|
|
8670
8733
|
try {
|
|
8671
|
-
const payload = await
|
|
8734
|
+
const payload = await session2.sendAndWait("Storage.getCookies", {}, { timeoutMs: 5000 });
|
|
8672
8735
|
return (payload.cookies ?? []).map(toStateCookie);
|
|
8673
8736
|
} catch {
|
|
8674
|
-
return (await readRawCookies(
|
|
8737
|
+
return (await readRawCookies(session2)).map(toStateCookie);
|
|
8675
8738
|
}
|
|
8676
8739
|
};
|
|
8677
8740
|
var mergeStateCookies = (...groups) => {
|
|
@@ -8751,11 +8814,11 @@ var route15 = defineJsonRoute({
|
|
|
8751
8814
|
});
|
|
8752
8815
|
|
|
8753
8816
|
// ../argus-watcher/dist/cdp/authSnapshot.js
|
|
8754
|
-
var inspectAuthState = async (
|
|
8755
|
-
const pageState = await inspectPageState(
|
|
8817
|
+
var inspectAuthState = async (session2, options) => {
|
|
8818
|
+
const pageState = await inspectPageState(session2);
|
|
8756
8819
|
const siteDomain = getLikelySiteDomain(pageState.origin);
|
|
8757
8820
|
const normalizedDomain = normalizeCookieDomainFilter(options.domain) ?? siteDomain;
|
|
8758
|
-
const cookies2 = await readStateCookies(
|
|
8821
|
+
const cookies2 = await readStateCookies(session2, options.readBrowserCookies, {
|
|
8759
8822
|
domain: normalizedDomain,
|
|
8760
8823
|
url: pageState.url
|
|
8761
8824
|
});
|
|
@@ -9008,12 +9071,12 @@ import { randomUUID as randomUUID2 } from "node:crypto";
|
|
|
9008
9071
|
var SCENARIO_ACTION_TIMEOUT_MS = 30000;
|
|
9009
9072
|
var DEFAULT_LOG_LIMIT = 500;
|
|
9010
9073
|
var MAX_LOG_LIMIT = 5000;
|
|
9011
|
-
var installScenarioBridge = async (
|
|
9074
|
+
var installScenarioBridge = async (session2, expression, args, services, timeoutMs) => {
|
|
9012
9075
|
const token = randomUUID2();
|
|
9013
9076
|
const suffix = token.replaceAll("-", "");
|
|
9014
9077
|
const bindingName = `__argusScenarioSend_${suffix}`;
|
|
9015
9078
|
const responseName = `__argusScenarioReceive_${suffix}`;
|
|
9016
|
-
const off =
|
|
9079
|
+
const off = session2.onEvent("Runtime.bindingCalled", (rawEvent, meta) => {
|
|
9017
9080
|
const { name, payload, executionContextId } = rawEvent;
|
|
9018
9081
|
if (name !== bindingName || typeof payload !== "string" || typeof executionContextId !== "number" || !Number.isInteger(executionContextId)) {
|
|
9019
9082
|
return;
|
|
@@ -9022,10 +9085,10 @@ var installScenarioBridge = async (session, expression, args, services, timeoutM
|
|
|
9022
9085
|
if (!request) {
|
|
9023
9086
|
return;
|
|
9024
9087
|
}
|
|
9025
|
-
respondToBridgeRequest(
|
|
9088
|
+
respondToBridgeRequest(session2, responseName, request, services, executionContextId, meta, timeoutMs);
|
|
9026
9089
|
});
|
|
9027
9090
|
try {
|
|
9028
|
-
await
|
|
9091
|
+
await session2.sendAndWait("Runtime.addBinding", { name: bindingName }, { timeoutMs });
|
|
9029
9092
|
} catch (error) {
|
|
9030
9093
|
off();
|
|
9031
9094
|
throw error;
|
|
@@ -9039,7 +9102,7 @@ var installScenarioBridge = async (session, expression, args, services, timeoutM
|
|
|
9039
9102
|
disposed = true;
|
|
9040
9103
|
off();
|
|
9041
9104
|
try {
|
|
9042
|
-
await
|
|
9105
|
+
await session2.sendAndWait("Runtime.removeBinding", { name: bindingName }, { timeoutMs });
|
|
9043
9106
|
} catch {}
|
|
9044
9107
|
}
|
|
9045
9108
|
};
|
|
@@ -9059,7 +9122,7 @@ var parseBridgeRequest = (payload, token) => {
|
|
|
9059
9122
|
return null;
|
|
9060
9123
|
}
|
|
9061
9124
|
};
|
|
9062
|
-
var respondToBridgeRequest = async (
|
|
9125
|
+
var respondToBridgeRequest = async (session2, responseName, request, services, executionContextId, meta, timeoutMs) => {
|
|
9063
9126
|
let response;
|
|
9064
9127
|
try {
|
|
9065
9128
|
response = { id: request.id, ok: true, result: await handleBridgeRequest(request, services) };
|
|
@@ -9067,7 +9130,7 @@ var respondToBridgeRequest = async (session, responseName, request, services, ex
|
|
|
9067
9130
|
response = { id: request.id, ok: false, error: formatError(error) };
|
|
9068
9131
|
}
|
|
9069
9132
|
try {
|
|
9070
|
-
await sendBridgeResponse(
|
|
9133
|
+
await sendBridgeResponse(session2, responseName, response, executionContextId, meta, timeoutMs);
|
|
9071
9134
|
} catch {}
|
|
9072
9135
|
};
|
|
9073
9136
|
var handleBridgeRequest = async (request, services) => {
|
|
@@ -9199,8 +9262,8 @@ var requireRecord = (value, label) => {
|
|
|
9199
9262
|
}
|
|
9200
9263
|
return value;
|
|
9201
9264
|
};
|
|
9202
|
-
var sendBridgeResponse = async (
|
|
9203
|
-
await
|
|
9265
|
+
var sendBridgeResponse = async (session2, responseName, response, executionContextId, meta, timeoutMs) => {
|
|
9266
|
+
await session2.sendAndWait("Runtime.evaluate", {
|
|
9204
9267
|
expression: `globalThis[${JSON.stringify(responseName)}]?.(${JSON.stringify(response)})`,
|
|
9205
9268
|
contextId: executionContextId,
|
|
9206
9269
|
returnByValue: true,
|
|
@@ -9283,7 +9346,7 @@ var buildScenarioExpression = (expression, options) => `(async () => {
|
|
|
9283
9346
|
})()`;
|
|
9284
9347
|
|
|
9285
9348
|
// ../argus-watcher/dist/cdp/eval.js
|
|
9286
|
-
var evaluateExpression = async (
|
|
9349
|
+
var evaluateExpression = async (session2, options) => {
|
|
9287
9350
|
const args = hasEvalArgs(options.args) ? options.args : undefined;
|
|
9288
9351
|
let scenarioBridge;
|
|
9289
9352
|
try {
|
|
@@ -9291,9 +9354,9 @@ var evaluateExpression = async (session, options) => {
|
|
|
9291
9354
|
if (!options.scenarioServices) {
|
|
9292
9355
|
throw new Error("Scenario host services are unavailable");
|
|
9293
9356
|
}
|
|
9294
|
-
scenarioBridge = await installScenarioBridge(
|
|
9357
|
+
scenarioBridge = await installScenarioBridge(session2, options.expression, args, options.scenarioServices, options.timeoutMs);
|
|
9295
9358
|
}
|
|
9296
|
-
const recordResult = await evaluateAndAwaitRecord(
|
|
9359
|
+
const recordResult = await evaluateAndAwaitRecord(session2, {
|
|
9297
9360
|
...options,
|
|
9298
9361
|
expression: wrapExpressionWithArgs(scenarioBridge?.expression ?? options.expression, args),
|
|
9299
9362
|
replMode: scenarioBridge ? false : options.replMode
|
|
@@ -9302,7 +9365,7 @@ var evaluateExpression = async (session, options) => {
|
|
|
9302
9365
|
return recordResult.response;
|
|
9303
9366
|
const record2 = recordResult.record;
|
|
9304
9367
|
if (options.jsonValue) {
|
|
9305
|
-
const jsonResult = await materializeJsonValue(
|
|
9368
|
+
const jsonResult = await materializeJsonValue(session2, record2, options);
|
|
9306
9369
|
if (!jsonResult.ok)
|
|
9307
9370
|
return jsonResult.response;
|
|
9308
9371
|
return {
|
|
@@ -9312,7 +9375,7 @@ var evaluateExpression = async (session, options) => {
|
|
|
9312
9375
|
exception: null
|
|
9313
9376
|
};
|
|
9314
9377
|
}
|
|
9315
|
-
const value = await materializeRemoteObject(
|
|
9378
|
+
const value = await materializeRemoteObject(session2, record2, options);
|
|
9316
9379
|
return {
|
|
9317
9380
|
ok: true,
|
|
9318
9381
|
result: value ?? null,
|
|
@@ -9331,8 +9394,8 @@ var wrapExpressionWithArgs = (expression, args) => {
|
|
|
9331
9394
|
${expression}
|
|
9332
9395
|
}`;
|
|
9333
9396
|
};
|
|
9334
|
-
var evaluateAndAwaitRecord = async (
|
|
9335
|
-
const payload = await evaluateRawExpression(
|
|
9397
|
+
var evaluateAndAwaitRecord = async (session2, options) => {
|
|
9398
|
+
const payload = await evaluateRawExpression(session2, options);
|
|
9336
9399
|
if (payload.exceptionDetails) {
|
|
9337
9400
|
return { response: formatExceptionResponse(payload), exception: true };
|
|
9338
9401
|
}
|
|
@@ -9340,7 +9403,7 @@ var evaluateAndAwaitRecord = async (session, options) => {
|
|
|
9340
9403
|
if (!(options.awaitPromise ?? true) || record2?.subtype !== "promise" || !record2.objectId) {
|
|
9341
9404
|
return { record: record2, exception: false };
|
|
9342
9405
|
}
|
|
9343
|
-
const awaitedPayload = await awaitPromiseResult(
|
|
9406
|
+
const awaitedPayload = await awaitPromiseResult(session2, record2.objectId, options.timeoutMs);
|
|
9344
9407
|
if (awaitedPayload.exceptionDetails) {
|
|
9345
9408
|
return { response: formatExceptionResponse(awaitedPayload), exception: true };
|
|
9346
9409
|
}
|
|
@@ -9355,25 +9418,25 @@ var formatExceptionResponse = (payload) => ({
|
|
|
9355
9418
|
details: payload.exceptionDetails?.exception ?? null
|
|
9356
9419
|
}
|
|
9357
9420
|
});
|
|
9358
|
-
var evaluateRawExpression = async (
|
|
9421
|
+
var evaluateRawExpression = async (session2, options) => await session2.sendAndWait("Runtime.evaluate", {
|
|
9359
9422
|
expression: options.expression,
|
|
9360
9423
|
replMode: options.replMode ?? true,
|
|
9361
9424
|
awaitPromise: false,
|
|
9362
9425
|
returnByValue: false
|
|
9363
9426
|
}, { timeoutMs: options.timeoutMs });
|
|
9364
|
-
var awaitPromiseResult = async (
|
|
9427
|
+
var awaitPromiseResult = async (session2, promiseObjectId, timeoutMs) => await session2.sendAndWait("Runtime.awaitPromise", {
|
|
9365
9428
|
promiseObjectId,
|
|
9366
9429
|
returnByValue: false
|
|
9367
9430
|
}, { timeoutMs });
|
|
9368
9431
|
var EMPTY_JSON_ENVELOPE = "{}";
|
|
9369
|
-
var materializeJsonValue = async (
|
|
9432
|
+
var materializeJsonValue = async (session2, record2, options) => {
|
|
9370
9433
|
if (!record2) {
|
|
9371
9434
|
return { ok: true, json: EMPTY_JSON_ENVELOPE };
|
|
9372
9435
|
}
|
|
9373
9436
|
if (!record2.objectId) {
|
|
9374
9437
|
return { ok: true, json: JSON.stringify({ v: record2.value }) ?? EMPTY_JSON_ENVELOPE };
|
|
9375
9438
|
}
|
|
9376
|
-
const payload = await
|
|
9439
|
+
const payload = await session2.sendAndWait("Runtime.callFunctionOn", {
|
|
9377
9440
|
objectId: record2.objectId,
|
|
9378
9441
|
functionDeclaration: "function () { return JSON.stringify({ v: this }) }",
|
|
9379
9442
|
returnByValue: true
|
|
@@ -9384,23 +9447,23 @@ var materializeJsonValue = async (session, record2, options) => {
|
|
|
9384
9447
|
const json = payload.result?.value;
|
|
9385
9448
|
return { ok: true, json: typeof json === "string" ? json : EMPTY_JSON_ENVELOPE };
|
|
9386
9449
|
};
|
|
9387
|
-
var materializeRemoteObject = async (
|
|
9450
|
+
var materializeRemoteObject = async (session2, record2, options) => {
|
|
9388
9451
|
if (!record2) {
|
|
9389
9452
|
return null;
|
|
9390
9453
|
}
|
|
9391
9454
|
if ((options.returnByValue ?? true) && shouldMaterializeByValue(record2)) {
|
|
9392
9455
|
try {
|
|
9393
|
-
const byValuePayload = await
|
|
9456
|
+
const byValuePayload = await session2.sendAndWait("Runtime.callFunctionOn", {
|
|
9394
9457
|
objectId: record2.objectId,
|
|
9395
9458
|
functionDeclaration: "function () { return this; }",
|
|
9396
9459
|
returnByValue: true
|
|
9397
9460
|
}, { timeoutMs: options.timeoutMs });
|
|
9398
9461
|
if (byValuePayload.result) {
|
|
9399
|
-
return await serializeRemoteObject(byValuePayload.result,
|
|
9462
|
+
return await serializeRemoteObject(byValuePayload.result, session2);
|
|
9400
9463
|
}
|
|
9401
9464
|
} catch {}
|
|
9402
9465
|
}
|
|
9403
|
-
return await serializeRemoteObject(record2,
|
|
9466
|
+
return await serializeRemoteObject(record2, session2);
|
|
9404
9467
|
};
|
|
9405
9468
|
var shouldMaterializeByValue = (record2) => {
|
|
9406
9469
|
return Boolean(record2.objectId) && record2.type === "object" && (record2.subtype == null || record2.subtype === "array");
|
|
@@ -9493,11 +9556,11 @@ var route21 = defineJsonRoute({
|
|
|
9493
9556
|
});
|
|
9494
9557
|
|
|
9495
9558
|
// ../argus-watcher/dist/cdp/text-filter.js
|
|
9496
|
-
var filterNodesByText = async (
|
|
9559
|
+
var filterNodesByText = async (session2, nodeIds, text) => {
|
|
9497
9560
|
const pattern = parseTextPattern(text);
|
|
9498
9561
|
const filtered = [];
|
|
9499
9562
|
for (const nodeId of nodeIds) {
|
|
9500
|
-
const trimmedText = await callFunctionOnNode(
|
|
9563
|
+
const trimmedText = await callFunctionOnNode(session2, { nodeId }, { code: "function() { return this.textContent?.trim(); }" });
|
|
9501
9564
|
if (typeof trimmedText !== "string") {
|
|
9502
9565
|
continue;
|
|
9503
9566
|
}
|
|
@@ -9515,27 +9578,27 @@ var filterNodesByText = async (session, nodeIds, text) => {
|
|
|
9515
9578
|
};
|
|
9516
9579
|
|
|
9517
9580
|
// ../argus-watcher/dist/cdp/dom/selector.js
|
|
9518
|
-
var getDomRootId = async (
|
|
9519
|
-
const targetContext = await
|
|
9581
|
+
var getDomRootId = async (session2) => {
|
|
9582
|
+
const targetContext = await session2.getReadyTargetContext();
|
|
9520
9583
|
if (targetContext?.kind === "frame") {
|
|
9521
|
-
return getFrameDomRootId(
|
|
9584
|
+
return getFrameDomRootId(session2, targetContext);
|
|
9522
9585
|
}
|
|
9523
|
-
return getDocumentRootId(
|
|
9586
|
+
return getDocumentRootId(session2);
|
|
9524
9587
|
};
|
|
9525
|
-
var resolveSelectorMatches = async (
|
|
9526
|
-
const result = await
|
|
9588
|
+
var resolveSelectorMatches = async (session2, rootId, selector, all, text) => {
|
|
9589
|
+
const result = await session2.sendAndWait("DOM.querySelectorAll", { nodeId: rootId, selector });
|
|
9527
9590
|
let allNodeIds = result.nodeIds ?? [];
|
|
9528
9591
|
if (text != null) {
|
|
9529
|
-
allNodeIds = await filterNodesByText(
|
|
9592
|
+
allNodeIds = await filterNodesByText(session2, allNodeIds, text);
|
|
9530
9593
|
}
|
|
9531
9594
|
const nodeIds = all ? allNodeIds : allNodeIds.slice(0, 1);
|
|
9532
9595
|
return { allNodeIds, nodeIds };
|
|
9533
9596
|
};
|
|
9534
|
-
var waitForSelectorMatches = async (
|
|
9597
|
+
var waitForSelectorMatches = async (session2, selector, all, text, waitMs, intervalMs = 100) => {
|
|
9535
9598
|
const deadline = Date.now() + waitMs;
|
|
9536
9599
|
while (true) {
|
|
9537
|
-
const rootId = await getDomRootId(
|
|
9538
|
-
const result = await resolveSelectorMatches(
|
|
9600
|
+
const rootId = await getDomRootId(session2);
|
|
9601
|
+
const result = await resolveSelectorMatches(session2, rootId, selector, all, text);
|
|
9539
9602
|
if (result.allNodeIds.length > 0)
|
|
9540
9603
|
return result;
|
|
9541
9604
|
const remaining = deadline - Date.now();
|
|
@@ -9544,17 +9607,17 @@ var waitForSelectorMatches = async (session, selector, all, text, waitMs, interv
|
|
|
9544
9607
|
await new Promise((r) => setTimeout(r, Math.min(intervalMs, remaining)));
|
|
9545
9608
|
}
|
|
9546
9609
|
};
|
|
9547
|
-
var resolveSelectorTargets = async (
|
|
9548
|
-
await
|
|
9610
|
+
var resolveSelectorTargets = async (session2, options) => {
|
|
9611
|
+
await session2.sendAndWait("DOM.enable");
|
|
9549
9612
|
const waitMs = options.waitMs ?? 0;
|
|
9550
9613
|
if (waitMs > 0) {
|
|
9551
|
-
return waitForSelectorMatches(
|
|
9614
|
+
return waitForSelectorMatches(session2, options.selector, options.all, options.text, waitMs);
|
|
9552
9615
|
}
|
|
9553
|
-
const rootId = await getDomRootId(
|
|
9554
|
-
return resolveSelectorMatches(
|
|
9616
|
+
const rootId = await getDomRootId(session2);
|
|
9617
|
+
return resolveSelectorMatches(session2, rootId, options.selector, options.all, options.text);
|
|
9555
9618
|
};
|
|
9556
|
-
var resolveElementTargets = async (
|
|
9557
|
-
await
|
|
9619
|
+
var resolveElementTargets = async (session2, elementRefs, options) => {
|
|
9620
|
+
await session2.sendAndWait("DOM.enable");
|
|
9558
9621
|
if (options.ref) {
|
|
9559
9622
|
const backendNodeId = elementRefs.resolve(options.ref);
|
|
9560
9623
|
if (backendNodeId == null) {
|
|
@@ -9578,7 +9641,7 @@ var resolveElementTargets = async (session, elementRefs, options) => {
|
|
|
9578
9641
|
if (!options.selector) {
|
|
9579
9642
|
throw new Error("selector or ref is required");
|
|
9580
9643
|
}
|
|
9581
|
-
const result = (options.waitMs ?? 0) > 0 ? await waitForSelectorMatches(
|
|
9644
|
+
const result = (options.waitMs ?? 0) > 0 ? await waitForSelectorMatches(session2, options.selector, options.all, options.text, options.waitMs ?? 0) : await resolveSelectorMatches(session2, await getDomRootId(session2), options.selector, options.all, options.text);
|
|
9582
9645
|
return {
|
|
9583
9646
|
target: { kind: "selector", value: options.selector },
|
|
9584
9647
|
allHandles: result.allNodeIds.map((nodeId) => ({ nodeId })),
|
|
@@ -9586,28 +9649,28 @@ var resolveElementTargets = async (session, elementRefs, options) => {
|
|
|
9586
9649
|
...result
|
|
9587
9650
|
};
|
|
9588
9651
|
};
|
|
9589
|
-
var resolveFirstSelectorNodeId = async (
|
|
9590
|
-
const { nodeIds } = await resolveSelectorTargets(
|
|
9652
|
+
var resolveFirstSelectorNodeId = async (session2, selector, text) => {
|
|
9653
|
+
const { nodeIds } = await resolveSelectorTargets(session2, {
|
|
9591
9654
|
selector,
|
|
9592
9655
|
all: false,
|
|
9593
9656
|
text
|
|
9594
9657
|
});
|
|
9595
9658
|
return nodeIds[0] ?? null;
|
|
9596
9659
|
};
|
|
9597
|
-
var describeNodeByBackendId = async (
|
|
9598
|
-
const described = await
|
|
9660
|
+
var describeNodeByBackendId = async (session2, backendNodeId) => {
|
|
9661
|
+
const described = await session2.sendAndWait("DOM.describeNode", {
|
|
9599
9662
|
backendNodeId,
|
|
9600
9663
|
depth: 0
|
|
9601
9664
|
});
|
|
9602
9665
|
return described.node ?? null;
|
|
9603
9666
|
};
|
|
9604
|
-
var resolveNodeIdByBackendId = async (
|
|
9605
|
-
const describedNode = await describeNodeByBackendId(
|
|
9667
|
+
var resolveNodeIdByBackendId = async (session2, backendNodeId) => {
|
|
9668
|
+
const describedNode = await describeNodeByBackendId(session2, backendNodeId);
|
|
9606
9669
|
if (describedNode?.nodeId) {
|
|
9607
9670
|
return describedNode.nodeId;
|
|
9608
9671
|
}
|
|
9609
|
-
await getDomRootId(
|
|
9610
|
-
const pushed = await
|
|
9672
|
+
await getDomRootId(session2);
|
|
9673
|
+
const pushed = await session2.sendAndWait("DOM.pushNodesByBackendIdsToFrontend", {
|
|
9611
9674
|
backendNodeIds: [backendNodeId]
|
|
9612
9675
|
});
|
|
9613
9676
|
const nodeId = pushed.nodeIds?.[0];
|
|
@@ -9622,14 +9685,14 @@ var toDomNodeDescriptor = (handle) => {
|
|
|
9622
9685
|
}
|
|
9623
9686
|
throw new Error("DOM node handle is missing both nodeId and backendNodeId");
|
|
9624
9687
|
};
|
|
9625
|
-
var getFrameDomRootId = async (
|
|
9688
|
+
var getFrameDomRootId = async (session2, targetContext) => {
|
|
9626
9689
|
if (targetContext.sessionId) {
|
|
9627
|
-
return getDocumentRootId(
|
|
9690
|
+
return getDocumentRootId(session2);
|
|
9628
9691
|
}
|
|
9629
9692
|
if (targetContext.executionContextId == null) {
|
|
9630
9693
|
throw new Error(`Selected frame is not ready yet: ${targetContext.frameId}`);
|
|
9631
9694
|
}
|
|
9632
|
-
const evaluated = await
|
|
9695
|
+
const evaluated = await session2.sendAndWait("Runtime.evaluate", {
|
|
9633
9696
|
expression: "document",
|
|
9634
9697
|
contextId: targetContext.executionContextId,
|
|
9635
9698
|
returnByValue: false
|
|
@@ -9638,14 +9701,14 @@ var getFrameDomRootId = async (session, targetContext) => {
|
|
|
9638
9701
|
if (!objectId) {
|
|
9639
9702
|
throw new Error(`Unable to resolve DOM root for frame: ${targetContext.frameId}`);
|
|
9640
9703
|
}
|
|
9641
|
-
const requested = await
|
|
9704
|
+
const requested = await session2.sendAndWait("DOM.requestNode", { objectId });
|
|
9642
9705
|
if (!requested.nodeId) {
|
|
9643
9706
|
throw new Error(`Unable to resolve DOM root for frame: ${targetContext.frameId}`);
|
|
9644
9707
|
}
|
|
9645
9708
|
return requested.nodeId;
|
|
9646
9709
|
};
|
|
9647
|
-
var getDocumentRootId = async (
|
|
9648
|
-
const result = await
|
|
9710
|
+
var getDocumentRootId = async (session2) => {
|
|
9711
|
+
const result = await session2.sendAndWait("DOM.getDocument", { depth: 1 });
|
|
9649
9712
|
const rootId = result.root?.nodeId;
|
|
9650
9713
|
if (!rootId) {
|
|
9651
9714
|
throw new Error("Unable to resolve DOM root");
|
|
@@ -9737,9 +9800,9 @@ var RELEVANT_PROPERTIES = new Set([
|
|
|
9737
9800
|
"multiselectable",
|
|
9738
9801
|
"orientation"
|
|
9739
9802
|
]);
|
|
9740
|
-
var fetchAccessibilitySnapshot = async (
|
|
9741
|
-
await
|
|
9742
|
-
const nodes = await resolveAccessibilityNodes(
|
|
9803
|
+
var fetchAccessibilitySnapshot = async (session2, options, elementRefs) => {
|
|
9804
|
+
await session2.sendAndWait("Accessibility.enable");
|
|
9805
|
+
const nodes = await resolveAccessibilityNodes(session2, options.selector);
|
|
9743
9806
|
const totalNodes = nodes.length;
|
|
9744
9807
|
const roots = buildTree(nodes, {
|
|
9745
9808
|
depth: options.depth,
|
|
@@ -9749,8 +9812,8 @@ var fetchAccessibilitySnapshot = async (session, options, elementRefs) => {
|
|
|
9749
9812
|
const returnedNodes = countNodes(roots);
|
|
9750
9813
|
return { ok: true, roots, totalNodes, returnedNodes };
|
|
9751
9814
|
};
|
|
9752
|
-
var listAccessibleElements = async (
|
|
9753
|
-
const nodes = await resolveAccessibilityNodes(
|
|
9815
|
+
var listAccessibleElements = async (session2, elementRefs, options = {}) => {
|
|
9816
|
+
const nodes = await resolveAccessibilityNodes(session2, options.selector);
|
|
9754
9817
|
return collectAccessibleElements(nodes, elementRefs);
|
|
9755
9818
|
};
|
|
9756
9819
|
var buildTree = (cdpNodes, options) => {
|
|
@@ -9821,24 +9884,24 @@ var convertNode = (nodeMap, nodeId, currentDepth, options) => {
|
|
|
9821
9884
|
}
|
|
9822
9885
|
return [result];
|
|
9823
9886
|
};
|
|
9824
|
-
var fetchAccessibilityNodes = async (
|
|
9825
|
-
const axResult = await
|
|
9887
|
+
var fetchAccessibilityNodes = async (session2) => {
|
|
9888
|
+
const axResult = await session2.sendAndWait("Accessibility.getFullAXTree");
|
|
9826
9889
|
return axResult.nodes ?? [];
|
|
9827
9890
|
};
|
|
9828
|
-
var resolveAccessibilityNodes = async (
|
|
9829
|
-
const nodes = await fetchAccessibilityNodes(
|
|
9891
|
+
var resolveAccessibilityNodes = async (session2, selector) => {
|
|
9892
|
+
const nodes = await fetchAccessibilityNodes(session2);
|
|
9830
9893
|
if (!selector) {
|
|
9831
9894
|
return nodes;
|
|
9832
9895
|
}
|
|
9833
|
-
return filterAccessibilityNodesBySelector(
|
|
9896
|
+
return filterAccessibilityNodesBySelector(session2, nodes, selector);
|
|
9834
9897
|
};
|
|
9835
|
-
var filterAccessibilityNodesBySelector = async (
|
|
9836
|
-
const domNodeId = await resolveFirstSelectorNodeId(
|
|
9898
|
+
var filterAccessibilityNodesBySelector = async (session2, nodes, selector) => {
|
|
9899
|
+
const domNodeId = await resolveFirstSelectorNodeId(session2, selector);
|
|
9837
9900
|
if (!domNodeId) {
|
|
9838
9901
|
throw new Error(`No element found for selector: ${selector}`);
|
|
9839
9902
|
}
|
|
9840
|
-
await
|
|
9841
|
-
const allDescendants = await
|
|
9903
|
+
await session2.sendAndWait("DOM.getDocument", { depth: -1 });
|
|
9904
|
+
const allDescendants = await session2.sendAndWait("DOM.querySelectorAll", {
|
|
9842
9905
|
nodeId: domNodeId,
|
|
9843
9906
|
selector: "*"
|
|
9844
9907
|
});
|
|
@@ -9846,7 +9909,7 @@ var filterAccessibilityNodesBySelector = async (session, nodes, selector) => {
|
|
|
9846
9909
|
const backendIds = new Set;
|
|
9847
9910
|
const allDomNodeIds = [domNodeId, ...descendantNodeIds];
|
|
9848
9911
|
for (const nid of allDomNodeIds) {
|
|
9849
|
-
const desc = await
|
|
9912
|
+
const desc = await session2.sendAndWait("DOM.describeNode", { nodeId: nid, depth: 0 });
|
|
9850
9913
|
if (desc.node?.backendNodeId != null) {
|
|
9851
9914
|
backendIds.add(desc.node.backendNodeId);
|
|
9852
9915
|
}
|
|
@@ -9981,8 +10044,8 @@ var route22 = defineJsonRoute({
|
|
|
9981
10044
|
|
|
9982
10045
|
// ../argus-watcher/dist/cdp/locate.js
|
|
9983
10046
|
var LABELABLE_ROLES = new Set(["button", "checkbox", "combobox", "listbox", "radio", "searchbox", "slider", "spinbutton", "switch", "textbox"]);
|
|
9984
|
-
var locateByRole = async (
|
|
9985
|
-
const matches = (await listAccessibleElements(
|
|
10047
|
+
var locateByRole = async (session2, elementRefs, request) => {
|
|
10048
|
+
const matches = (await listAccessibleElements(session2, elementRefs)).filter((element) => {
|
|
9986
10049
|
if (normalizeText(element.role) !== normalizeText(request.role)) {
|
|
9987
10050
|
return false;
|
|
9988
10051
|
}
|
|
@@ -9991,29 +10054,29 @@ var locateByRole = async (session, elementRefs, request) => {
|
|
|
9991
10054
|
}
|
|
9992
10055
|
return matchesText(element.name, request.name, request.exact ?? false);
|
|
9993
10056
|
});
|
|
9994
|
-
return buildLocateResponse(
|
|
10057
|
+
return buildLocateResponse(session2, request.all ?? false, matches);
|
|
9995
10058
|
};
|
|
9996
|
-
var locateByText = async (
|
|
9997
|
-
const matches = (await listAccessibleElements(
|
|
9998
|
-
return buildLocateResponse(
|
|
10059
|
+
var locateByText = async (session2, elementRefs, request) => {
|
|
10060
|
+
const matches = (await listAccessibleElements(session2, elementRefs)).filter((element) => matchesText(element.name, request.text, request.exact ?? false) || matchesText(element.value ?? "", request.text, request.exact ?? false));
|
|
10061
|
+
return buildLocateResponse(session2, request.all ?? false, matches);
|
|
9999
10062
|
};
|
|
10000
|
-
var locateByLabel = async (
|
|
10001
|
-
const matches = (await listAccessibleElements(
|
|
10063
|
+
var locateByLabel = async (session2, elementRefs, request) => {
|
|
10064
|
+
const matches = (await listAccessibleElements(session2, elementRefs)).filter((element) => {
|
|
10002
10065
|
if (!LABELABLE_ROLES.has(element.role)) {
|
|
10003
10066
|
return false;
|
|
10004
10067
|
}
|
|
10005
10068
|
return matchesText(element.name, request.label, request.exact ?? false);
|
|
10006
10069
|
});
|
|
10007
|
-
return buildLocateResponse(
|
|
10070
|
+
return buildLocateResponse(session2, request.all ?? false, await removeCompositeLabelWrappers(session2, matches));
|
|
10008
10071
|
};
|
|
10009
10072
|
var NATIVE_LABELABLE_TAGS = new Set(["button", "input", "select", "textarea"]);
|
|
10010
|
-
var removeCompositeLabelWrappers = async (
|
|
10073
|
+
var removeCompositeLabelWrappers = async (session2, matches) => {
|
|
10011
10074
|
if (matches.length < 2)
|
|
10012
10075
|
return matches;
|
|
10013
10076
|
const candidates = await Promise.all(matches.map(async (match) => {
|
|
10014
10077
|
const [node, nodeId] = await Promise.all([
|
|
10015
|
-
describeNodeByBackendId(
|
|
10016
|
-
resolveNodeIdByBackendId(
|
|
10078
|
+
describeNodeByBackendId(session2, match.backendNodeId),
|
|
10079
|
+
resolveNodeIdByBackendId(session2, match.backendNodeId)
|
|
10017
10080
|
]);
|
|
10018
10081
|
const tag = node ? (node.localName ?? node.nodeName).toLowerCase() : "";
|
|
10019
10082
|
return { match, nodeId, native: NATIVE_LABELABLE_TAGS.has(tag) };
|
|
@@ -10027,7 +10090,7 @@ var removeCompositeLabelWrappers = async (session, matches) => {
|
|
|
10027
10090
|
kept.push(candidate.match);
|
|
10028
10091
|
continue;
|
|
10029
10092
|
}
|
|
10030
|
-
const descendants = await
|
|
10093
|
+
const descendants = await session2.sendAndWait("DOM.querySelectorAll", {
|
|
10031
10094
|
nodeId: candidate.nodeId,
|
|
10032
10095
|
selector: "button,input,select,textarea"
|
|
10033
10096
|
});
|
|
@@ -10038,17 +10101,17 @@ var removeCompositeLabelWrappers = async (session, matches) => {
|
|
|
10038
10101
|
}
|
|
10039
10102
|
return kept;
|
|
10040
10103
|
};
|
|
10041
|
-
var buildLocateResponse = async (
|
|
10104
|
+
var buildLocateResponse = async (session2, all, matches) => {
|
|
10042
10105
|
const selected = all ? matches : matches.slice(0, 1);
|
|
10043
|
-
const elements = await Promise.all(selected.map((element) => toLocatedElement(
|
|
10106
|
+
const elements = await Promise.all(selected.map((element) => toLocatedElement(session2, element)));
|
|
10044
10107
|
return {
|
|
10045
10108
|
ok: true,
|
|
10046
10109
|
matches: matches.length,
|
|
10047
10110
|
elements
|
|
10048
10111
|
};
|
|
10049
10112
|
};
|
|
10050
|
-
var toLocatedElement = async (
|
|
10051
|
-
const node = await describeNodeByBackendId(
|
|
10113
|
+
var toLocatedElement = async (session2, element) => {
|
|
10114
|
+
const node = await describeNodeByBackendId(session2, element.backendNodeId);
|
|
10052
10115
|
const attributes = node?.attributes ? toAttributesRecord(node.attributes) : undefined;
|
|
10053
10116
|
return {
|
|
10054
10117
|
ref: element.ref,
|
|
@@ -10189,13 +10252,13 @@ var DEFAULT_DEPTH = 2;
|
|
|
10189
10252
|
var DEFAULT_MAX_NODES = 5000;
|
|
10190
10253
|
var MAX_DEPTH = 10;
|
|
10191
10254
|
var MAX_MAX_NODES = 50000;
|
|
10192
|
-
var fetchDomSubtreeBySelector = async (
|
|
10255
|
+
var fetchDomSubtreeBySelector = async (session2, options) => {
|
|
10193
10256
|
const depth = clamp(options.depth ?? DEFAULT_DEPTH, 0, MAX_DEPTH);
|
|
10194
10257
|
const maxNodes = clamp(options.maxNodes ?? DEFAULT_MAX_NODES, 1, MAX_MAX_NODES);
|
|
10195
10258
|
const all = options.all ?? false;
|
|
10196
|
-
await
|
|
10197
|
-
const rootId = await getDomRootId(
|
|
10198
|
-
const { allNodeIds, nodeIds } = await resolveSelectorMatches(
|
|
10259
|
+
await session2.sendAndWait("DOM.enable");
|
|
10260
|
+
const rootId = await getDomRootId(session2);
|
|
10261
|
+
const { allNodeIds, nodeIds } = await resolveSelectorMatches(session2, rootId, options.selector, all, options.text);
|
|
10199
10262
|
if (allNodeIds.length === 0) {
|
|
10200
10263
|
return { ok: true, matches: 0, roots: [], truncated: false };
|
|
10201
10264
|
}
|
|
@@ -10207,7 +10270,7 @@ var fetchDomSubtreeBySelector = async (session, options) => {
|
|
|
10207
10270
|
state2.truncatedReason = "max_nodes";
|
|
10208
10271
|
break;
|
|
10209
10272
|
}
|
|
10210
|
-
const describeResult = await
|
|
10273
|
+
const describeResult = await session2.sendAndWait("DOM.describeNode", {
|
|
10211
10274
|
nodeId,
|
|
10212
10275
|
depth: depth + 1
|
|
10213
10276
|
});
|
|
@@ -10278,10 +10341,10 @@ var toDomNodeTree = (node, remainingDepth, state2) => {
|
|
|
10278
10341
|
// ../argus-watcher/dist/cdp/dom/info.js
|
|
10279
10342
|
var DEFAULT_OUTER_HTML_MAX_CHARS = 50000;
|
|
10280
10343
|
var MAX_OUTER_HTML_CHARS = 500000;
|
|
10281
|
-
var fetchDomInfoBySelector = async (
|
|
10344
|
+
var fetchDomInfoBySelector = async (session2, elementRefs, options) => {
|
|
10282
10345
|
const all = options.all ?? false;
|
|
10283
10346
|
const maxChars = clamp(options.outerHtmlMaxChars ?? DEFAULT_OUTER_HTML_MAX_CHARS, 0, MAX_OUTER_HTML_CHARS);
|
|
10284
|
-
const resolved = await resolveElementTargets(
|
|
10347
|
+
const resolved = await resolveElementTargets(session2, elementRefs, {
|
|
10285
10348
|
selector: options.selector,
|
|
10286
10349
|
ref: options.ref,
|
|
10287
10350
|
all,
|
|
@@ -10297,7 +10360,7 @@ var fetchDomInfoBySelector = async (session, elementRefs, options) => {
|
|
|
10297
10360
|
const elements = [];
|
|
10298
10361
|
for (const handle of handles) {
|
|
10299
10362
|
const descriptor = toDomNodeDescriptor(handle);
|
|
10300
|
-
const describeResult = await
|
|
10363
|
+
const describeResult = await session2.sendAndWait("DOM.describeNode", {
|
|
10301
10364
|
...descriptor,
|
|
10302
10365
|
depth: 1
|
|
10303
10366
|
});
|
|
@@ -10310,7 +10373,7 @@ var fetchDomInfoBySelector = async (session, elementRefs, options) => {
|
|
|
10310
10373
|
let outerHTML = null;
|
|
10311
10374
|
let outerHTMLTruncated = false;
|
|
10312
10375
|
try {
|
|
10313
|
-
const htmlResult = await
|
|
10376
|
+
const htmlResult = await session2.sendAndWait("DOM.getOuterHTML", descriptor);
|
|
10314
10377
|
outerHTML = htmlResult.outerHTML ?? null;
|
|
10315
10378
|
if (outerHTML && outerHTML.length > maxChars) {
|
|
10316
10379
|
outerHTML = outerHTML.slice(0, maxChars);
|
|
@@ -10330,18 +10393,18 @@ var fetchDomInfoBySelector = async (session, elementRefs, options) => {
|
|
|
10330
10393
|
return { ok: true, matches: allHandles.length, elements };
|
|
10331
10394
|
};
|
|
10332
10395
|
// ../argus-watcher/dist/cdp/dom/mutate.js
|
|
10333
|
-
var mutateMatchedElements = async (
|
|
10334
|
-
await
|
|
10335
|
-
const rootId = await getDomRootId(
|
|
10336
|
-
const { allNodeIds, nodeIds } = await resolveSelectorMatches(
|
|
10396
|
+
var mutateMatchedElements = async (session2, target, apply) => {
|
|
10397
|
+
await session2.sendAndWait("DOM.enable");
|
|
10398
|
+
const rootId = await getDomRootId(session2);
|
|
10399
|
+
const { allNodeIds, nodeIds } = await resolveSelectorMatches(session2, rootId, target.selector, target.all ?? false, target.text);
|
|
10337
10400
|
for (const nodeId of nodeIds) {
|
|
10338
10401
|
await apply(nodeId);
|
|
10339
10402
|
}
|
|
10340
10403
|
return { allNodeIds, mutatedCount: nodeIds.length };
|
|
10341
10404
|
};
|
|
10342
|
-
var mutateWithPageFunction = (
|
|
10343
|
-
var removeElements = (
|
|
10344
|
-
var modifyElements = (
|
|
10405
|
+
var mutateWithPageFunction = (session2, target, fn) => mutateMatchedElements(session2, target, (nodeId) => callFunctionOnNode(session2, { nodeId }, fn));
|
|
10406
|
+
var removeElements = (session2, options) => mutateWithPageFunction(session2, options, { code: "function() { this.remove(); }" });
|
|
10407
|
+
var modifyElements = (session2, options) => mutateWithPageFunction(session2, options, buildModifyFunction(options));
|
|
10345
10408
|
var FILL_FUNCTION = `function(value) {
|
|
10346
10409
|
var el = this;
|
|
10347
10410
|
el.focus();
|
|
@@ -10363,29 +10426,29 @@ var FILL_FUNCTION = `function(value) {
|
|
|
10363
10426
|
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
10364
10427
|
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
10365
10428
|
}`;
|
|
10366
|
-
var fillResolvedNodes = async (
|
|
10429
|
+
var fillResolvedNodes = async (session2, handles, value) => {
|
|
10367
10430
|
for (const handle of handles) {
|
|
10368
|
-
await callFunctionOnNode(
|
|
10431
|
+
await callFunctionOnNode(session2, toDomNodeDescriptor(handle), { code: FILL_FUNCTION, args: [{ value }] });
|
|
10369
10432
|
}
|
|
10370
10433
|
return handles.length;
|
|
10371
10434
|
};
|
|
10372
|
-
var insertAdjacentHtml = async (
|
|
10435
|
+
var insertAdjacentHtml = async (session2, options) => {
|
|
10373
10436
|
if (options.nodeIds.length === 0) {
|
|
10374
10437
|
return 0;
|
|
10375
10438
|
}
|
|
10376
|
-
await
|
|
10439
|
+
await session2.sendAndWait("DOM.enable");
|
|
10377
10440
|
const fn = {
|
|
10378
10441
|
code: options.text ? "function(pos, value) { this.insertAdjacentText(pos, value); }" : "function(pos, html) { this.insertAdjacentHTML(pos, html); }",
|
|
10379
10442
|
args: [{ value: options.position ?? "beforeend" }, { value: options.html }]
|
|
10380
10443
|
};
|
|
10381
10444
|
for (const nodeId of options.nodeIds) {
|
|
10382
|
-
await callFunctionOnNode(
|
|
10445
|
+
await callFunctionOnNode(session2, { nodeId }, fn);
|
|
10383
10446
|
}
|
|
10384
10447
|
return options.nodeIds.length;
|
|
10385
10448
|
};
|
|
10386
|
-
var setFileOnResolvedNodes = async (
|
|
10449
|
+
var setFileOnResolvedNodes = async (session2, nodeIds, files) => {
|
|
10387
10450
|
for (const nodeId of nodeIds) {
|
|
10388
|
-
await
|
|
10451
|
+
await session2.sendAndWait("DOM.setFileInputFiles", { files, nodeId });
|
|
10389
10452
|
}
|
|
10390
10453
|
return nodeIds.length;
|
|
10391
10454
|
};
|
|
@@ -10502,27 +10565,27 @@ var route28 = defineJsonRoute({
|
|
|
10502
10565
|
});
|
|
10503
10566
|
|
|
10504
10567
|
// ../argus-watcher/dist/cdp/mouse.js
|
|
10505
|
-
var resolveDomSelectorMatches = async (
|
|
10506
|
-
return resolveSelectorTargets(
|
|
10568
|
+
var resolveDomSelectorMatches = async (session2, selector, all, text) => {
|
|
10569
|
+
return resolveSelectorTargets(session2, { selector, all, text });
|
|
10507
10570
|
};
|
|
10508
|
-
var hoverDomNodes = async (
|
|
10571
|
+
var hoverDomNodes = async (session2, handles) => {
|
|
10509
10572
|
if (handles.length === 0) {
|
|
10510
10573
|
return;
|
|
10511
10574
|
}
|
|
10512
10575
|
for (const handle of handles) {
|
|
10513
|
-
await scrollIntoView(
|
|
10514
|
-
const point = await resolveNodePoint(
|
|
10515
|
-
await dispatchMouseEvent(
|
|
10576
|
+
await scrollIntoView(session2, handle);
|
|
10577
|
+
const point = await resolveNodePoint(session2, handle);
|
|
10578
|
+
await dispatchMouseEvent(session2, { type: "mouseMoved", x: point.x, y: point.y });
|
|
10516
10579
|
}
|
|
10517
10580
|
};
|
|
10518
10581
|
var BUTTON_MASK = { left: 1, middle: 4, right: 2 };
|
|
10519
|
-
var clickAtPoint = async (
|
|
10582
|
+
var clickAtPoint = async (session2, x, y, button = "left") => {
|
|
10520
10583
|
const mask = BUTTON_MASK[button] ?? 1;
|
|
10521
|
-
await dispatchMouseEvent(
|
|
10522
|
-
await dispatchMouseEvent(
|
|
10523
|
-
await dispatchMouseEvent(
|
|
10584
|
+
await dispatchMouseEvent(session2, { type: "mouseMoved", x, y });
|
|
10585
|
+
await dispatchMouseEvent(session2, { type: "mousePressed", x, y, button, buttons: mask, clickCount: 1 });
|
|
10586
|
+
await dispatchMouseEvent(session2, { type: "mouseReleased", x, y, button, buttons: 0, clickCount: 1 });
|
|
10524
10587
|
};
|
|
10525
|
-
var dragAtPoints = async (
|
|
10588
|
+
var dragAtPoints = async (session2, start, end, options = {}) => {
|
|
10526
10589
|
const button = options.button ?? "left";
|
|
10527
10590
|
const mask = BUTTON_MASK[button] ?? 1;
|
|
10528
10591
|
const steps = Math.max(1, Math.floor(options.steps ?? 12));
|
|
@@ -10530,35 +10593,35 @@ var dragAtPoints = async (session, start, end, options = {}) => {
|
|
|
10530
10593
|
const stepDelayMs = durationMs / steps;
|
|
10531
10594
|
let latest = start;
|
|
10532
10595
|
let pressed = false;
|
|
10533
|
-
await dispatchMouseEvent(
|
|
10596
|
+
await dispatchMouseEvent(session2, { type: "mouseMoved", x: start.x, y: start.y });
|
|
10534
10597
|
try {
|
|
10535
|
-
await dispatchMouseEvent(
|
|
10598
|
+
await dispatchMouseEvent(session2, { type: "mousePressed", x: start.x, y: start.y, button, buttons: mask, clickCount: 1 });
|
|
10536
10599
|
pressed = true;
|
|
10537
10600
|
for (let i = 1;i <= steps; i++) {
|
|
10538
10601
|
if (stepDelayMs > 0) {
|
|
10539
10602
|
await delay(stepDelayMs);
|
|
10540
10603
|
}
|
|
10541
10604
|
latest = interpolatePoint(start, end, i / steps);
|
|
10542
|
-
await dispatchMouseEvent(
|
|
10605
|
+
await dispatchMouseEvent(session2, { type: "mouseMoved", x: latest.x, y: latest.y, button, buttons: mask, clickCount: 1 });
|
|
10543
10606
|
}
|
|
10544
|
-
await dispatchMouseEvent(
|
|
10607
|
+
await dispatchMouseEvent(session2, { type: "mouseReleased", x: end.x, y: end.y, button, buttons: 0, clickCount: 1 });
|
|
10545
10608
|
pressed = false;
|
|
10546
10609
|
} finally {
|
|
10547
10610
|
if (pressed) {
|
|
10548
|
-
await dispatchMouseEvent(
|
|
10611
|
+
await dispatchMouseEvent(session2, { type: "mouseReleased", x: latest.x, y: latest.y, button, buttons: 0, clickCount: 1 }).catch(() => {
|
|
10549
10612
|
return;
|
|
10550
10613
|
});
|
|
10551
10614
|
}
|
|
10552
10615
|
}
|
|
10553
10616
|
};
|
|
10554
|
-
var dragDomNodes = async (
|
|
10617
|
+
var dragDomNodes = async (session2, handles, destination, options = {}) => {
|
|
10555
10618
|
if (handles.length === 0) {
|
|
10556
10619
|
return;
|
|
10557
10620
|
}
|
|
10558
10621
|
for (const handle of handles) {
|
|
10559
|
-
await scrollIntoView(
|
|
10560
|
-
const start = await resolveNodePoint(
|
|
10561
|
-
await dragAtPoints(
|
|
10622
|
+
await scrollIntoView(session2, handle);
|
|
10623
|
+
const start = await resolveNodePoint(session2, handle, options.offset);
|
|
10624
|
+
await dragAtPoints(session2, start, resolveDragEndPoint(start, destination), options);
|
|
10562
10625
|
}
|
|
10563
10626
|
};
|
|
10564
10627
|
var resolveDragEndPoint = (start, destination) => {
|
|
@@ -10570,67 +10633,67 @@ var resolveDragEndPoint = (start, destination) => {
|
|
|
10570
10633
|
y: start.y + destination.delta.y
|
|
10571
10634
|
};
|
|
10572
10635
|
};
|
|
10573
|
-
var clickDomNodes = async (
|
|
10636
|
+
var clickDomNodes = async (session2, handles, button = "left") => {
|
|
10574
10637
|
if (handles.length === 0) {
|
|
10575
10638
|
return;
|
|
10576
10639
|
}
|
|
10577
10640
|
const mask = BUTTON_MASK[button] ?? 1;
|
|
10578
10641
|
for (const handle of handles) {
|
|
10579
|
-
await scrollIntoView(
|
|
10580
|
-
const point = await resolveNodePoint(
|
|
10581
|
-
await dispatchMouseEvent(
|
|
10582
|
-
await dispatchMouseEvent(
|
|
10583
|
-
await dispatchMouseEvent(
|
|
10642
|
+
await scrollIntoView(session2, handle);
|
|
10643
|
+
const point = await resolveNodePoint(session2, handle);
|
|
10644
|
+
await dispatchMouseEvent(session2, { type: "mouseMoved", x: point.x, y: point.y });
|
|
10645
|
+
await dispatchMouseEvent(session2, { type: "mousePressed", x: point.x, y: point.y, button, buttons: mask, clickCount: 1 });
|
|
10646
|
+
await dispatchMouseEvent(session2, { type: "mouseReleased", x: point.x, y: point.y, button, buttons: 0, clickCount: 1 });
|
|
10584
10647
|
}
|
|
10585
10648
|
};
|
|
10586
|
-
var focusDomNodes = async (
|
|
10649
|
+
var focusDomNodes = async (session2, handles) => {
|
|
10587
10650
|
if (handles.length === 0) {
|
|
10588
10651
|
return;
|
|
10589
10652
|
}
|
|
10590
10653
|
for (const handle of handles) {
|
|
10591
|
-
await scrollIntoView(
|
|
10592
|
-
await
|
|
10654
|
+
await scrollIntoView(session2, handle);
|
|
10655
|
+
await session2.sendAndWait("DOM.focus", toDomNodeDescriptor(handle));
|
|
10593
10656
|
}
|
|
10594
10657
|
};
|
|
10595
|
-
var scrollIntoView = async (
|
|
10658
|
+
var scrollIntoView = async (session2, handle) => {
|
|
10596
10659
|
const descriptor = toDomNodeDescriptor(handle);
|
|
10597
10660
|
try {
|
|
10598
|
-
await
|
|
10661
|
+
await session2.sendAndWait("DOM.scrollIntoViewIfNeeded", descriptor);
|
|
10599
10662
|
return;
|
|
10600
10663
|
} catch {}
|
|
10601
|
-
await callFunctionOnNode(
|
|
10664
|
+
await callFunctionOnNode(session2, descriptor, { code: 'function() { this.scrollIntoView({ block: "center", inline: "center" }); }' }, { onUnresolved: () => createNotInteractableError("Unable to resolve node for scrolling") });
|
|
10602
10665
|
};
|
|
10603
|
-
var scrollDomNodes = async (
|
|
10666
|
+
var scrollDomNodes = async (session2, handles, mode) => {
|
|
10604
10667
|
if (handles.length === 0) {
|
|
10605
|
-
return getViewportScroll(
|
|
10668
|
+
return getViewportScroll(session2);
|
|
10606
10669
|
}
|
|
10607
10670
|
for (const handle of handles) {
|
|
10608
10671
|
if (mode.to || mode.by) {
|
|
10609
|
-
await scrollElementContainer(
|
|
10672
|
+
await scrollElementContainer(session2, handle, mode);
|
|
10610
10673
|
} else {
|
|
10611
|
-
await scrollIntoView(
|
|
10674
|
+
await scrollIntoView(session2, handle);
|
|
10612
10675
|
}
|
|
10613
10676
|
}
|
|
10614
|
-
return getViewportScroll(
|
|
10677
|
+
return getViewportScroll(session2);
|
|
10615
10678
|
};
|
|
10616
|
-
var scrollViewport = async (
|
|
10679
|
+
var scrollViewport = async (session2, mode) => {
|
|
10617
10680
|
const fn = mode.to ? `window.scrollTo(${mode.to.x}, ${mode.to.y})` : `window.scrollBy(${mode.by.x}, ${mode.by.y})`;
|
|
10618
|
-
await evaluateInPage(
|
|
10619
|
-
return getViewportScroll(
|
|
10681
|
+
await evaluateInPage(session2, fn);
|
|
10682
|
+
return getViewportScroll(session2);
|
|
10620
10683
|
};
|
|
10621
|
-
var scrollElementContainer = async (
|
|
10684
|
+
var scrollElementContainer = async (session2, handle, mode) => {
|
|
10622
10685
|
const fn = mode.to ? `function() { this.scrollTo(${mode.to.x}, ${mode.to.y}); }` : `function() { this.scrollBy(${mode.by.x}, ${mode.by.y}); }`;
|
|
10623
|
-
await callFunctionOnNode(
|
|
10686
|
+
await callFunctionOnNode(session2, toDomNodeDescriptor(handle), { code: fn }, {
|
|
10624
10687
|
onUnresolved: () => createNotInteractableError("Unable to resolve node for scrolling")
|
|
10625
10688
|
});
|
|
10626
10689
|
};
|
|
10627
|
-
var getViewportScroll = async (
|
|
10628
|
-
const serialized = await evaluateInPage(
|
|
10690
|
+
var getViewportScroll = async (session2) => {
|
|
10691
|
+
const serialized = await evaluateInPage(session2, "JSON.stringify({scrollX:window.scrollX,scrollY:window.scrollY})");
|
|
10629
10692
|
const parsed = serialized ? JSON.parse(serialized) : { scrollX: 0, scrollY: 0 };
|
|
10630
10693
|
return { scrollX: parsed.scrollX, scrollY: parsed.scrollY };
|
|
10631
10694
|
};
|
|
10632
|
-
var resolveNodePoint = async (
|
|
10633
|
-
const { x, y, w, h } = await resolveNodeRect(
|
|
10695
|
+
var resolveNodePoint = async (session2, handle, offset) => {
|
|
10696
|
+
const { x, y, w, h } = await resolveNodeRect(session2, handle);
|
|
10634
10697
|
if (w <= 0 || h <= 0) {
|
|
10635
10698
|
throw createNotInteractableError("Element has zero area");
|
|
10636
10699
|
}
|
|
@@ -10639,9 +10702,9 @@ var resolveNodePoint = async (session, handle, offset) => {
|
|
|
10639
10702
|
}
|
|
10640
10703
|
return { x: x + w / 2, y: y + h / 2 };
|
|
10641
10704
|
};
|
|
10642
|
-
var resolveNodeRect = async (
|
|
10705
|
+
var resolveNodeRect = async (session2, handle) => {
|
|
10643
10706
|
const descriptor = toDomNodeDescriptor(handle);
|
|
10644
|
-
const boxModel = await
|
|
10707
|
+
const boxModel = await session2.sendAndWait("DOM.getBoxModel", descriptor).catch(() => null);
|
|
10645
10708
|
const quad = boxModel?.model?.border ?? boxModel?.model?.content;
|
|
10646
10709
|
if (quad && quad.length >= 8) {
|
|
10647
10710
|
const xs = [quad[0], quad[2], quad[4], quad[6]];
|
|
@@ -10652,7 +10715,7 @@ var resolveNodeRect = async (session, handle) => {
|
|
|
10652
10715
|
const maxY = Math.max(...ys);
|
|
10653
10716
|
return { x: minX, y: minY, w: maxX - minX, h: maxY - minY };
|
|
10654
10717
|
}
|
|
10655
|
-
const rect = await callFunctionOnNode(
|
|
10718
|
+
const rect = await callFunctionOnNode(session2, descriptor, {
|
|
10656
10719
|
code: "function(){var r=this.getBoundingClientRect();return{x:r.x,y:r.y,w:r.width,h:r.height}}"
|
|
10657
10720
|
});
|
|
10658
10721
|
if (!rect || !Number.isFinite(rect.x) || !Number.isFinite(rect.y)) {
|
|
@@ -10660,8 +10723,8 @@ var resolveNodeRect = async (session, handle) => {
|
|
|
10660
10723
|
}
|
|
10661
10724
|
return rect;
|
|
10662
10725
|
};
|
|
10663
|
-
var emulateScroll = async (
|
|
10664
|
-
await
|
|
10726
|
+
var emulateScroll = async (session2, x, y, delta) => {
|
|
10727
|
+
await session2.sendAndWait("Input.dispatchMouseEvent", {
|
|
10665
10728
|
type: "mouseWheel",
|
|
10666
10729
|
x,
|
|
10667
10730
|
y,
|
|
@@ -10669,18 +10732,18 @@ var emulateScroll = async (session, x, y, delta) => {
|
|
|
10669
10732
|
deltaY: delta.y
|
|
10670
10733
|
});
|
|
10671
10734
|
};
|
|
10672
|
-
var emulateScrollOnNodes = async (
|
|
10735
|
+
var emulateScrollOnNodes = async (session2, handles, delta) => {
|
|
10673
10736
|
if (handles.length === 0) {
|
|
10674
10737
|
return;
|
|
10675
10738
|
}
|
|
10676
10739
|
for (const handle of handles) {
|
|
10677
|
-
await scrollIntoView(
|
|
10678
|
-
const point = await resolveNodePoint(
|
|
10679
|
-
await emulateScroll(
|
|
10740
|
+
await scrollIntoView(session2, handle);
|
|
10741
|
+
const point = await resolveNodePoint(session2, handle);
|
|
10742
|
+
await emulateScroll(session2, point.x, point.y, delta);
|
|
10680
10743
|
}
|
|
10681
10744
|
};
|
|
10682
|
-
var dispatchMouseEvent = async (
|
|
10683
|
-
await
|
|
10745
|
+
var dispatchMouseEvent = async (session2, options) => {
|
|
10746
|
+
await session2.sendAndWait("Input.dispatchMouseEvent", {
|
|
10684
10747
|
type: options.type,
|
|
10685
10748
|
x: options.x,
|
|
10686
10749
|
y: options.y,
|
|
@@ -10841,6 +10904,11 @@ var buildKeyMaps = () => {
|
|
|
10841
10904
|
byKey.set(lookup.toLowerCase(), def);
|
|
10842
10905
|
byCode.set(def.code.toLowerCase(), def);
|
|
10843
10906
|
};
|
|
10907
|
+
const putShiftAlias = (def) => {
|
|
10908
|
+
if (def.shiftKey) {
|
|
10909
|
+
byKey.set(def.shiftKey.toLowerCase(), def);
|
|
10910
|
+
}
|
|
10911
|
+
};
|
|
10844
10912
|
for (let i = 0;i < 26; i++) {
|
|
10845
10913
|
const lower = String.fromCharCode(97 + i);
|
|
10846
10914
|
const upper = String.fromCharCode(65 + i);
|
|
@@ -10848,11 +10916,32 @@ var buildKeyMaps = () => {
|
|
|
10848
10916
|
const keyCode = 65 + i;
|
|
10849
10917
|
put(lower, { key: lower, code: code2, keyCode, text: lower });
|
|
10850
10918
|
}
|
|
10919
|
+
const DIGIT_SHIFT_KEYS = ")!@#$%^&*(";
|
|
10851
10920
|
for (let i = 0;i < 10; i++) {
|
|
10852
10921
|
const digit = String(i);
|
|
10853
10922
|
const code2 = `Digit${digit}`;
|
|
10854
10923
|
const keyCode = 48 + i;
|
|
10855
|
-
|
|
10924
|
+
const def = { key: digit, code: code2, keyCode, text: digit, shiftKey: DIGIT_SHIFT_KEYS[i] };
|
|
10925
|
+
put(digit, def);
|
|
10926
|
+
putShiftAlias(def);
|
|
10927
|
+
}
|
|
10928
|
+
const PUNCTUATION = [
|
|
10929
|
+
["Backquote", "`", "~", 192],
|
|
10930
|
+
["Minus", "-", "_", 189],
|
|
10931
|
+
["Equal", "=", "+", 187],
|
|
10932
|
+
["BracketLeft", "[", "{", 219],
|
|
10933
|
+
["BracketRight", "]", "}", 221],
|
|
10934
|
+
["Backslash", "\\", "|", 220],
|
|
10935
|
+
["Semicolon", ";", ":", 186],
|
|
10936
|
+
["Quote", "'", '"', 222],
|
|
10937
|
+
["Comma", ",", "<", 188],
|
|
10938
|
+
["Period", ".", ">", 190],
|
|
10939
|
+
["Slash", "/", "?", 191]
|
|
10940
|
+
];
|
|
10941
|
+
for (const [code2, key, shiftKey, keyCode] of PUNCTUATION) {
|
|
10942
|
+
const def = { key, code: code2, keyCode, text: key, shiftKey };
|
|
10943
|
+
put(key, def);
|
|
10944
|
+
putShiftAlias(def);
|
|
10856
10945
|
}
|
|
10857
10946
|
put("Enter", { key: "Enter", code: "Enter", keyCode: 13, text: "\r" });
|
|
10858
10947
|
put("Tab", { key: "Tab", code: "Tab", keyCode: 9 });
|
|
@@ -10931,7 +11020,7 @@ var resolveKeyboardEvent = (options) => {
|
|
|
10931
11020
|
const text = resolveEventText(key, baseDef);
|
|
10932
11021
|
const event = {
|
|
10933
11022
|
key,
|
|
10934
|
-
code: codeInput ?? baseDef.code,
|
|
11023
|
+
code: codeDef?.code ?? codeInput ?? baseDef.code,
|
|
10935
11024
|
keyCode: baseDef.keyCode,
|
|
10936
11025
|
modifiers,
|
|
10937
11026
|
altKey: (modifiers & MODIFIER_BITS.alt) !== 0,
|
|
@@ -10953,6 +11042,9 @@ var resolveEventKey = (keyInput, def, modifiers) => {
|
|
|
10953
11042
|
if (isSingleLetter(semanticKey)) {
|
|
10954
11043
|
return isShift(modifiers) ? semanticKey.toUpperCase() : semanticKey.toLowerCase();
|
|
10955
11044
|
}
|
|
11045
|
+
if (isShift(modifiers) && def.shiftKey && semanticKey === def.key) {
|
|
11046
|
+
return def.shiftKey;
|
|
11047
|
+
}
|
|
10956
11048
|
return semanticKey;
|
|
10957
11049
|
};
|
|
10958
11050
|
var resolveEventText = (key, def) => {
|
|
@@ -10963,12 +11055,12 @@ var resolveEventText = (key, def) => {
|
|
|
10963
11055
|
};
|
|
10964
11056
|
var isSingleLetter = (value) => /^[a-z]$/i.test(value);
|
|
10965
11057
|
var isShift = (modifiers) => (modifiers & MODIFIER_BITS.shift) !== 0;
|
|
10966
|
-
var dispatchKeydown = async (
|
|
11058
|
+
var dispatchKeydown = async (session2, options) => {
|
|
10967
11059
|
const { selector } = options;
|
|
10968
11060
|
const event = resolveKeyboardEvent(options);
|
|
10969
11061
|
let focused = false;
|
|
10970
11062
|
if (selector) {
|
|
10971
|
-
const { allNodeIds, nodeIds } = await resolveDomSelectorMatches(
|
|
11063
|
+
const { allNodeIds, nodeIds } = await resolveDomSelectorMatches(session2, selector, false);
|
|
10972
11064
|
if (allNodeIds.length === 0) {
|
|
10973
11065
|
throw new Error(`No element found for selector: ${selector}`);
|
|
10974
11066
|
}
|
|
@@ -10976,7 +11068,7 @@ var dispatchKeydown = async (session, options) => {
|
|
|
10976
11068
|
throw codedError("multiple_matches", `Selector matched ${allNodeIds.length} elements; keydown requires exactly one target`);
|
|
10977
11069
|
}
|
|
10978
11070
|
const nodeId = nodeIds[0];
|
|
10979
|
-
await
|
|
11071
|
+
await session2.sendAndWait("DOM.focus", { nodeId });
|
|
10980
11072
|
focused = true;
|
|
10981
11073
|
}
|
|
10982
11074
|
const isPrintable = event.text != null && event.text !== "\r";
|
|
@@ -10988,12 +11080,12 @@ var dispatchKeydown = async (session, options) => {
|
|
|
10988
11080
|
modifiers: event.modifiers
|
|
10989
11081
|
};
|
|
10990
11082
|
if (isPrintable) {
|
|
10991
|
-
await
|
|
10992
|
-
await
|
|
10993
|
-
await
|
|
11083
|
+
await session2.sendAndWait("Input.dispatchKeyEvent", { ...baseParams, type: "keyDown", text: event.text });
|
|
11084
|
+
await session2.sendAndWait("Input.dispatchKeyEvent", { ...baseParams, type: "char", text: event.text });
|
|
11085
|
+
await session2.sendAndWait("Input.dispatchKeyEvent", { ...baseParams, type: "keyUp" });
|
|
10994
11086
|
} else {
|
|
10995
|
-
await
|
|
10996
|
-
await
|
|
11087
|
+
await session2.sendAndWait("Input.dispatchKeyEvent", { ...baseParams, type: "rawKeyDown", text: event.text });
|
|
11088
|
+
await session2.sendAndWait("Input.dispatchKeyEvent", { ...baseParams, type: "keyUp" });
|
|
10997
11089
|
}
|
|
10998
11090
|
return { key: event.key, code: event.code, modifiers: event.modifiers, focused, event };
|
|
10999
11091
|
};
|
|
@@ -11195,8 +11287,8 @@ var route39 = defineJsonRoute({
|
|
|
11195
11287
|
return { ok: true, matches: allNodeIds.length, scrolled: nodeIds.length };
|
|
11196
11288
|
}
|
|
11197
11289
|
});
|
|
11198
|
-
var getViewportSize = async (
|
|
11199
|
-
const serialized = await evaluateInPage(
|
|
11290
|
+
var getViewportSize = async (session2) => {
|
|
11291
|
+
const serialized = await evaluateInPage(session2, "JSON.stringify({width:window.innerWidth,height:window.innerHeight})");
|
|
11200
11292
|
const parsed = serialized ? JSON.parse(serialized) : { width: 800, height: 600 };
|
|
11201
11293
|
return { width: parsed.width, height: parsed.height };
|
|
11202
11294
|
};
|
|
@@ -11242,11 +11334,11 @@ var route42 = defineJsonRoute({
|
|
|
11242
11334
|
bodySchema: emulationRequestSchema,
|
|
11243
11335
|
endpoint: "emulation",
|
|
11244
11336
|
handle: async ({ ctx, body: payload }) => {
|
|
11245
|
-
const
|
|
11337
|
+
const session2 = ctx.cdpSession.isAttached() ? ctx.cdpSession : null;
|
|
11246
11338
|
if (payload.action === "clear") {
|
|
11247
|
-
return ctx.emulationController.clearDesired(
|
|
11339
|
+
return ctx.emulationController.clearDesired(session2);
|
|
11248
11340
|
}
|
|
11249
|
-
return ctx.emulationController.setDesired(payload.state,
|
|
11341
|
+
return ctx.emulationController.setDesired(payload.state, session2);
|
|
11250
11342
|
}
|
|
11251
11343
|
});
|
|
11252
11344
|
|
|
@@ -11265,11 +11357,11 @@ var route44 = defineJsonRoute({
|
|
|
11265
11357
|
bodySchema: throttleRequestSchema,
|
|
11266
11358
|
endpoint: "throttle",
|
|
11267
11359
|
handle: ({ ctx, body: payload }) => {
|
|
11268
|
-
const
|
|
11360
|
+
const session2 = ctx.cdpSession.isAttached() ? ctx.cdpSession : null;
|
|
11269
11361
|
if (payload.action === "clear") {
|
|
11270
|
-
return ctx.throttleController.clearDesired(
|
|
11362
|
+
return ctx.throttleController.clearDesired(session2);
|
|
11271
11363
|
}
|
|
11272
|
-
return ctx.throttleController.setDesired(payload.rate,
|
|
11364
|
+
return ctx.throttleController.setDesired(payload.rate, session2);
|
|
11273
11365
|
}
|
|
11274
11366
|
});
|
|
11275
11367
|
|
|
@@ -11319,9 +11411,9 @@ var route47 = defineJsonRoute({
|
|
|
11319
11411
|
endpoint: "visibility",
|
|
11320
11412
|
handle: async ({ ctx, body: payload }) => {
|
|
11321
11413
|
const lock = payload.action === "show" ? "shown" : "default";
|
|
11322
|
-
const
|
|
11323
|
-
const attached =
|
|
11324
|
-
await ctx.visibilityController.setLock(attached ?
|
|
11414
|
+
const session2 = ctx.pageCdpSession;
|
|
11415
|
+
const attached = session2.isAttached();
|
|
11416
|
+
await ctx.visibilityController.setLock(attached ? session2 : null, lock);
|
|
11325
11417
|
return { ok: true, attached, state: lock };
|
|
11326
11418
|
}
|
|
11327
11419
|
});
|
|
@@ -11331,8 +11423,8 @@ var storageAccessors = {
|
|
|
11331
11423
|
local: "localStorage",
|
|
11332
11424
|
session: "sessionStorage"
|
|
11333
11425
|
};
|
|
11334
|
-
var executeStorage = async (
|
|
11335
|
-
return await evaluateInPage(
|
|
11426
|
+
var executeStorage = async (session2, area, request) => {
|
|
11427
|
+
return await evaluateInPage(session2, buildStorageExpression(area, request), { timeoutMs: 5000 });
|
|
11336
11428
|
};
|
|
11337
11429
|
var buildStorageExpression = (area, request) => {
|
|
11338
11430
|
return `(() => {
|
|
@@ -11676,8 +11768,8 @@ var createInjectOnAttach = (inject, record2) => {
|
|
|
11676
11768
|
if (!inject?.script) {
|
|
11677
11769
|
return async () => {};
|
|
11678
11770
|
}
|
|
11679
|
-
return async (
|
|
11680
|
-
if (!
|
|
11771
|
+
return async (session2, target) => {
|
|
11772
|
+
if (!session2.isAttached()) {
|
|
11681
11773
|
return;
|
|
11682
11774
|
}
|
|
11683
11775
|
const trimmedScript = inject.script.trim();
|
|
@@ -11699,8 +11791,8 @@ var createInjectOnAttach = (inject, record2) => {
|
|
|
11699
11791
|
}
|
|
11700
11792
|
} : null;
|
|
11701
11793
|
const expression = buildInjectExpression(trimmedScript, argusPayload);
|
|
11702
|
-
await runInjectStep("register", record2.id, () =>
|
|
11703
|
-
await runInjectStep("run", record2.id, () =>
|
|
11794
|
+
await runInjectStep("register", record2.id, () => session2.sendAndWait("Page.addScriptToEvaluateOnNewDocument", { source: expression }));
|
|
11795
|
+
await runInjectStep("run", record2.id, () => session2.sendAndWait("Runtime.evaluate", { expression, silent: true }));
|
|
11704
11796
|
};
|
|
11705
11797
|
};
|
|
11706
11798
|
var runInjectStep = async (step, watcherId, action) => {
|
|
@@ -12150,11 +12242,11 @@ var createPageIndicatorController = (options) => {
|
|
|
12150
12242
|
let currentSession = null;
|
|
12151
12243
|
let currentInfo = null;
|
|
12152
12244
|
let currentState = { recording: false };
|
|
12153
|
-
const onAttach = (
|
|
12245
|
+
const onAttach = (session2, _target, info) => {
|
|
12154
12246
|
stop();
|
|
12155
|
-
currentSession =
|
|
12247
|
+
currentSession = session2;
|
|
12156
12248
|
currentInfo = info;
|
|
12157
|
-
installIndicator(
|
|
12249
|
+
installIndicator(session2, {
|
|
12158
12250
|
info,
|
|
12159
12251
|
position,
|
|
12160
12252
|
ttlMs,
|
|
@@ -12172,9 +12264,9 @@ var createPageIndicatorController = (options) => {
|
|
|
12172
12264
|
sendHeartbeat(currentSession, currentInfo, currentState);
|
|
12173
12265
|
}, heartbeatMs);
|
|
12174
12266
|
};
|
|
12175
|
-
const onNavigation = (
|
|
12267
|
+
const onNavigation = (session2, info) => {
|
|
12176
12268
|
currentInfo = info;
|
|
12177
|
-
installIndicator(
|
|
12269
|
+
installIndicator(session2, {
|
|
12178
12270
|
info,
|
|
12179
12271
|
position,
|
|
12180
12272
|
ttlMs,
|
|
@@ -12229,7 +12321,7 @@ var createPageIndicatorController = (options) => {
|
|
|
12229
12321
|
};
|
|
12230
12322
|
return { onAttach, onNavigation, setRecording, reinstall, onDetach, stop };
|
|
12231
12323
|
};
|
|
12232
|
-
var installIndicator = async (
|
|
12324
|
+
var installIndicator = async (session2, params) => {
|
|
12233
12325
|
const { info, position, ttlMs, bgColor, hoverBgColor, iconColor, margin, size, state: state2 } = params;
|
|
12234
12326
|
const expression = buildInstallExpression({
|
|
12235
12327
|
info,
|
|
@@ -12242,15 +12334,15 @@ var installIndicator = async (session, params) => {
|
|
|
12242
12334
|
size,
|
|
12243
12335
|
state: state2
|
|
12244
12336
|
});
|
|
12245
|
-
await tryEvaluateInPage(
|
|
12337
|
+
await tryEvaluateInPage(session2, expression);
|
|
12246
12338
|
};
|
|
12247
|
-
var sendHeartbeat = async (
|
|
12339
|
+
var sendHeartbeat = async (session2, info, state2) => {
|
|
12248
12340
|
const expression = buildHeartbeatExpression(info, state2);
|
|
12249
|
-
await tryEvaluateInPage(
|
|
12341
|
+
await tryEvaluateInPage(session2, expression);
|
|
12250
12342
|
};
|
|
12251
|
-
var removeIndicator = async (
|
|
12343
|
+
var removeIndicator = async (session2) => {
|
|
12252
12344
|
const expression = buildRemoveExpression();
|
|
12253
|
-
await tryEvaluateInPage(
|
|
12345
|
+
await tryEvaluateInPage(session2, expression);
|
|
12254
12346
|
};
|
|
12255
12347
|
|
|
12256
12348
|
// ../argus-watcher/dist/runtime/watcherIndicator.js
|
|
@@ -12268,23 +12360,23 @@ var createIndicatorBinding = (input) => {
|
|
|
12268
12360
|
attachedAt: attachedAt ?? Date.now()
|
|
12269
12361
|
});
|
|
12270
12362
|
return {
|
|
12271
|
-
onNavigation: (
|
|
12363
|
+
onNavigation: (session2, info) => {
|
|
12272
12364
|
if (!controller) {
|
|
12273
12365
|
return;
|
|
12274
12366
|
}
|
|
12275
12367
|
const status2 = input.getCdpStatus();
|
|
12276
12368
|
const target = status2.attached ? { title: status2.target?.title ?? null, url: status2.target?.url ?? info.url } : { title: null, url: info.url };
|
|
12277
|
-
controller.onNavigation(
|
|
12369
|
+
controller.onNavigation(session2, buildInfo(target));
|
|
12278
12370
|
},
|
|
12279
12371
|
onLoad: () => {
|
|
12280
12372
|
controller?.reinstall();
|
|
12281
12373
|
},
|
|
12282
|
-
onAttach: (
|
|
12374
|
+
onAttach: (session2, target) => {
|
|
12283
12375
|
if (!controller) {
|
|
12284
12376
|
return;
|
|
12285
12377
|
}
|
|
12286
12378
|
attachedAt = Date.now();
|
|
12287
|
-
controller.onAttach(
|
|
12379
|
+
controller.onAttach(session2, {
|
|
12288
12380
|
id: target.id,
|
|
12289
12381
|
title: target.title,
|
|
12290
12382
|
url: target.url,
|
|
@@ -13530,7 +13622,7 @@ var nextId = 1;
|
|
|
13530
13622
|
var createCdpSessionHandle = () => {
|
|
13531
13623
|
let connection = null;
|
|
13532
13624
|
const handlers = new Map;
|
|
13533
|
-
const
|
|
13625
|
+
const session2 = {
|
|
13534
13626
|
isAttached: () => Boolean(connection),
|
|
13535
13627
|
sendAndWait: async (method, params, options) => {
|
|
13536
13628
|
if (!connection) {
|
|
@@ -13633,7 +13725,7 @@ var createCdpSessionHandle = () => {
|
|
|
13633
13725
|
}
|
|
13634
13726
|
connection = null;
|
|
13635
13727
|
};
|
|
13636
|
-
return { session, attach, detach };
|
|
13728
|
+
return { session: session2, attach, detach };
|
|
13637
13729
|
};
|
|
13638
13730
|
var createCdpNotAttachedError = () => createNotAttachedError("Watcher not attached to a CDP target");
|
|
13639
13731
|
var parseMessage = (data) => {
|
|
@@ -13686,30 +13778,30 @@ var openCdpConnection = async (wsUrl, connectTimeoutMs = 5000) => {
|
|
|
13686
13778
|
};
|
|
13687
13779
|
|
|
13688
13780
|
// ../argus-watcher/dist/cdp/emulation.js
|
|
13689
|
-
var applyEmulation = async (
|
|
13781
|
+
var applyEmulation = async (session2, state2, baseline) => {
|
|
13690
13782
|
if (state2.viewport) {
|
|
13691
|
-
await
|
|
13783
|
+
await session2.sendAndWait("Emulation.setDeviceMetricsOverride", {
|
|
13692
13784
|
width: state2.viewport.width,
|
|
13693
13785
|
height: state2.viewport.height,
|
|
13694
13786
|
deviceScaleFactor: state2.viewport.deviceScaleFactor,
|
|
13695
13787
|
mobile: state2.viewport.mobile
|
|
13696
13788
|
});
|
|
13697
13789
|
} else {
|
|
13698
|
-
await
|
|
13790
|
+
await session2.sendAndWait("Emulation.clearDeviceMetricsOverride");
|
|
13699
13791
|
}
|
|
13700
13792
|
const touchEnabled = state2.touch?.enabled ?? false;
|
|
13701
|
-
await
|
|
13793
|
+
await session2.sendAndWait("Emulation.setTouchEmulationEnabled", { enabled: touchEnabled });
|
|
13702
13794
|
if (state2.userAgent?.value != null) {
|
|
13703
|
-
await
|
|
13795
|
+
await session2.sendAndWait("Emulation.setUserAgentOverride", { userAgent: state2.userAgent.value });
|
|
13704
13796
|
} else if (baseline.userAgent) {
|
|
13705
|
-
await
|
|
13797
|
+
await session2.sendAndWait("Emulation.setUserAgentOverride", { userAgent: baseline.userAgent });
|
|
13706
13798
|
}
|
|
13707
13799
|
};
|
|
13708
|
-
var clearEmulation = async (
|
|
13709
|
-
await
|
|
13710
|
-
await
|
|
13800
|
+
var clearEmulation = async (session2, baseline) => {
|
|
13801
|
+
await session2.sendAndWait("Emulation.clearDeviceMetricsOverride");
|
|
13802
|
+
await session2.sendAndWait("Emulation.setTouchEmulationEnabled", { enabled: false });
|
|
13711
13803
|
if (baseline.userAgent) {
|
|
13712
|
-
await
|
|
13804
|
+
await session2.sendAndWait("Emulation.setUserAgentOverride", { userAgent: baseline.userAgent });
|
|
13713
13805
|
}
|
|
13714
13806
|
};
|
|
13715
13807
|
|
|
@@ -13719,7 +13811,7 @@ var createStickyController = (options) => {
|
|
|
13719
13811
|
let applied = false;
|
|
13720
13812
|
let lastError = null;
|
|
13721
13813
|
const getState = () => ({ applied, state: desired, lastError });
|
|
13722
|
-
const run = async (
|
|
13814
|
+
const run = async (session2, action, appliedOnSuccess) => {
|
|
13723
13815
|
try {
|
|
13724
13816
|
await action();
|
|
13725
13817
|
applied = appliedOnSuccess;
|
|
@@ -13737,30 +13829,30 @@ var createStickyController = (options) => {
|
|
|
13737
13829
|
};
|
|
13738
13830
|
return {
|
|
13739
13831
|
getState,
|
|
13740
|
-
setDesired: async (state2,
|
|
13832
|
+
setDesired: async (state2, session2) => {
|
|
13741
13833
|
desired = state2;
|
|
13742
13834
|
lastError = null;
|
|
13743
|
-
if (!
|
|
13835
|
+
if (!session2?.isAttached()) {
|
|
13744
13836
|
return detached();
|
|
13745
13837
|
}
|
|
13746
|
-
return await run(
|
|
13838
|
+
return await run(session2, () => options.apply(session2, state2), true);
|
|
13747
13839
|
},
|
|
13748
|
-
clearDesired: async (
|
|
13840
|
+
clearDesired: async (session2) => {
|
|
13749
13841
|
desired = null;
|
|
13750
13842
|
lastError = null;
|
|
13751
|
-
if (!
|
|
13843
|
+
if (!session2?.isAttached()) {
|
|
13752
13844
|
return detached();
|
|
13753
13845
|
}
|
|
13754
|
-
return await run(
|
|
13846
|
+
return await run(session2, () => options.clear(session2), false);
|
|
13755
13847
|
},
|
|
13756
|
-
onAttach: async (
|
|
13757
|
-
await options.onBeforeReapply?.(
|
|
13848
|
+
onAttach: async (session2) => {
|
|
13849
|
+
await options.onBeforeReapply?.(session2);
|
|
13758
13850
|
if (!desired) {
|
|
13759
13851
|
applied = false;
|
|
13760
13852
|
return;
|
|
13761
13853
|
}
|
|
13762
13854
|
try {
|
|
13763
|
-
await options.apply(
|
|
13855
|
+
await options.apply(session2, desired);
|
|
13764
13856
|
applied = true;
|
|
13765
13857
|
lastError = null;
|
|
13766
13858
|
} catch (error) {
|
|
@@ -13778,10 +13870,10 @@ var createEmulationController = () => {
|
|
|
13778
13870
|
const getBaseline = () => ({ userAgent: baselineUserAgent });
|
|
13779
13871
|
const sticky = createStickyController({
|
|
13780
13872
|
label: "Emulation",
|
|
13781
|
-
apply: (
|
|
13782
|
-
clear: (
|
|
13783
|
-
onBeforeReapply: async (
|
|
13784
|
-
const value = await evaluateInPage(
|
|
13873
|
+
apply: (session2, state2) => applyEmulation(session2, state2, getBaseline()),
|
|
13874
|
+
clear: (session2) => clearEmulation(session2, getBaseline()),
|
|
13875
|
+
onBeforeReapply: async (session2) => {
|
|
13876
|
+
const value = await evaluateInPage(session2, "navigator.userAgent").catch(() => null);
|
|
13785
13877
|
baselineUserAgent = typeof value === "string" ? value : null;
|
|
13786
13878
|
}
|
|
13787
13879
|
});
|
|
@@ -13790,12 +13882,12 @@ var createEmulationController = () => {
|
|
|
13790
13882
|
const { applied, state: state2, lastError } = sticky.getState();
|
|
13791
13883
|
return { ok: true, attached: ctx.attached, applied, state: state2, baseline: getBaseline(), lastError };
|
|
13792
13884
|
},
|
|
13793
|
-
setDesired: async (state2,
|
|
13794
|
-
const { attached, applied, state: next, lastError } = await sticky.setDesired(state2,
|
|
13885
|
+
setDesired: async (state2, session2) => {
|
|
13886
|
+
const { attached, applied, state: next, lastError } = await sticky.setDesired(state2, session2);
|
|
13795
13887
|
return { ok: true, attached, applied, state: next, ...lastError ? { error: lastError } : {} };
|
|
13796
13888
|
},
|
|
13797
|
-
clearDesired: async (
|
|
13798
|
-
const { attached, applied, lastError } = await sticky.clearDesired(
|
|
13889
|
+
clearDesired: async (session2) => {
|
|
13890
|
+
const { attached, applied, lastError } = await sticky.clearDesired(session2);
|
|
13799
13891
|
return { ok: true, attached, applied, state: null, ...lastError ? { error: lastError } : {} };
|
|
13800
13892
|
},
|
|
13801
13893
|
onAttach: sticky.onAttach
|
|
@@ -13803,31 +13895,31 @@ var createEmulationController = () => {
|
|
|
13803
13895
|
};
|
|
13804
13896
|
|
|
13805
13897
|
// ../argus-watcher/dist/cdp/throttle.js
|
|
13806
|
-
var applyThrottle = async (
|
|
13807
|
-
await
|
|
13898
|
+
var applyThrottle = async (session2, rate) => {
|
|
13899
|
+
await session2.sendAndWait("Emulation.setCPUThrottlingRate", { rate });
|
|
13808
13900
|
};
|
|
13809
|
-
var clearThrottle = async (
|
|
13810
|
-
await
|
|
13901
|
+
var clearThrottle = async (session2) => {
|
|
13902
|
+
await session2.sendAndWait("Emulation.setCPUThrottlingRate", { rate: 1 });
|
|
13811
13903
|
};
|
|
13812
13904
|
|
|
13813
13905
|
// ../argus-watcher/dist/throttle/ThrottleController.js
|
|
13814
13906
|
var createThrottleController = () => {
|
|
13815
13907
|
const sticky = createStickyController({
|
|
13816
13908
|
label: "Throttle",
|
|
13817
|
-
apply: (
|
|
13818
|
-
clear: (
|
|
13909
|
+
apply: (session2, state2) => applyThrottle(session2, state2.rate),
|
|
13910
|
+
clear: (session2) => clearThrottle(session2)
|
|
13819
13911
|
});
|
|
13820
13912
|
return {
|
|
13821
13913
|
getStatus: (ctx) => {
|
|
13822
13914
|
const { applied, state: state2, lastError } = sticky.getState();
|
|
13823
13915
|
return { ok: true, attached: ctx.attached, applied, state: state2, lastError };
|
|
13824
13916
|
},
|
|
13825
|
-
setDesired: async (rate,
|
|
13826
|
-
const { attached, applied, state: state2, lastError } = await sticky.setDesired({ rate },
|
|
13917
|
+
setDesired: async (rate, session2) => {
|
|
13918
|
+
const { attached, applied, state: state2, lastError } = await sticky.setDesired({ rate }, session2);
|
|
13827
13919
|
return { ok: true, attached, applied, state: state2, ...lastError ? { error: lastError } : {} };
|
|
13828
13920
|
},
|
|
13829
|
-
clearDesired: async (
|
|
13830
|
-
const { attached, applied, lastError } = await sticky.clearDesired(
|
|
13921
|
+
clearDesired: async (session2) => {
|
|
13922
|
+
const { attached, applied, lastError } = await sticky.clearDesired(session2);
|
|
13831
13923
|
return { ok: true, attached, applied, state: null, ...lastError ? { error: lastError } : {} };
|
|
13832
13924
|
},
|
|
13833
13925
|
onAttach: sticky.onAttach
|
|
@@ -13896,8 +13988,8 @@ class NetMockInterception {
|
|
|
13896
13988
|
if (reset) {
|
|
13897
13989
|
this.enabledTargets.clear();
|
|
13898
13990
|
}
|
|
13899
|
-
const
|
|
13900
|
-
if (!
|
|
13991
|
+
const session2 = this.binding?.pageSession;
|
|
13992
|
+
if (!session2?.isAttached()) {
|
|
13901
13993
|
this.enabledTargets.clear();
|
|
13902
13994
|
return false;
|
|
13903
13995
|
}
|
|
@@ -13936,12 +14028,12 @@ class NetMockInterception {
|
|
|
13936
14028
|
return targets;
|
|
13937
14029
|
}
|
|
13938
14030
|
async sendCommand(target, method, params = {}) {
|
|
13939
|
-
const
|
|
13940
|
-
if (!
|
|
14031
|
+
const session2 = this.binding?.pageSession;
|
|
14032
|
+
if (!session2?.isAttached()) {
|
|
13941
14033
|
return false;
|
|
13942
14034
|
}
|
|
13943
14035
|
try {
|
|
13944
|
-
await
|
|
14036
|
+
await session2.sendAndWait(method, params, target.sessionId ? { sessionId: target.sessionId } : undefined);
|
|
13945
14037
|
return true;
|
|
13946
14038
|
} catch (error) {
|
|
13947
14039
|
if (!isBenignInterceptionError(error)) {
|
|
@@ -14157,35 +14249,35 @@ var toPublicRule = (rule) => ({
|
|
|
14157
14249
|
});
|
|
14158
14250
|
|
|
14159
14251
|
// ../argus-watcher/dist/visibility/VisibilityController.js
|
|
14160
|
-
var applyLock = async (
|
|
14252
|
+
var applyLock = async (session2, lock) => {
|
|
14161
14253
|
if (lock !== "shown") {
|
|
14162
|
-
await
|
|
14254
|
+
await session2.sendAndWait("Emulation.setFocusEmulationEnabled", { enabled: false });
|
|
14163
14255
|
return;
|
|
14164
14256
|
}
|
|
14165
14257
|
try {
|
|
14166
|
-
await
|
|
14258
|
+
await session2.sendAndWait("Page.bringToFront");
|
|
14167
14259
|
} catch {}
|
|
14168
|
-
await
|
|
14260
|
+
await session2.sendAndWait("Emulation.setFocusEmulationEnabled", { enabled: true });
|
|
14169
14261
|
};
|
|
14170
14262
|
var createVisibilityController = () => {
|
|
14171
14263
|
const sticky = createStickyController({
|
|
14172
14264
|
label: "Visibility",
|
|
14173
14265
|
apply: applyLock,
|
|
14174
|
-
clear: (
|
|
14266
|
+
clear: (session2) => applyLock(session2, "default")
|
|
14175
14267
|
});
|
|
14176
14268
|
return {
|
|
14177
14269
|
getDesired: () => sticky.getState().state ?? "default",
|
|
14178
|
-
setLock: async (
|
|
14179
|
-
const result = await sticky.setDesired(lock,
|
|
14270
|
+
setLock: async (session2, lock) => {
|
|
14271
|
+
const result = await sticky.setDesired(lock, session2);
|
|
14180
14272
|
if (result.lastError) {
|
|
14181
14273
|
throw new Error(result.lastError.message);
|
|
14182
14274
|
}
|
|
14183
14275
|
},
|
|
14184
|
-
onAttach: async (
|
|
14276
|
+
onAttach: async (session2) => {
|
|
14185
14277
|
if (sticky.getState().state !== "shown") {
|
|
14186
14278
|
return;
|
|
14187
14279
|
}
|
|
14188
|
-
await sticky.onAttach(
|
|
14280
|
+
await sticky.onAttach(session2);
|
|
14189
14281
|
}
|
|
14190
14282
|
};
|
|
14191
14283
|
};
|
|
@@ -14992,25 +15084,25 @@ var createTraceRecorder = (options) => {
|
|
|
14992
15084
|
import fs7 from "node:fs/promises";
|
|
14993
15085
|
|
|
14994
15086
|
// ../argus-watcher/dist/cdp/visualCapture.js
|
|
14995
|
-
var createVisualCapturePlan = async (
|
|
15087
|
+
var createVisualCapturePlan = async (session2, pageSession, request) => {
|
|
14996
15088
|
const subject = resolveVisualCaptureSubject(request);
|
|
14997
|
-
const targetContext = await
|
|
15089
|
+
const targetContext = await session2.getReadyTargetContext();
|
|
14998
15090
|
if (targetContext?.kind === "frame" && pageSession) {
|
|
14999
15091
|
return createFrameCapturePlan({
|
|
15000
|
-
frameSession:
|
|
15092
|
+
frameSession: session2,
|
|
15001
15093
|
pageSession,
|
|
15002
15094
|
frameContext: targetContext,
|
|
15003
15095
|
subject
|
|
15004
15096
|
});
|
|
15005
15097
|
}
|
|
15006
|
-
const clip = await resolveSubjectClip(
|
|
15098
|
+
const clip = await resolveSubjectClip(session2, subject);
|
|
15007
15099
|
if (!clip) {
|
|
15008
|
-
return { session };
|
|
15100
|
+
return { session: session2 };
|
|
15009
15101
|
}
|
|
15010
15102
|
return {
|
|
15011
|
-
session,
|
|
15103
|
+
session: session2,
|
|
15012
15104
|
clip,
|
|
15013
|
-
viewport: await resolveViewportSize(
|
|
15105
|
+
viewport: await resolveViewportSize(session2)
|
|
15014
15106
|
};
|
|
15015
15107
|
};
|
|
15016
15108
|
var createFrameCapturePlan = async (options) => {
|
|
@@ -15039,21 +15131,21 @@ var resolveFrameViewportClip = async (pageSession, frameId) => {
|
|
|
15039
15131
|
}
|
|
15040
15132
|
return resolveNodeClip(pageSession, owner);
|
|
15041
15133
|
};
|
|
15042
|
-
var resolveSelectorClip = async (
|
|
15043
|
-
const nodeId = await resolveFirstSelectorNodeId(
|
|
15134
|
+
var resolveSelectorClip = async (session2, selector) => {
|
|
15135
|
+
const nodeId = await resolveFirstSelectorNodeId(session2, selector);
|
|
15044
15136
|
if (!nodeId) {
|
|
15045
15137
|
throw new Error(`No element found for selector: ${selector}`);
|
|
15046
15138
|
}
|
|
15047
|
-
return resolveNodeClip(
|
|
15139
|
+
return resolveNodeClip(session2, { nodeId });
|
|
15048
15140
|
};
|
|
15049
|
-
var resolveSubjectClip = async (
|
|
15141
|
+
var resolveSubjectClip = async (session2, subject) => {
|
|
15050
15142
|
switch (subject.kind) {
|
|
15051
15143
|
case "viewport":
|
|
15052
15144
|
return null;
|
|
15053
15145
|
case "selector":
|
|
15054
|
-
return resolveSelectorClip(
|
|
15146
|
+
return resolveSelectorClip(session2, subject.selector);
|
|
15055
15147
|
case "clip":
|
|
15056
|
-
return resolveViewportRectClip(
|
|
15148
|
+
return resolveViewportRectClip(session2, subject.clip);
|
|
15057
15149
|
}
|
|
15058
15150
|
};
|
|
15059
15151
|
var resolveVisualCaptureSubject = (request) => {
|
|
@@ -15065,8 +15157,8 @@ var resolveVisualCaptureSubject = (request) => {
|
|
|
15065
15157
|
}
|
|
15066
15158
|
return { kind: "viewport" };
|
|
15067
15159
|
};
|
|
15068
|
-
var resolveViewportRectClip = async (
|
|
15069
|
-
const viewport = await resolveVisualViewport(
|
|
15160
|
+
var resolveViewportRectClip = async (session2, clip) => {
|
|
15161
|
+
const viewport = await resolveVisualViewport(session2);
|
|
15070
15162
|
return {
|
|
15071
15163
|
x: clip.x,
|
|
15072
15164
|
y: clip.y,
|
|
@@ -15075,8 +15167,8 @@ var resolveViewportRectClip = async (session, clip) => {
|
|
|
15075
15167
|
scale: viewport?.scale ?? 1
|
|
15076
15168
|
};
|
|
15077
15169
|
};
|
|
15078
|
-
var resolveNodeClip = async (
|
|
15079
|
-
const boxResult = await
|
|
15170
|
+
var resolveNodeClip = async (session2, target) => {
|
|
15171
|
+
const boxResult = await session2.sendAndWait("DOM.getBoxModel", target.nodeId != null ? { nodeId: target.nodeId } : { backendNodeId: target.backendNodeId });
|
|
15080
15172
|
const quad = boxResult.model?.content ?? boxResult.model?.border;
|
|
15081
15173
|
if (!quad || quad.length < 8) {
|
|
15082
15174
|
throw new Error("Unable to compute element box model");
|
|
@@ -15085,7 +15177,7 @@ var resolveNodeClip = async (session, target) => {
|
|
|
15085
15177
|
if (rect.width <= 0 || rect.height <= 0) {
|
|
15086
15178
|
throw new Error("Element has zero area");
|
|
15087
15179
|
}
|
|
15088
|
-
const viewport = await resolveVisualViewport(
|
|
15180
|
+
const viewport = await resolveVisualViewport(session2);
|
|
15089
15181
|
const pageX = viewport?.pageX ?? 0;
|
|
15090
15182
|
const pageY = viewport?.pageY ?? 0;
|
|
15091
15183
|
const scale = viewport?.scale ?? 1;
|
|
@@ -15097,17 +15189,17 @@ var resolveNodeClip = async (session, target) => {
|
|
|
15097
15189
|
scale
|
|
15098
15190
|
};
|
|
15099
15191
|
};
|
|
15100
|
-
var resolveVisualViewport = async (
|
|
15101
|
-
const metrics = await
|
|
15192
|
+
var resolveVisualViewport = async (session2) => {
|
|
15193
|
+
const metrics = await session2.sendAndWait("Page.getLayoutMetrics");
|
|
15102
15194
|
const payload = metrics;
|
|
15103
15195
|
return payload.cssVisualViewport ?? payload.visualViewport;
|
|
15104
15196
|
};
|
|
15105
|
-
var resolveViewportSize = async (
|
|
15106
|
-
const viewport = await resolveVisualViewport(
|
|
15197
|
+
var resolveViewportSize = async (session2) => {
|
|
15198
|
+
const viewport = await resolveVisualViewport(session2);
|
|
15107
15199
|
if (isPositiveFiniteNumber(viewport?.clientWidth) && isPositiveFiniteNumber(viewport?.clientHeight)) {
|
|
15108
15200
|
return { width: viewport.clientWidth, height: viewport.clientHeight };
|
|
15109
15201
|
}
|
|
15110
|
-
const evaluated = await evaluateInPage(
|
|
15202
|
+
const evaluated = await evaluateInPage(session2, "({width: window.visualViewport?.width ?? window.innerWidth, height: window.visualViewport?.height ?? window.innerHeight})");
|
|
15111
15203
|
const width = evaluated?.width;
|
|
15112
15204
|
const height = evaluated?.height;
|
|
15113
15205
|
if (!isPositiveFiniteNumber(width) || !isPositiveFiniteNumber(height)) {
|
|
@@ -15161,11 +15253,11 @@ var createScreenshotter = (options) => {
|
|
|
15161
15253
|
};
|
|
15162
15254
|
return { capture };
|
|
15163
15255
|
};
|
|
15164
|
-
var captureScreenshot = async (
|
|
15256
|
+
var captureScreenshot = async (session2, options) => {
|
|
15165
15257
|
let lastError;
|
|
15166
15258
|
for (let attempt = 1;attempt <= SCREENSHOT_CDP_MAX_ATTEMPTS; attempt += 1) {
|
|
15167
15259
|
try {
|
|
15168
|
-
const payload = await
|
|
15260
|
+
const payload = await session2.sendAndWait("Page.captureScreenshot", {
|
|
15169
15261
|
format: options.format,
|
|
15170
15262
|
clip: options.clip
|
|
15171
15263
|
}, { timeoutMs: SCREENSHOT_CDP_TIMEOUT_MS });
|
|
@@ -15549,7 +15641,7 @@ var QUIET_PERIOD_MS = 100;
|
|
|
15549
15641
|
var ENABLE_TIMEOUT_MS = 5000;
|
|
15550
15642
|
var DEFAULT_READ_LIMIT = 2000;
|
|
15551
15643
|
var MAX_GREP_MATCHES = 500;
|
|
15552
|
-
var createRuntimeEditor = (
|
|
15644
|
+
var createRuntimeEditor = (session2) => {
|
|
15553
15645
|
const scripts = new Map;
|
|
15554
15646
|
const stylesheets = new Map;
|
|
15555
15647
|
const sources = new Map;
|
|
@@ -15595,9 +15687,9 @@ var createRuntimeEditor = (session) => {
|
|
|
15595
15687
|
await ensureEnabled();
|
|
15596
15688
|
const resource = getResource(url);
|
|
15597
15689
|
if (resource.type === "stylesheet") {
|
|
15598
|
-
await
|
|
15690
|
+
await session2.sendAndWait("CSS.setStyleSheetText", { styleSheetId: resource.id, text: source }, getSessionOptions(resource));
|
|
15599
15691
|
} else {
|
|
15600
|
-
await editScript(
|
|
15692
|
+
await editScript(session2, resource, source);
|
|
15601
15693
|
}
|
|
15602
15694
|
sources.set(getSourceCacheKey(resource), source);
|
|
15603
15695
|
return { ok: true, resource: toCodeResource(resource) };
|
|
@@ -15686,9 +15778,9 @@ var createRuntimeEditor = (session) => {
|
|
|
15686
15778
|
}
|
|
15687
15779
|
enabling = (async () => {
|
|
15688
15780
|
clearResourceState();
|
|
15689
|
-
await
|
|
15690
|
-
await
|
|
15691
|
-
await
|
|
15781
|
+
await session2.sendAndWait("Debugger.enable", undefined, { timeoutMs: ENABLE_TIMEOUT_MS });
|
|
15782
|
+
await session2.sendAndWait("DOM.enable", undefined, { timeoutMs: ENABLE_TIMEOUT_MS });
|
|
15783
|
+
await session2.sendAndWait("CSS.enable", undefined, { timeoutMs: ENABLE_TIMEOUT_MS });
|
|
15692
15784
|
await waitForResourceQuietPeriod();
|
|
15693
15785
|
enabled = true;
|
|
15694
15786
|
})();
|
|
@@ -15703,13 +15795,13 @@ var createRuntimeEditor = (session) => {
|
|
|
15703
15795
|
return;
|
|
15704
15796
|
}
|
|
15705
15797
|
listenerDisposers = [
|
|
15706
|
-
|
|
15798
|
+
session2.onEvent("Debugger.scriptParsed", (params, meta) => {
|
|
15707
15799
|
handleScriptParsed(params, meta);
|
|
15708
15800
|
}),
|
|
15709
|
-
|
|
15801
|
+
session2.onEvent("CSS.styleSheetAdded", (params, meta) => {
|
|
15710
15802
|
handleStyleSheetAdded(params, meta);
|
|
15711
15803
|
}),
|
|
15712
|
-
|
|
15804
|
+
session2.onEvent("CSS.styleSheetRemoved", (params, meta) => {
|
|
15713
15805
|
handleStyleSheetRemoved(params, meta);
|
|
15714
15806
|
})
|
|
15715
15807
|
];
|
|
@@ -15822,11 +15914,11 @@ var createRuntimeEditor = (session) => {
|
|
|
15822
15914
|
sources.clear();
|
|
15823
15915
|
}
|
|
15824
15916
|
async function readStylesheetSource(resource) {
|
|
15825
|
-
const result = await
|
|
15917
|
+
const result = await session2.sendAndWait("CSS.getStyleSheetText", { styleSheetId: resource.id }, getSessionOptions(resource));
|
|
15826
15918
|
return result.text ?? "";
|
|
15827
15919
|
}
|
|
15828
15920
|
async function readScriptSource(resource) {
|
|
15829
|
-
const result = await
|
|
15921
|
+
const result = await session2.sendAndWait("Debugger.getScriptSource", { scriptId: resource.id }, getSessionOptions(resource));
|
|
15830
15922
|
return result.scriptSource ?? "";
|
|
15831
15923
|
}
|
|
15832
15924
|
};
|
|
@@ -15851,10 +15943,10 @@ var matchesUrlPattern = (resource, pattern) => !pattern || resource.url.toLowerC
|
|
|
15851
15943
|
var matchesLine = (line, pattern) => matchesTextPattern(line, pattern);
|
|
15852
15944
|
var getSessionOptions = (resource) => resource.sessionId ? { sessionId: resource.sessionId } : undefined;
|
|
15853
15945
|
var getSourceCacheKey = (resource) => `${resource.type}:${resource.sessionId ?? "root"}:${resource.id}`;
|
|
15854
|
-
async function editScript(
|
|
15946
|
+
async function editScript(session2, resource, source) {
|
|
15855
15947
|
let result;
|
|
15856
15948
|
try {
|
|
15857
|
-
result = await
|
|
15949
|
+
result = await session2.sendAndWait("Debugger.setScriptSource", { scriptId: resource.id, scriptSource: source }, getSessionOptions(resource));
|
|
15858
15950
|
} catch (error) {
|
|
15859
15951
|
const message = formatError(error);
|
|
15860
15952
|
if (/setScriptSource.*no longer available/i.test(message)) {
|
|
@@ -15997,9 +16089,9 @@ var toExceptionEvent = async (params, page, config) => {
|
|
|
15997
16089
|
};
|
|
15998
16090
|
return applyLocation(baseEvent, details?.stackTrace?.callFrames, config);
|
|
15999
16091
|
};
|
|
16000
|
-
var fetchPageIntl = async (
|
|
16092
|
+
var fetchPageIntl = async (session2) => {
|
|
16001
16093
|
try {
|
|
16002
|
-
const result = await
|
|
16094
|
+
const result = await session2.sendAndWait("Runtime.evaluate", {
|
|
16003
16095
|
expression: "(() => { const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone ?? null; const locale = navigator.language ?? null; return { timezone, locale }; })()",
|
|
16004
16096
|
returnByValue: true
|
|
16005
16097
|
});
|
|
@@ -16214,7 +16306,7 @@ var startCdpWatcher = (options) => {
|
|
|
16214
16306
|
let stopped = false;
|
|
16215
16307
|
let socket = null;
|
|
16216
16308
|
let currentTarget = null;
|
|
16217
|
-
const { session, attach, detach } = options.sessionHandle ?? createCdpSessionHandle();
|
|
16309
|
+
const { session: session2, attach, detach } = options.sessionHandle ?? createCdpSessionHandle();
|
|
16218
16310
|
const stop = async () => {
|
|
16219
16311
|
stopped = true;
|
|
16220
16312
|
if (socket) {
|
|
@@ -16222,19 +16314,19 @@ var startCdpWatcher = (options) => {
|
|
|
16222
16314
|
}
|
|
16223
16315
|
};
|
|
16224
16316
|
runLoop();
|
|
16225
|
-
|
|
16317
|
+
session2.onEvent("Runtime.consoleAPICalled", (params) => {
|
|
16226
16318
|
if (!currentTarget) {
|
|
16227
16319
|
return;
|
|
16228
16320
|
}
|
|
16229
|
-
toConsoleEvent(params, currentTarget, { ...options, cdp:
|
|
16321
|
+
toConsoleEvent(params, currentTarget, { ...options, cdp: session2 }).then((event) => options.onLog(event));
|
|
16230
16322
|
});
|
|
16231
|
-
|
|
16323
|
+
session2.onEvent("Runtime.exceptionThrown", (params) => {
|
|
16232
16324
|
if (!currentTarget) {
|
|
16233
16325
|
return;
|
|
16234
16326
|
}
|
|
16235
|
-
toExceptionEvent(params, currentTarget, { ...options, cdp:
|
|
16327
|
+
toExceptionEvent(params, currentTarget, { ...options, cdp: session2 }).then((event) => options.onLog(event));
|
|
16236
16328
|
});
|
|
16237
|
-
|
|
16329
|
+
session2.onEvent("Page.frameNavigated", (params) => {
|
|
16238
16330
|
if (!currentTarget) {
|
|
16239
16331
|
return;
|
|
16240
16332
|
}
|
|
@@ -16245,7 +16337,7 @@ var startCdpWatcher = (options) => {
|
|
|
16245
16337
|
currentTarget.url = navigation.url;
|
|
16246
16338
|
options.onPageNavigation?.({ url: navigation.url, title: currentTarget.title ?? null });
|
|
16247
16339
|
});
|
|
16248
|
-
|
|
16340
|
+
session2.onEvent("Page.domContentEventFired", () => {
|
|
16249
16341
|
if (!currentTarget) {
|
|
16250
16342
|
return;
|
|
16251
16343
|
}
|
|
@@ -16253,7 +16345,7 @@ var startCdpWatcher = (options) => {
|
|
|
16253
16345
|
});
|
|
16254
16346
|
return {
|
|
16255
16347
|
stop,
|
|
16256
|
-
session,
|
|
16348
|
+
session: session2,
|
|
16257
16349
|
getTarget: () => currentTarget ? { ...currentTarget } : null
|
|
16258
16350
|
};
|
|
16259
16351
|
async function runLoop() {
|
|
@@ -16295,13 +16387,13 @@ var startCdpWatcher = (options) => {
|
|
|
16295
16387
|
options.onStatus({ attached: false, target: null, reason });
|
|
16296
16388
|
options.onDetach?.(reason);
|
|
16297
16389
|
});
|
|
16298
|
-
const pageIntl = await fetchPageIntl(
|
|
16390
|
+
const pageIntl = await fetchPageIntl(session2);
|
|
16299
16391
|
if (pageIntl) {
|
|
16300
16392
|
options.onPageIntl?.(pageIntl);
|
|
16301
16393
|
}
|
|
16302
|
-
await
|
|
16303
|
-
await
|
|
16304
|
-
await options.onAttach?.(
|
|
16394
|
+
await session2.sendAndWait("Runtime.enable");
|
|
16395
|
+
await session2.sendAndWait("Page.enable");
|
|
16396
|
+
await options.onAttach?.(session2, target);
|
|
16305
16397
|
options.onStatus({
|
|
16306
16398
|
attached: true,
|
|
16307
16399
|
target: {
|
|
@@ -16417,7 +16509,7 @@ var createCdpSource = (options) => {
|
|
|
16417
16509
|
onPageNavigation: events.onPageNavigation,
|
|
16418
16510
|
onPageLoad: events.onPageLoad,
|
|
16419
16511
|
onPageIntl: events.onPageIntl,
|
|
16420
|
-
onAttach: events.onAttach ? (
|
|
16512
|
+
onAttach: events.onAttach ? (session2, target) => events.onAttach(session2, {
|
|
16421
16513
|
id: target.id,
|
|
16422
16514
|
title: target.title,
|
|
16423
16515
|
url: target.url,
|
|
@@ -16615,12 +16707,12 @@ class SessionManager {
|
|
|
16615
16707
|
}
|
|
16616
16708
|
}
|
|
16617
16709
|
handleTabAttached(message) {
|
|
16618
|
-
const
|
|
16619
|
-
this.events.onAttach(
|
|
16710
|
+
const session2 = this.createSession(message);
|
|
16711
|
+
this.events.onAttach(session2);
|
|
16620
16712
|
}
|
|
16621
16713
|
handleTabDetached(message) {
|
|
16622
|
-
const
|
|
16623
|
-
if (
|
|
16714
|
+
const session2 = this.sessions.get(message.tabId);
|
|
16715
|
+
if (session2) {
|
|
16624
16716
|
this.sessions.delete(message.tabId);
|
|
16625
16717
|
this.eventHandlers.delete(message.tabId);
|
|
16626
16718
|
}
|
|
@@ -16688,7 +16780,7 @@ class SessionManager {
|
|
|
16688
16780
|
getTargetContext: () => ({ kind: "page" }),
|
|
16689
16781
|
getReadyTargetContext: async () => ({ kind: "page" })
|
|
16690
16782
|
};
|
|
16691
|
-
const
|
|
16783
|
+
const session2 = {
|
|
16692
16784
|
tabId,
|
|
16693
16785
|
url,
|
|
16694
16786
|
title,
|
|
@@ -16709,8 +16801,8 @@ class SessionManager {
|
|
|
16709
16801
|
}), options?.timeoutMs ?? 1e4);
|
|
16710
16802
|
}
|
|
16711
16803
|
};
|
|
16712
|
-
this.sessions.set(tabId,
|
|
16713
|
-
return
|
|
16804
|
+
this.sessions.set(tabId, session2);
|
|
16805
|
+
return session2;
|
|
16714
16806
|
}
|
|
16715
16807
|
async getCookies(tabId, query2, timeoutMs = 5000) {
|
|
16716
16808
|
if (!this.sessions.has(tabId)) {
|
|
@@ -16773,13 +16865,13 @@ var parseExtensionTargetId = (targetId) => {
|
|
|
16773
16865
|
}
|
|
16774
16866
|
throw new Error(`Invalid extension target id: ${targetId}`);
|
|
16775
16867
|
};
|
|
16776
|
-
var buildPageTarget = (
|
|
16777
|
-
id: formatPageTargetId(
|
|
16778
|
-
title:
|
|
16779
|
-
url:
|
|
16868
|
+
var buildPageTarget = (session2, options) => ({
|
|
16869
|
+
id: formatPageTargetId(session2.tabId),
|
|
16870
|
+
title: session2.title,
|
|
16871
|
+
url: session2.url,
|
|
16780
16872
|
type: "page",
|
|
16781
16873
|
parentId: null,
|
|
16782
|
-
faviconUrl:
|
|
16874
|
+
faviconUrl: session2.faviconUrl,
|
|
16783
16875
|
attached: options.attached
|
|
16784
16876
|
});
|
|
16785
16877
|
var frameToTarget = (tabId, frame, options) => ({
|
|
@@ -16949,7 +17041,7 @@ var createDelegatingSession = (options) => {
|
|
|
16949
17041
|
rebind: rebindSubscriptions,
|
|
16950
17042
|
dispose: disposeSubscriptions
|
|
16951
17043
|
};
|
|
16952
|
-
const
|
|
17044
|
+
const session2 = {
|
|
16953
17045
|
isAttached: () => options.getCurrentSession()?.handle.isAttached() ?? false,
|
|
16954
17046
|
sendAndWait: async (method, params, commandOptions) => {
|
|
16955
17047
|
const currentSession = options.requireCurrentSession();
|
|
@@ -16983,7 +17075,7 @@ var createDelegatingSession = (options) => {
|
|
|
16983
17075
|
getReadyTargetContext: options.getReadyTargetContext ?? (async () => options.getTargetContext())
|
|
16984
17076
|
};
|
|
16985
17077
|
controller.rebind();
|
|
16986
|
-
return { session, controller };
|
|
17078
|
+
return { session: session2, controller };
|
|
16987
17079
|
};
|
|
16988
17080
|
var createDelegatingEventSubscription = (method, handler) => ({
|
|
16989
17081
|
method,
|
|
@@ -16996,32 +17088,32 @@ var createDelegatingEventSubscription = (method, handler) => ({
|
|
|
16996
17088
|
});
|
|
16997
17089
|
|
|
16998
17090
|
// ../argus-watcher/dist/sources/extension-session-events.js
|
|
16999
|
-
var registerExtensionSessionEventHandlers = ({ session, events, ignoreMatcher, stripUrlPrefixes: stripUrlPrefixes2, sourcemaps, getOrCreateFrameState, reconcileTargetSelection, removeFrame, refreshFrameTitle, emitTargetChanged, setCurrentSession }) => {
|
|
17000
|
-
|
|
17091
|
+
var registerExtensionSessionEventHandlers = ({ session: session2, events, ignoreMatcher, stripUrlPrefixes: stripUrlPrefixes2, sourcemaps, getOrCreateFrameState, reconcileTargetSelection, removeFrame, refreshFrameTitle, emitTargetChanged, setCurrentSession }) => {
|
|
17092
|
+
session2.handle.onEvent("Runtime.executionContextCreated", (params, meta) => {
|
|
17001
17093
|
const context = parseExecutionContext(params);
|
|
17002
17094
|
if (!context?.isDefault || !context.frameId) {
|
|
17003
17095
|
return;
|
|
17004
17096
|
}
|
|
17005
|
-
const state2 = getOrCreateFrameState(
|
|
17097
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
17006
17098
|
state2.executionContexts.set(context.frameId, context.id);
|
|
17007
17099
|
const frame = state2.frames.get(context.frameId);
|
|
17008
17100
|
if (frame) {
|
|
17009
17101
|
frame.sessionId = meta.sessionId ?? null;
|
|
17010
17102
|
}
|
|
17011
|
-
refreshFrameTitle(
|
|
17012
|
-
reconcileTargetSelection(
|
|
17103
|
+
refreshFrameTitle(session2, context.frameId, context.id);
|
|
17104
|
+
reconcileTargetSelection(session2);
|
|
17013
17105
|
});
|
|
17014
|
-
|
|
17015
|
-
const state2 = getOrCreateFrameState(
|
|
17106
|
+
session2.handle.onEvent("Runtime.executionContextsCleared", () => {
|
|
17107
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
17016
17108
|
state2.executionContexts.clear();
|
|
17017
17109
|
state2.pendingTitleLoads.clear();
|
|
17018
17110
|
});
|
|
17019
|
-
|
|
17111
|
+
session2.handle.onEvent("Runtime.executionContextDestroyed", (params) => {
|
|
17020
17112
|
const record2 = params;
|
|
17021
17113
|
if (record2.executionContextId == null) {
|
|
17022
17114
|
return;
|
|
17023
17115
|
}
|
|
17024
|
-
const state2 = getOrCreateFrameState(
|
|
17116
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
17025
17117
|
for (const [frameId, contextId] of state2.executionContexts.entries()) {
|
|
17026
17118
|
if (contextId === record2.executionContextId) {
|
|
17027
17119
|
state2.executionContexts.delete(frameId);
|
|
@@ -17029,42 +17121,42 @@ var registerExtensionSessionEventHandlers = ({ session, events, ignoreMatcher, s
|
|
|
17029
17121
|
}
|
|
17030
17122
|
}
|
|
17031
17123
|
});
|
|
17032
|
-
|
|
17124
|
+
session2.handle.onEvent("Page.frameNavigated", (params, meta) => {
|
|
17033
17125
|
const frame = parseFrame(params);
|
|
17034
17126
|
if (!frame) {
|
|
17035
17127
|
return;
|
|
17036
17128
|
}
|
|
17037
|
-
const state2 = getOrCreateFrameState(
|
|
17129
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
17038
17130
|
const preservedSessionId = pickFrameSessionId(meta.sessionId, state2.frames.get(frame.frameId)?.sessionId);
|
|
17039
17131
|
state2.frames.set(frame.frameId, frame);
|
|
17040
17132
|
frame.sessionId = preservedSessionId;
|
|
17041
17133
|
if (!frame.parentFrameId) {
|
|
17042
17134
|
if (!meta.sessionId) {
|
|
17043
17135
|
state2.topFrameId = frame.frameId;
|
|
17044
|
-
|
|
17136
|
+
session2.url = frame.url;
|
|
17045
17137
|
} else if (state2.topFrameId == null) {
|
|
17046
17138
|
state2.topFrameId = frame.parentFrameId;
|
|
17047
17139
|
}
|
|
17048
17140
|
} else if (state2.executionContexts.has(frame.frameId)) {
|
|
17049
|
-
refreshFrameTitle(
|
|
17141
|
+
refreshFrameTitle(session2, frame.frameId);
|
|
17050
17142
|
}
|
|
17051
|
-
setCurrentSession(
|
|
17143
|
+
setCurrentSession(session2);
|
|
17052
17144
|
if (!frame.parentFrameId && !meta.sessionId) {
|
|
17053
|
-
events.onPageNavigation?.({ url: frame.url, title:
|
|
17145
|
+
events.onPageNavigation?.({ url: frame.url, title: session2.title ?? null });
|
|
17054
17146
|
}
|
|
17055
|
-
if (reconcileTargetSelection(
|
|
17147
|
+
if (reconcileTargetSelection(session2)) {
|
|
17056
17148
|
return;
|
|
17057
17149
|
}
|
|
17058
17150
|
if (!frame.parentFrameId && state2.activeFrameId == null || state2.activeFrameId === frame.frameId) {
|
|
17059
|
-
emitTargetChanged(
|
|
17151
|
+
emitTargetChanged(session2);
|
|
17060
17152
|
}
|
|
17061
17153
|
});
|
|
17062
|
-
|
|
17154
|
+
session2.handle.onEvent("Page.frameAttached", (params, meta) => {
|
|
17063
17155
|
const record2 = params;
|
|
17064
17156
|
if (!record2.frameId) {
|
|
17065
17157
|
return;
|
|
17066
17158
|
}
|
|
17067
|
-
const state2 = getOrCreateFrameState(
|
|
17159
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
17068
17160
|
state2.frames.set(record2.frameId, {
|
|
17069
17161
|
frameId: record2.frameId,
|
|
17070
17162
|
parentFrameId: record2.parentFrameId ?? state2.topFrameId ?? null,
|
|
@@ -17072,25 +17164,25 @@ var registerExtensionSessionEventHandlers = ({ session, events, ignoreMatcher, s
|
|
|
17072
17164
|
title: null,
|
|
17073
17165
|
sessionId: pickFrameSessionId(meta.sessionId, state2.frames.get(record2.frameId)?.sessionId)
|
|
17074
17166
|
});
|
|
17075
|
-
reconcileTargetSelection(
|
|
17167
|
+
reconcileTargetSelection(session2);
|
|
17076
17168
|
});
|
|
17077
|
-
|
|
17169
|
+
session2.handle.onEvent("Page.frameDetached", (params) => {
|
|
17078
17170
|
const record2 = params;
|
|
17079
17171
|
if (!record2.frameId) {
|
|
17080
17172
|
return;
|
|
17081
17173
|
}
|
|
17082
|
-
removeFrame(
|
|
17083
|
-
reconcileTargetSelection(
|
|
17174
|
+
removeFrame(session2.tabId, record2.frameId);
|
|
17175
|
+
reconcileTargetSelection(session2);
|
|
17084
17176
|
});
|
|
17085
|
-
|
|
17177
|
+
session2.handle.onEvent("Page.domContentEventFired", () => {
|
|
17086
17178
|
events.onPageLoad?.();
|
|
17087
17179
|
});
|
|
17088
|
-
const logConfig = { ignoreMatcher, stripUrlPrefixes: stripUrlPrefixes2, sourcemaps, cdp:
|
|
17089
|
-
|
|
17090
|
-
toConsoleEvent(params,
|
|
17180
|
+
const logConfig = { ignoreMatcher, stripUrlPrefixes: stripUrlPrefixes2, sourcemaps, cdp: session2.handle };
|
|
17181
|
+
session2.handle.onEvent("Runtime.consoleAPICalled", (params) => {
|
|
17182
|
+
toConsoleEvent(params, session2, logConfig).then((event) => events.onLog(event));
|
|
17091
17183
|
});
|
|
17092
|
-
|
|
17093
|
-
toExceptionEvent(params,
|
|
17184
|
+
session2.handle.onEvent("Runtime.exceptionThrown", (params) => {
|
|
17185
|
+
toExceptionEvent(params, session2, logConfig).then((event) => events.onLog(event));
|
|
17094
17186
|
});
|
|
17095
17187
|
};
|
|
17096
17188
|
var pickFrameSessionId = (nextSessionId, existingSessionId) => nextSessionId ?? existingSessionId ?? null;
|
|
@@ -17280,18 +17372,18 @@ var FRAME_COMMAND_READY_POLL_MS = 100;
|
|
|
17280
17372
|
var createTargetRecovery = (deps) => {
|
|
17281
17373
|
const { getCurrentSession, getOrCreateFrameState, refreshFrameTree, reconcileTargetSelection } = deps;
|
|
17282
17374
|
const recoveryByTabId = new Map;
|
|
17283
|
-
const sync = (
|
|
17375
|
+
const sync = (session2, state2) => {
|
|
17284
17376
|
if (!needsTargetRecovery(state2)) {
|
|
17285
|
-
clear(
|
|
17377
|
+
clear(session2.tabId);
|
|
17286
17378
|
return;
|
|
17287
17379
|
}
|
|
17288
|
-
if (recoveryByTabId.has(
|
|
17380
|
+
if (recoveryByTabId.has(session2.tabId)) {
|
|
17289
17381
|
return;
|
|
17290
17382
|
}
|
|
17291
17383
|
const timer = setInterval(() => {
|
|
17292
|
-
retry(
|
|
17384
|
+
retry(session2.tabId);
|
|
17293
17385
|
}, TARGET_RECOVERY_INTERVAL_MS);
|
|
17294
|
-
recoveryByTabId.set(
|
|
17386
|
+
recoveryByTabId.set(session2.tabId, {
|
|
17295
17387
|
timer,
|
|
17296
17388
|
deadline: Date.now() + TARGET_RECOVERY_TIMEOUT_MS
|
|
17297
17389
|
});
|
|
@@ -17311,8 +17403,8 @@ var createTargetRecovery = (deps) => {
|
|
|
17311
17403
|
};
|
|
17312
17404
|
const retry = async (tabId) => {
|
|
17313
17405
|
const recovery = recoveryByTabId.get(tabId);
|
|
17314
|
-
const
|
|
17315
|
-
if (!recovery || !
|
|
17406
|
+
const session2 = getCurrentSession();
|
|
17407
|
+
if (!recovery || !session2 || session2.tabId !== tabId) {
|
|
17316
17408
|
clear(tabId);
|
|
17317
17409
|
return;
|
|
17318
17410
|
}
|
|
@@ -17326,32 +17418,32 @@ var createTargetRecovery = (deps) => {
|
|
|
17326
17418
|
return;
|
|
17327
17419
|
}
|
|
17328
17420
|
try {
|
|
17329
|
-
await refreshFrameTree(
|
|
17421
|
+
await refreshFrameTree(session2);
|
|
17330
17422
|
} catch {}
|
|
17331
|
-
reconcileTargetSelection(
|
|
17423
|
+
reconcileTargetSelection(session2);
|
|
17332
17424
|
if (!needsTargetRecovery(getOrCreateFrameState(tabId))) {
|
|
17333
17425
|
clear(tabId);
|
|
17334
17426
|
}
|
|
17335
17427
|
};
|
|
17336
|
-
const kick = async (
|
|
17337
|
-
const state2 = getOrCreateFrameState(
|
|
17428
|
+
const kick = async (session2) => {
|
|
17429
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
17338
17430
|
if (!needsTargetRecovery(state2)) {
|
|
17339
17431
|
return;
|
|
17340
17432
|
}
|
|
17341
|
-
sync(
|
|
17342
|
-
await retry(
|
|
17433
|
+
sync(session2, state2);
|
|
17434
|
+
await retry(session2.tabId);
|
|
17343
17435
|
};
|
|
17344
17436
|
const waitForSelectedFrameCommandTarget = async () => {
|
|
17345
|
-
const
|
|
17346
|
-
if (!
|
|
17437
|
+
const session2 = getCurrentSession();
|
|
17438
|
+
if (!session2) {
|
|
17347
17439
|
throw createNotAttachedError();
|
|
17348
17440
|
}
|
|
17349
|
-
const tabId =
|
|
17441
|
+
const tabId = session2.tabId;
|
|
17350
17442
|
const immediate = resolveSelectedFrameCommandState(getOrCreateFrameState(tabId));
|
|
17351
17443
|
if (immediate.kind === "frame") {
|
|
17352
17444
|
return buildFrameTargetContext(getOrCreateFrameState(tabId), immediate.frameId);
|
|
17353
17445
|
}
|
|
17354
|
-
await kick(
|
|
17446
|
+
await kick(session2);
|
|
17355
17447
|
const deadline = Date.now() + FRAME_COMMAND_READY_TIMEOUT_MS;
|
|
17356
17448
|
while (Date.now() < deadline) {
|
|
17357
17449
|
await delay(FRAME_COMMAND_READY_POLL_MS);
|
|
@@ -17372,11 +17464,11 @@ var needsTargetRecovery = (state2) => resolveSelectedFrameCommandState(state2).k
|
|
|
17372
17464
|
var buildSelectedFrameNotReadyError = (tabId) => codedError("extension_frame_not_ready", `Selected iframe target on tab ${tabId} is not executable yet after reload. Try again in a few seconds or reattach the watcher if the problem persists.`);
|
|
17373
17465
|
|
|
17374
17466
|
// ../argus-watcher/dist/sources/extension-frame-snapshot.js
|
|
17375
|
-
var applyExtensionFrameSnapshot = (
|
|
17467
|
+
var applyExtensionFrameSnapshot = (session2, state2, snapshot2, deps) => {
|
|
17376
17468
|
const nextIds = new Set(snapshot2.frames.map((frame) => frame.frameId));
|
|
17377
17469
|
for (const frameId of [...state2.frames.keys()]) {
|
|
17378
17470
|
if (!nextIds.has(frameId)) {
|
|
17379
|
-
deps.removeFrame(
|
|
17471
|
+
deps.removeFrame(session2.tabId, frameId);
|
|
17380
17472
|
}
|
|
17381
17473
|
}
|
|
17382
17474
|
let activeTargetTouched = false;
|
|
@@ -17407,29 +17499,29 @@ var applyExtensionFrameSnapshot = (session, state2, snapshot2, deps) => {
|
|
|
17407
17499
|
const record2 = state2.frames.get(frame.frameId);
|
|
17408
17500
|
const needsTitle = (!existing || urlChanged || record2.title == null) && frame.frameId !== snapshot2.topFrameId;
|
|
17409
17501
|
if (needsTitle && state2.executionContexts.has(frame.frameId)) {
|
|
17410
|
-
deps.refreshFrameTitle(
|
|
17502
|
+
deps.refreshFrameTitle(session2, frame.frameId);
|
|
17411
17503
|
}
|
|
17412
17504
|
}
|
|
17413
17505
|
if (snapshot2.topFrameId != null) {
|
|
17414
17506
|
state2.topFrameId = snapshot2.topFrameId;
|
|
17415
17507
|
const topFrame = state2.frames.get(snapshot2.topFrameId);
|
|
17416
17508
|
if (topFrame?.url) {
|
|
17417
|
-
|
|
17509
|
+
session2.url = topFrame.url;
|
|
17418
17510
|
}
|
|
17419
17511
|
}
|
|
17420
|
-
const selectionChanged = deps.reconcileTargetSelection(
|
|
17512
|
+
const selectionChanged = deps.reconcileTargetSelection(session2);
|
|
17421
17513
|
if (!selectionChanged && activeTargetTouched) {
|
|
17422
|
-
deps.emitTargetChanged(
|
|
17514
|
+
deps.emitTargetChanged(session2);
|
|
17423
17515
|
}
|
|
17424
17516
|
};
|
|
17425
17517
|
|
|
17426
17518
|
// ../argus-watcher/dist/sources/extension-frame-runtime.js
|
|
17427
|
-
var seedExtensionFrameState = (
|
|
17428
|
-
if (state2.frames.size > 0 ||
|
|
17519
|
+
var seedExtensionFrameState = (session2, state2) => {
|
|
17520
|
+
if (state2.frames.size > 0 || session2.frames.length === 0) {
|
|
17429
17521
|
return state2;
|
|
17430
17522
|
}
|
|
17431
|
-
state2.topFrameId =
|
|
17432
|
-
for (const frame of
|
|
17523
|
+
state2.topFrameId = session2.topFrameId;
|
|
17524
|
+
for (const frame of session2.frames) {
|
|
17433
17525
|
state2.frames.set(frame.frameId, {
|
|
17434
17526
|
frameId: frame.frameId,
|
|
17435
17527
|
parentFrameId: frame.parentFrameId,
|
|
@@ -17440,16 +17532,16 @@ var seedExtensionFrameState = (session, state2) => {
|
|
|
17440
17532
|
}
|
|
17441
17533
|
return state2;
|
|
17442
17534
|
};
|
|
17443
|
-
var getSelectedExtensionTarget = (
|
|
17535
|
+
var getSelectedExtensionTarget = (session2, state2) => {
|
|
17444
17536
|
const frameId = state2?.requestedFrameId ?? state2?.activeFrameId;
|
|
17445
17537
|
if (!state2 || !frameId) {
|
|
17446
|
-
return buildPageTarget(
|
|
17538
|
+
return buildPageTarget(session2, { attached: true });
|
|
17447
17539
|
}
|
|
17448
17540
|
const frame = state2.frames.get(frameId);
|
|
17449
17541
|
if (frame) {
|
|
17450
|
-
return frameToTarget(
|
|
17542
|
+
return frameToTarget(session2.tabId, frame, { attached: true, faviconUrl: session2.faviconUrl, topFrameId: state2.topFrameId });
|
|
17451
17543
|
}
|
|
17452
|
-
return buildSelectedIframeFallbackTarget(
|
|
17544
|
+
return buildSelectedIframeFallbackTarget(session2, state2);
|
|
17453
17545
|
};
|
|
17454
17546
|
var setRequestedTargetSelection = (state2, frameId) => {
|
|
17455
17547
|
if (state2.requestedFrameId !== frameId) {
|
|
@@ -17459,13 +17551,13 @@ var setRequestedTargetSelection = (state2, frameId) => {
|
|
|
17459
17551
|
state2.requestedFrameId = frameId;
|
|
17460
17552
|
state2.requestedFrameHint = frameId ? createRequestedFrameHint(state2.frames.get(frameId)) ?? previousHint : null;
|
|
17461
17553
|
};
|
|
17462
|
-
var listExtensionTargets = (
|
|
17554
|
+
var listExtensionTargets = (session2, state2) => {
|
|
17463
17555
|
if (!state2) {
|
|
17464
|
-
return [buildPageTarget(
|
|
17556
|
+
return [buildPageTarget(session2, { attached: true })];
|
|
17465
17557
|
}
|
|
17466
|
-
const selected = getSelectedExtensionTarget(
|
|
17558
|
+
const selected = getSelectedExtensionTarget(session2, state2);
|
|
17467
17559
|
selected.targetReady = isSelectedTargetReady(state2);
|
|
17468
|
-
const targets = [buildPageTarget(
|
|
17560
|
+
const targets = [buildPageTarget(session2, { attached: false }), ...buildFrameTargets(state2, session2.tabId, null, session2.faviconUrl)];
|
|
17469
17561
|
const selectedIndex = targets.findIndex((target) => target.id === selected.id);
|
|
17470
17562
|
if (selectedIndex < 0) {
|
|
17471
17563
|
targets.push(selected);
|
|
@@ -17474,7 +17566,7 @@ var listExtensionTargets = (session, state2) => {
|
|
|
17474
17566
|
}
|
|
17475
17567
|
return targets;
|
|
17476
17568
|
};
|
|
17477
|
-
var reconcileExtensionTargetSelection = (
|
|
17569
|
+
var reconcileExtensionTargetSelection = (session2, state2, onTargetChanged) => {
|
|
17478
17570
|
const resolution = resolveRequestedTarget(state2);
|
|
17479
17571
|
if (resolution.kind === "page") {
|
|
17480
17572
|
return activatePageTarget(state2, onTargetChanged);
|
|
@@ -17507,7 +17599,7 @@ var removeExtensionFrame = (state2, frameId) => {
|
|
|
17507
17599
|
state2.executionContexts.delete(frameId);
|
|
17508
17600
|
state2.pendingTitleLoads.delete(frameId);
|
|
17509
17601
|
};
|
|
17510
|
-
var refreshExtensionFrameTitle = async (
|
|
17602
|
+
var refreshExtensionFrameTitle = async (session2, state2, frameId, onActiveFrameUpdated, contextId) => {
|
|
17511
17603
|
if (frameId === state2.topFrameId || state2.pendingTitleLoads.has(frameId)) {
|
|
17512
17604
|
return;
|
|
17513
17605
|
}
|
|
@@ -17521,7 +17613,7 @@ var refreshExtensionFrameTitle = async (session, state2, frameId, onActiveFrameU
|
|
|
17521
17613
|
}
|
|
17522
17614
|
state2.pendingTitleLoads.add(frameId);
|
|
17523
17615
|
try {
|
|
17524
|
-
const evaluated = await
|
|
17616
|
+
const evaluated = await session2.handle.sendAndWait("Runtime.evaluate", {
|
|
17525
17617
|
expression: "document.title",
|
|
17526
17618
|
contextId: executionContextId,
|
|
17527
17619
|
returnByValue: true,
|
|
@@ -17568,19 +17660,19 @@ var syncRequestedFrameSelection = (state2, frameId) => {
|
|
|
17568
17660
|
state2.requestedFrameId = frameId;
|
|
17569
17661
|
state2.requestedFrameHint = createRequestedFrameHint(frame);
|
|
17570
17662
|
};
|
|
17571
|
-
var buildSelectedIframeFallbackTarget = (
|
|
17663
|
+
var buildSelectedIframeFallbackTarget = (session2, state2) => {
|
|
17572
17664
|
const hint = state2.requestedFrameHint;
|
|
17573
17665
|
const frameId = state2.requestedFrameId ?? state2.activeFrameId;
|
|
17574
17666
|
if (!frameId) {
|
|
17575
|
-
return buildPageTarget(
|
|
17667
|
+
return buildPageTarget(session2, { attached: true });
|
|
17576
17668
|
}
|
|
17577
17669
|
return {
|
|
17578
|
-
id: formatFrameTargetId(
|
|
17670
|
+
id: formatFrameTargetId(session2.tabId, frameId),
|
|
17579
17671
|
title: hint?.title ?? hint?.url ?? `iframe ${frameId}`,
|
|
17580
|
-
url: hint?.url ??
|
|
17672
|
+
url: hint?.url ?? session2.url,
|
|
17581
17673
|
type: "iframe",
|
|
17582
|
-
parentId: formatPageTargetId(
|
|
17583
|
-
faviconUrl:
|
|
17674
|
+
parentId: formatPageTargetId(session2.tabId),
|
|
17675
|
+
faviconUrl: session2.faviconUrl,
|
|
17584
17676
|
attached: true,
|
|
17585
17677
|
targetReady: false
|
|
17586
17678
|
};
|
|
@@ -17618,17 +17710,17 @@ var createExtensionSource = (options) => {
|
|
|
17618
17710
|
});
|
|
17619
17711
|
const frameSnapshotDeps = {
|
|
17620
17712
|
removeFrame,
|
|
17621
|
-
refreshFrameTitle: (
|
|
17713
|
+
refreshFrameTitle: (session2, frameId) => refreshFrameTitle(session2, frameId),
|
|
17622
17714
|
reconcileTargetSelection,
|
|
17623
17715
|
emitTargetChanged
|
|
17624
17716
|
};
|
|
17625
17717
|
const sessionManager = new SessionManager(messaging, {
|
|
17626
|
-
onAttach: (
|
|
17627
|
-
console.error(`[ExtensionSource] Tab attached: ${
|
|
17628
|
-
currentSession =
|
|
17718
|
+
onAttach: (session2) => {
|
|
17719
|
+
console.error(`[ExtensionSource] Tab attached: ${session2.tabId} - ${session2.url}`);
|
|
17720
|
+
currentSession = session2;
|
|
17629
17721
|
rebindDelegatingSessions();
|
|
17630
|
-
seedFrameState(
|
|
17631
|
-
bootstrapAttachedSession(
|
|
17722
|
+
seedFrameState(session2);
|
|
17723
|
+
bootstrapAttachedSession(session2);
|
|
17632
17724
|
},
|
|
17633
17725
|
onDetach: (tabId, reason) => {
|
|
17634
17726
|
console.error(`[ExtensionSource] Tab detached: ${tabId} - ${reason}`);
|
|
@@ -17642,20 +17734,20 @@ var createExtensionSource = (options) => {
|
|
|
17642
17734
|
events.onDetach?.(reason);
|
|
17643
17735
|
},
|
|
17644
17736
|
onTargetSelected: (tabId, frameId) => {
|
|
17645
|
-
const
|
|
17646
|
-
if (!
|
|
17737
|
+
const session2 = currentSession;
|
|
17738
|
+
if (!session2 || session2.tabId !== tabId) {
|
|
17647
17739
|
const state2 = getOrCreateFrameState(tabId);
|
|
17648
17740
|
setRequestedTargetSelection(state2, frameId);
|
|
17649
17741
|
return;
|
|
17650
17742
|
}
|
|
17651
|
-
requestTargetSelection(
|
|
17743
|
+
requestTargetSelection(session2, frameId);
|
|
17652
17744
|
},
|
|
17653
17745
|
onFrameSnapshot: (snapshot2) => {
|
|
17654
|
-
const
|
|
17655
|
-
if (!
|
|
17746
|
+
const session2 = currentSession;
|
|
17747
|
+
if (!session2 || session2.tabId !== snapshot2.tabId) {
|
|
17656
17748
|
return;
|
|
17657
17749
|
}
|
|
17658
|
-
applyExtensionFrameSnapshot(
|
|
17750
|
+
applyExtensionFrameSnapshot(session2, getOrCreateFrameState(snapshot2.tabId), snapshot2, frameSnapshotDeps);
|
|
17659
17751
|
}
|
|
17660
17752
|
});
|
|
17661
17753
|
const { session: proxySession, controller: proxyController } = createDelegatingSession({
|
|
@@ -17710,70 +17802,70 @@ var createExtensionSource = (options) => {
|
|
|
17710
17802
|
messaging.stop();
|
|
17711
17803
|
};
|
|
17712
17804
|
const listTargets = async () => {
|
|
17713
|
-
const
|
|
17714
|
-
if (!
|
|
17805
|
+
const session2 = currentSession;
|
|
17806
|
+
if (!session2) {
|
|
17715
17807
|
return [];
|
|
17716
17808
|
}
|
|
17717
|
-
return listExtensionTargets(
|
|
17809
|
+
return listExtensionTargets(session2, frameStateByTabId.get(session2.tabId));
|
|
17718
17810
|
};
|
|
17719
17811
|
const attachTarget = async (targetId) => {
|
|
17720
17812
|
const target = parseExtensionTargetId(targetId);
|
|
17721
|
-
const
|
|
17722
|
-
if (!
|
|
17813
|
+
const session2 = currentSession;
|
|
17814
|
+
if (!session2) {
|
|
17723
17815
|
if (target.frameId) {
|
|
17724
17816
|
throw new Error(`Cannot attach iframe ${target.frameId} before tab ${target.tabId} is attached`);
|
|
17725
17817
|
}
|
|
17726
17818
|
throw new Error(`Watcher ${hostInfo.watcherId} is a tab watcher. Use extension-control to attach tab ${target.tabId}.`);
|
|
17727
17819
|
}
|
|
17728
|
-
if (
|
|
17729
|
-
throw new Error(`Watcher ${hostInfo.watcherId} is pinned to tab ${
|
|
17820
|
+
if (session2.tabId !== target.tabId) {
|
|
17821
|
+
throw new Error(`Watcher ${hostInfo.watcherId} is pinned to tab ${session2.tabId}, not tab ${target.tabId}`);
|
|
17730
17822
|
}
|
|
17731
|
-
requestTargetSelection(
|
|
17732
|
-
return { ok: true, tab: sessionToBrowserTab(
|
|
17823
|
+
requestTargetSelection(session2, target.frameId);
|
|
17824
|
+
return { ok: true, tab: sessionToBrowserTab(session2), watcherId: hostInfo.watcherId };
|
|
17733
17825
|
};
|
|
17734
17826
|
const detachTarget = async (targetId) => {
|
|
17735
17827
|
const target = parseExtensionTargetId(targetId);
|
|
17736
|
-
const
|
|
17737
|
-
if (!
|
|
17828
|
+
const session2 = currentSession;
|
|
17829
|
+
if (!session2 || session2.tabId === target.tabId) {
|
|
17738
17830
|
sessionManager.detachTab(target.tabId);
|
|
17739
17831
|
return {
|
|
17740
17832
|
ok: true,
|
|
17741
|
-
tab:
|
|
17833
|
+
tab: session2 ? { ...sessionToBrowserTab(session2), attached: false, watcherId: undefined } : { tabId: target.tabId, url: "", title: "", attached: false }
|
|
17742
17834
|
};
|
|
17743
17835
|
}
|
|
17744
|
-
throw new Error(`Watcher ${hostInfo.watcherId} is pinned to tab ${
|
|
17836
|
+
throw new Error(`Watcher ${hostInfo.watcherId} is pinned to tab ${session2.tabId}, not tab ${target.tabId}`);
|
|
17745
17837
|
};
|
|
17746
17838
|
return {
|
|
17747
17839
|
session: proxySession,
|
|
17748
17840
|
pageSession,
|
|
17749
17841
|
readBrowserCookies: async ({ domain, url }) => {
|
|
17750
|
-
const
|
|
17751
|
-
return await sessionManager.getCookies(
|
|
17842
|
+
const session2 = getCurrentExtensionSession();
|
|
17843
|
+
return await sessionManager.getCookies(session2.tabId, {
|
|
17752
17844
|
domain: domain ?? undefined,
|
|
17753
17845
|
url: url ?? undefined
|
|
17754
17846
|
});
|
|
17755
17847
|
},
|
|
17756
17848
|
getNetFilterContext: () => {
|
|
17757
|
-
const
|
|
17758
|
-
if (!
|
|
17849
|
+
const session2 = currentSession;
|
|
17850
|
+
if (!session2) {
|
|
17759
17851
|
return null;
|
|
17760
17852
|
}
|
|
17761
|
-
const state2 = frameStateByTabId.get(
|
|
17762
|
-
const selectedTarget = getSelectedTarget(
|
|
17853
|
+
const state2 = frameStateByTabId.get(session2.tabId);
|
|
17854
|
+
const selectedTarget = getSelectedTarget(session2);
|
|
17763
17855
|
return {
|
|
17764
17856
|
sourceMode: "extension",
|
|
17765
17857
|
selectedFrameId: state2?.activeFrameId ?? null,
|
|
17766
|
-
topFrameId: state2?.topFrameId ??
|
|
17767
|
-
selectedTargetUrl: selectedTarget?.url ??
|
|
17768
|
-
pageUrl:
|
|
17858
|
+
topFrameId: state2?.topFrameId ?? session2.topFrameId,
|
|
17859
|
+
selectedTargetUrl: selectedTarget?.url ?? session2.url,
|
|
17860
|
+
pageUrl: session2.url
|
|
17769
17861
|
};
|
|
17770
17862
|
},
|
|
17771
17863
|
getFrameSessionId: (frameId) => {
|
|
17772
|
-
const
|
|
17773
|
-
if (!
|
|
17864
|
+
const session2 = currentSession;
|
|
17865
|
+
if (!session2) {
|
|
17774
17866
|
return null;
|
|
17775
17867
|
}
|
|
17776
|
-
const state2 = frameStateByTabId.get(
|
|
17868
|
+
const state2 = frameStateByTabId.get(session2.tabId);
|
|
17777
17869
|
return state2?.frames.get(frameId)?.sessionId ?? null;
|
|
17778
17870
|
},
|
|
17779
17871
|
syncWatcherInfo: (info) => {
|
|
@@ -17809,10 +17901,10 @@ var createExtensionSource = (options) => {
|
|
|
17809
17901
|
}
|
|
17810
17902
|
delegatingSessions.clear();
|
|
17811
17903
|
}
|
|
17812
|
-
async function bootstrapAttachedSession(
|
|
17904
|
+
async function bootstrapAttachedSession(session2) {
|
|
17813
17905
|
try {
|
|
17814
17906
|
registerExtensionSessionEventHandlers({
|
|
17815
|
-
session,
|
|
17907
|
+
session: session2,
|
|
17816
17908
|
events,
|
|
17817
17909
|
ignoreMatcher: ignoreMatcherObj,
|
|
17818
17910
|
stripUrlPrefixes: stripUrlPrefixes2,
|
|
@@ -17826,34 +17918,34 @@ var createExtensionSource = (options) => {
|
|
|
17826
17918
|
currentSession = nextSession;
|
|
17827
17919
|
}
|
|
17828
17920
|
});
|
|
17829
|
-
await enableBootstrapDomains(
|
|
17830
|
-
await refreshFrameTree(
|
|
17831
|
-
if (currentSession?.tabId !==
|
|
17921
|
+
await enableBootstrapDomains(session2);
|
|
17922
|
+
await refreshFrameTree(session2);
|
|
17923
|
+
if (currentSession?.tabId !== session2.tabId) {
|
|
17832
17924
|
return;
|
|
17833
17925
|
}
|
|
17834
|
-
const target = getSelectedTarget(
|
|
17926
|
+
const target = getSelectedTarget(session2) ?? buildPageTarget(session2, { attached: true });
|
|
17835
17927
|
emitStatus(target, null);
|
|
17836
|
-
await events.onAttach?.(
|
|
17837
|
-
reconcileTargetSelection(
|
|
17928
|
+
await events.onAttach?.(session2.handle, target);
|
|
17929
|
+
reconcileTargetSelection(session2);
|
|
17838
17930
|
} catch (error) {
|
|
17839
17931
|
const message = formatError(error);
|
|
17840
|
-
console.error(`[ExtensionSource] Failed to bootstrap attached tab ${
|
|
17841
|
-
if (currentSession?.tabId ===
|
|
17932
|
+
console.error(`[ExtensionSource] Failed to bootstrap attached tab ${session2.tabId}: ${message}`);
|
|
17933
|
+
if (currentSession?.tabId === session2.tabId) {
|
|
17842
17934
|
emitStatus(null, message);
|
|
17843
17935
|
events.onDetach?.(message);
|
|
17844
17936
|
}
|
|
17845
17937
|
}
|
|
17846
17938
|
}
|
|
17847
|
-
async function enableBootstrapDomains(
|
|
17848
|
-
await
|
|
17849
|
-
await
|
|
17939
|
+
async function enableBootstrapDomains(session2) {
|
|
17940
|
+
await session2.handle.sendAndWait("Runtime.enable");
|
|
17941
|
+
await session2.handle.sendAndWait("Page.enable");
|
|
17850
17942
|
}
|
|
17851
17943
|
function getCurrentTargetContext() {
|
|
17852
|
-
const
|
|
17853
|
-
if (!
|
|
17944
|
+
const session2 = currentSession;
|
|
17945
|
+
if (!session2) {
|
|
17854
17946
|
return null;
|
|
17855
17947
|
}
|
|
17856
|
-
const state2 = frameStateByTabId.get(
|
|
17948
|
+
const state2 = frameStateByTabId.get(session2.tabId);
|
|
17857
17949
|
const frameId = state2?.requestedFrameId ?? state2?.activeFrameId;
|
|
17858
17950
|
if (!state2 || !frameId) {
|
|
17859
17951
|
return { kind: "page" };
|
|
@@ -17869,13 +17961,13 @@ var createExtensionSource = (options) => {
|
|
|
17869
17961
|
frameStateByTabId.set(tabId, created);
|
|
17870
17962
|
return created;
|
|
17871
17963
|
}
|
|
17872
|
-
function seedFrameState(
|
|
17873
|
-
const state2 = getOrCreateFrameState(
|
|
17874
|
-
return seedExtensionFrameState(
|
|
17964
|
+
function seedFrameState(session2) {
|
|
17965
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
17966
|
+
return seedExtensionFrameState(session2, state2);
|
|
17875
17967
|
}
|
|
17876
17968
|
function emitStatus(target, reason) {
|
|
17877
|
-
const
|
|
17878
|
-
const targetReady = target == null ? null :
|
|
17969
|
+
const session2 = currentSession;
|
|
17970
|
+
const targetReady = target == null ? null : session2 ? isTargetReady(session2.tabId) : true;
|
|
17879
17971
|
events.onStatus({
|
|
17880
17972
|
attached: Boolean(target),
|
|
17881
17973
|
targetReady,
|
|
@@ -17888,16 +17980,16 @@ var createExtensionSource = (options) => {
|
|
|
17888
17980
|
reason
|
|
17889
17981
|
});
|
|
17890
17982
|
}
|
|
17891
|
-
function emitTargetChanged(
|
|
17892
|
-
const target = getSelectedTarget(
|
|
17983
|
+
function emitTargetChanged(session2) {
|
|
17984
|
+
const target = getSelectedTarget(session2);
|
|
17893
17985
|
if (!target) {
|
|
17894
17986
|
return;
|
|
17895
17987
|
}
|
|
17896
|
-
const state2 = getOrCreateFrameState(
|
|
17988
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
17897
17989
|
if (state2.activeAttachedAt == null) {
|
|
17898
17990
|
state2.activeAttachedAt = Date.now();
|
|
17899
17991
|
}
|
|
17900
|
-
const targetReady = isTargetReady(
|
|
17992
|
+
const targetReady = isTargetReady(session2.tabId);
|
|
17901
17993
|
emitStatus(target, null);
|
|
17902
17994
|
messaging.send({
|
|
17903
17995
|
type: "target_info",
|
|
@@ -17907,46 +17999,46 @@ var createExtensionSource = (options) => {
|
|
|
17907
17999
|
attachedAt: state2.activeAttachedAt,
|
|
17908
18000
|
targetReady
|
|
17909
18001
|
});
|
|
17910
|
-
events.onTargetChanged?.(
|
|
18002
|
+
events.onTargetChanged?.(session2.handle, target);
|
|
17911
18003
|
}
|
|
17912
|
-
function getSelectedTarget(
|
|
17913
|
-
return getSelectedExtensionTarget(
|
|
18004
|
+
function getSelectedTarget(session2) {
|
|
18005
|
+
return getSelectedExtensionTarget(session2, frameStateByTabId.get(session2.tabId));
|
|
17914
18006
|
}
|
|
17915
|
-
function requestTargetSelection(
|
|
17916
|
-
const state2 = getOrCreateFrameState(
|
|
18007
|
+
function requestTargetSelection(session2, frameId) {
|
|
18008
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
17917
18009
|
setRequestedTargetSelection(state2, frameId);
|
|
17918
|
-
reconcileTargetSelection(
|
|
18010
|
+
reconcileTargetSelection(session2);
|
|
17919
18011
|
}
|
|
17920
|
-
function reconcileTargetSelection(
|
|
17921
|
-
const state2 = getOrCreateFrameState(
|
|
17922
|
-
const changed = reconcileExtensionTargetSelection(
|
|
17923
|
-
emitTargetChanged(
|
|
18012
|
+
function reconcileTargetSelection(session2) {
|
|
18013
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
18014
|
+
const changed = reconcileExtensionTargetSelection(session2, state2, () => {
|
|
18015
|
+
emitTargetChanged(session2);
|
|
17924
18016
|
});
|
|
17925
|
-
targetRecovery.sync(
|
|
18017
|
+
targetRecovery.sync(session2, state2);
|
|
17926
18018
|
return changed;
|
|
17927
18019
|
}
|
|
17928
|
-
async function refreshFrameTree(
|
|
17929
|
-
await
|
|
18020
|
+
async function refreshFrameTree(session2) {
|
|
18021
|
+
await session2.requestFrameSnapshot({ refresh: true });
|
|
17930
18022
|
}
|
|
17931
18023
|
function removeFrame(tabId, frameId) {
|
|
17932
18024
|
const state2 = getOrCreateFrameState(tabId);
|
|
17933
18025
|
removeExtensionFrame(state2, frameId);
|
|
17934
18026
|
}
|
|
17935
|
-
async function refreshFrameTitle(
|
|
17936
|
-
const state2 = getOrCreateFrameState(
|
|
17937
|
-
await refreshExtensionFrameTitle(
|
|
17938
|
-
emitTargetChanged(
|
|
18027
|
+
async function refreshFrameTitle(session2, frameId, contextId) {
|
|
18028
|
+
const state2 = getOrCreateFrameState(session2.tabId);
|
|
18029
|
+
await refreshExtensionFrameTitle(session2, state2, frameId, () => {
|
|
18030
|
+
emitTargetChanged(session2);
|
|
17939
18031
|
}, contextId);
|
|
17940
18032
|
}
|
|
17941
18033
|
function isTargetReady(tabId) {
|
|
17942
18034
|
return isSelectedTargetReady(getOrCreateFrameState(tabId));
|
|
17943
18035
|
}
|
|
17944
18036
|
};
|
|
17945
|
-
var sessionToBrowserTab = (
|
|
17946
|
-
tabId:
|
|
17947
|
-
url:
|
|
17948
|
-
title:
|
|
17949
|
-
faviconUrl:
|
|
18037
|
+
var sessionToBrowserTab = (session2) => ({
|
|
18038
|
+
tabId: session2.tabId,
|
|
18039
|
+
url: session2.url,
|
|
18040
|
+
title: session2.title,
|
|
18041
|
+
faviconUrl: session2.faviconUrl,
|
|
17950
18042
|
attached: true
|
|
17951
18043
|
});
|
|
17952
18044
|
|
|
@@ -18075,19 +18167,19 @@ var createWatcherHandle = async (options, watcherId) => {
|
|
|
18075
18167
|
const handlePageIntl = (info) => {
|
|
18076
18168
|
fileLogger?.setPageIntl(info);
|
|
18077
18169
|
};
|
|
18078
|
-
const handleSourceAttach = async (
|
|
18170
|
+
const handleSourceAttach = async (session2, target) => {
|
|
18079
18171
|
elementRefs.reset();
|
|
18080
18172
|
dialogTracker.clear();
|
|
18081
18173
|
runtimeEditor?.rebind();
|
|
18082
|
-
await emulationController.onAttach(
|
|
18083
|
-
await throttleController.onAttach(
|
|
18174
|
+
await emulationController.onAttach(session2);
|
|
18175
|
+
await throttleController.onAttach(session2);
|
|
18084
18176
|
await visibilityController.onAttach(getPageSession());
|
|
18085
18177
|
await netMockController.onAttach();
|
|
18086
18178
|
await networkCapture?.onAttached();
|
|
18087
|
-
indicator.onAttach(
|
|
18088
|
-
await injectOnAttach(
|
|
18179
|
+
indicator.onAttach(session2, target);
|
|
18180
|
+
await injectOnAttach(session2, target);
|
|
18089
18181
|
};
|
|
18090
|
-
const handleTargetChanged = (
|
|
18182
|
+
const handleTargetChanged = (session2, target) => {
|
|
18091
18183
|
elementRefs.reset();
|
|
18092
18184
|
updateCdpStatus({
|
|
18093
18185
|
attached: true,
|
|
@@ -18100,7 +18192,7 @@ var createWatcherHandle = async (options, watcherId) => {
|
|
|
18100
18192
|
reason: null
|
|
18101
18193
|
});
|
|
18102
18194
|
netMockController.onTargetChanged();
|
|
18103
|
-
indicator.onAttach(
|
|
18195
|
+
indicator.onAttach(session2, target);
|
|
18104
18196
|
};
|
|
18105
18197
|
const handleSourceDetach = (reason) => {
|
|
18106
18198
|
elementRefs.reset();
|
|
@@ -23629,14 +23721,14 @@ var parseCookieSetInput = (input, output) => {
|
|
|
23629
23721
|
if (sameSite === "None" && input.secure !== true) {
|
|
23630
23722
|
return writeCookieInputError(output, "sameSite=None requires --secure");
|
|
23631
23723
|
}
|
|
23632
|
-
const
|
|
23724
|
+
const session2 = input.session === true || expires === undefined;
|
|
23633
23725
|
return {
|
|
23634
23726
|
...identity,
|
|
23635
23727
|
value: input.value,
|
|
23636
23728
|
secure: input.secure === true,
|
|
23637
23729
|
httpOnly: input.httpOnly === true,
|
|
23638
|
-
session,
|
|
23639
|
-
expires:
|
|
23730
|
+
session: session2,
|
|
23731
|
+
expires: session2 ? null : expires,
|
|
23640
23732
|
sameSite
|
|
23641
23733
|
};
|
|
23642
23734
|
};
|
|
@@ -48234,7 +48326,7 @@ var keydownCommand = {
|
|
|
48234
48326
|
arguments: [{ flags: "[id]", description: "Watcher id to query" }],
|
|
48235
48327
|
options: [
|
|
48236
48328
|
{ flags: "--key <name>", description: "KeyboardEvent.key value (e.g. Enter, a, ArrowUp)" },
|
|
48237
|
-
{ flags: "--code <code>", description: "KeyboardEvent.code value (e.g. KeyG, Digit1)" },
|
|
48329
|
+
{ flags: "--code <code>", description: "KeyboardEvent.code value (e.g. KeyG, Digit1, Backquote)" },
|
|
48238
48330
|
{ flags: "--selector <css>", description: "Focus element before dispatching" },
|
|
48239
48331
|
{ flags: "--testid <id>", description: `Shorthand for --selector "[data-testid='<id>']"` },
|
|
48240
48332
|
{ flags: "--modifiers <list>", description: "Comma-separated modifiers: shift,ctrl,alt,meta" },
|
|
@@ -48250,6 +48342,7 @@ var keydownCommand = {
|
|
|
48250
48342
|
"argus keydown app --key Enter",
|
|
48251
48343
|
"argus keydown app --key G",
|
|
48252
48344
|
"argus keydown app --code KeyG",
|
|
48345
|
+
"argus keydown app --code Backquote --shift",
|
|
48253
48346
|
'argus keydown app --key a --selector "#input"',
|
|
48254
48347
|
"argus keydown app --key a --shift --ctrl"
|
|
48255
48348
|
],
|
|
@@ -51859,6 +51952,492 @@ var skillCommands = [
|
|
|
51859
51952
|
}
|
|
51860
51953
|
];
|
|
51861
51954
|
|
|
51955
|
+
// dist/session/runSession.js
|
|
51956
|
+
import readline from "node:readline";
|
|
51957
|
+
|
|
51958
|
+
// dist/session/sessionArgv.js
|
|
51959
|
+
var resolveSessionCommand = (program2, cmd) => {
|
|
51960
|
+
const tokens = cmd.trim().split(/\s+/).filter(Boolean);
|
|
51961
|
+
if (tokens.length === 0) {
|
|
51962
|
+
return { ok: false, code: "session_invalid_request", message: "cmd must name a command" };
|
|
51963
|
+
}
|
|
51964
|
+
let current = program2;
|
|
51965
|
+
const path25 = [];
|
|
51966
|
+
for (const token of tokens) {
|
|
51967
|
+
const next = current.commands.find((candidate) => candidate.name() === token || candidate.aliases().includes(token));
|
|
51968
|
+
if (!next) {
|
|
51969
|
+
const context = path25.length > 0 ? ` under "${path25.join(" ")}"` : "";
|
|
51970
|
+
return { ok: false, code: "session_unknown_command", message: `Unknown command "${token}"${context}.` };
|
|
51971
|
+
}
|
|
51972
|
+
current = next;
|
|
51973
|
+
path25.push(next.name());
|
|
51974
|
+
}
|
|
51975
|
+
return { ok: true, command: current, path: path25 };
|
|
51976
|
+
};
|
|
51977
|
+
var buildSessionArgv = (input) => {
|
|
51978
|
+
const resolved = resolveSessionCommand(input.program, input.request.cmd);
|
|
51979
|
+
if (!resolved.ok) {
|
|
51980
|
+
return resolved;
|
|
51981
|
+
}
|
|
51982
|
+
const blocked = rejectNonSessionCommand(resolved.path);
|
|
51983
|
+
if (blocked) {
|
|
51984
|
+
return blocked;
|
|
51985
|
+
}
|
|
51986
|
+
const tail = input.request.argv ? [...input.request.argv] : buildArgvFromArgs(resolved.command, input.request.args ?? {});
|
|
51987
|
+
if (isArgvFailure(tail)) {
|
|
51988
|
+
return tail;
|
|
51989
|
+
}
|
|
51990
|
+
const argv = [...resolved.path];
|
|
51991
|
+
if (takesWatcherId(resolved.command) && tail[0] !== input.watcherId) {
|
|
51992
|
+
argv.push(input.watcherId);
|
|
51993
|
+
}
|
|
51994
|
+
argv.push(...tail);
|
|
51995
|
+
if (declaresOption(resolved.command, "json") && !tail.some(isJsonFlag)) {
|
|
51996
|
+
argv.push("--json");
|
|
51997
|
+
}
|
|
51998
|
+
const rejected = rejectStdinInput(argv, resolved.path);
|
|
51999
|
+
if (rejected) {
|
|
52000
|
+
return rejected;
|
|
52001
|
+
}
|
|
52002
|
+
return { ok: true, argv, resolved };
|
|
52003
|
+
};
|
|
52004
|
+
var NON_SESSION_COMMANDS = new Set(["session", "start", "chrome start", "watcher start", "watcher native-host", "logs tail", "net tail", "net sse"]);
|
|
52005
|
+
var rejectNonSessionCommand = (path25) => {
|
|
52006
|
+
const name = path25.join(" ");
|
|
52007
|
+
if (!NON_SESSION_COMMANDS.has(name)) {
|
|
52008
|
+
return null;
|
|
52009
|
+
}
|
|
52010
|
+
return {
|
|
52011
|
+
ok: false,
|
|
52012
|
+
code: "session_command_rejected",
|
|
52013
|
+
message: `"${name}" runs until interrupted and cannot be dispatched from a session; run it as its own process.`
|
|
52014
|
+
};
|
|
52015
|
+
};
|
|
52016
|
+
var rejectStdinInput = (argv, path25) => {
|
|
52017
|
+
const readsStdin = argv.includes("--stdin") || STDIN_DASH_COMMANDS.has(path25[0]) && argv.includes("-");
|
|
52018
|
+
if (!readsStdin) {
|
|
52019
|
+
return null;
|
|
52020
|
+
}
|
|
52021
|
+
return {
|
|
52022
|
+
ok: false,
|
|
52023
|
+
code: "session_command_rejected",
|
|
52024
|
+
message: "stdin belongs to the session transport; pass the expression inline or with --file instead of reading stdin."
|
|
52025
|
+
};
|
|
52026
|
+
};
|
|
52027
|
+
var STDIN_DASH_COMMANDS = new Set(["eval", "eval-until"]);
|
|
52028
|
+
var isArgvFailure = (value) => !Array.isArray(value);
|
|
52029
|
+
var isJsonFlag = (token) => token === "--json" || token === "--no-json" || token === "--json-full";
|
|
52030
|
+
var takesWatcherId = (command) => command.registeredArguments[0]?.name() === "id";
|
|
52031
|
+
var declaresOption = (command, name) => findOptions(command, name).length > 0;
|
|
52032
|
+
var buildArgvFromArgs = (command, args) => {
|
|
52033
|
+
const names = positionalNames(command);
|
|
52034
|
+
const tokens = [];
|
|
52035
|
+
const positionals = {};
|
|
52036
|
+
for (const [key, value] of Object.entries(args)) {
|
|
52037
|
+
if (value === undefined)
|
|
52038
|
+
continue;
|
|
52039
|
+
const options = findOptions(command, key);
|
|
52040
|
+
if (options.length === 0) {
|
|
52041
|
+
if (!names.includes(camelCase(key))) {
|
|
52042
|
+
const path25 = commandPath(command);
|
|
52043
|
+
return {
|
|
52044
|
+
ok: false,
|
|
52045
|
+
code: "session_invalid_request",
|
|
52046
|
+
message: `Unknown argument "${key}" for command "${path25}". Run \`argus ${path25} --help\` for the accepted flags.`
|
|
52047
|
+
};
|
|
52048
|
+
}
|
|
52049
|
+
positionals[camelCase(key)] = value;
|
|
52050
|
+
continue;
|
|
52051
|
+
}
|
|
52052
|
+
const emitted = emitOption(options, key, value);
|
|
52053
|
+
if (isArgvFailure(emitted)) {
|
|
52054
|
+
return emitted;
|
|
52055
|
+
}
|
|
52056
|
+
tokens.push(...emitted);
|
|
52057
|
+
}
|
|
52058
|
+
const ordered = orderPositionals(names, positionals);
|
|
52059
|
+
if (isArgvFailure(ordered)) {
|
|
52060
|
+
return ordered;
|
|
52061
|
+
}
|
|
52062
|
+
return [...ordered, ...tokens];
|
|
52063
|
+
};
|
|
52064
|
+
var emitOption = (options, key, value) => {
|
|
52065
|
+
const positive = options.find((option) => !option.negate);
|
|
52066
|
+
const negated = options.find((option) => option.negate);
|
|
52067
|
+
const valued = options.find((option) => option.required || option.optional);
|
|
52068
|
+
if (valued) {
|
|
52069
|
+
const values = Array.isArray(value) ? value : [value];
|
|
52070
|
+
const tokens = [];
|
|
52071
|
+
for (const entry of values) {
|
|
52072
|
+
if (entry == null)
|
|
52073
|
+
continue;
|
|
52074
|
+
if (typeof entry === "object") {
|
|
52075
|
+
return { ok: false, code: "session_invalid_request", message: `Argument "${key}" must be a string, number, or boolean.` };
|
|
52076
|
+
}
|
|
52077
|
+
tokens.push(flagOf(valued), String(entry));
|
|
52078
|
+
}
|
|
52079
|
+
return tokens;
|
|
52080
|
+
}
|
|
52081
|
+
if (typeof value !== "boolean") {
|
|
52082
|
+
return { ok: false, code: "session_invalid_request", message: `Argument "${key}" is a switch and must be true or false.` };
|
|
52083
|
+
}
|
|
52084
|
+
const wanted = value ? positive : negated;
|
|
52085
|
+
return wanted ? [flagOf(wanted)] : [];
|
|
52086
|
+
};
|
|
52087
|
+
var orderPositionals = (declaredNames, values) => {
|
|
52088
|
+
const tokens = [];
|
|
52089
|
+
let missing = null;
|
|
52090
|
+
for (const name of declaredNames) {
|
|
52091
|
+
if (name === "id")
|
|
52092
|
+
continue;
|
|
52093
|
+
const value = values[name];
|
|
52094
|
+
if (value === undefined) {
|
|
52095
|
+
missing ??= name;
|
|
52096
|
+
continue;
|
|
52097
|
+
}
|
|
52098
|
+
if (missing) {
|
|
52099
|
+
return {
|
|
52100
|
+
ok: false,
|
|
52101
|
+
code: "session_invalid_request",
|
|
52102
|
+
message: `Argument "${name}" cannot be set without "${missing}"; positional arguments are filled in order.`
|
|
52103
|
+
};
|
|
52104
|
+
}
|
|
52105
|
+
for (const entry of Array.isArray(value) ? value : [value]) {
|
|
52106
|
+
if (entry != null && typeof entry === "object") {
|
|
52107
|
+
return { ok: false, code: "session_invalid_request", message: `Argument "${name}" must be a string, number, or boolean.` };
|
|
52108
|
+
}
|
|
52109
|
+
tokens.push(String(entry));
|
|
52110
|
+
}
|
|
52111
|
+
}
|
|
52112
|
+
return tokens;
|
|
52113
|
+
};
|
|
52114
|
+
var findOptions = (command, key) => {
|
|
52115
|
+
const wanted = camelCase(key);
|
|
52116
|
+
return commandChain(command).flatMap((current) => current.options).filter((option) => option.attributeName() === wanted || option.name() === key || option.short === `-${key}`);
|
|
52117
|
+
};
|
|
52118
|
+
var positionalNames = (command) => command.registeredArguments.map((argument) => camelCase(argument.name()));
|
|
52119
|
+
var flagOf = (option) => option.long ?? option.short ?? `--${option.name()}`;
|
|
52120
|
+
var commandPath = (command) => commandChain(command).map((current) => current.name()).reverse().join(" ");
|
|
52121
|
+
var commandChain = (command) => {
|
|
52122
|
+
const chain = [];
|
|
52123
|
+
for (let current = command;current?.parent; current = current.parent) {
|
|
52124
|
+
chain.push(current);
|
|
52125
|
+
}
|
|
52126
|
+
return chain;
|
|
52127
|
+
};
|
|
52128
|
+
var camelCase = (value) => value.replace(/[-_]([a-z0-9])/g, (_4, character) => character.toUpperCase());
|
|
52129
|
+
|
|
52130
|
+
// dist/session/sessionDispatch.js
|
|
52131
|
+
var dispatchSessionRequest = async (input) => {
|
|
52132
|
+
const { request } = input;
|
|
52133
|
+
const respond = createResponder(request, Date.now());
|
|
52134
|
+
const timeoutMs = resolveTimeoutMs(request.timeout, input.defaultTimeoutMs);
|
|
52135
|
+
if (timeoutMs == null) {
|
|
52136
|
+
return respond.failure({ message: `Invalid timeout "${String(request.timeout)}".`, code: "session_invalid_request" }, 2);
|
|
52137
|
+
}
|
|
52138
|
+
const built = buildSessionArgv({ program: input.program, request, watcherId: input.watcherId });
|
|
52139
|
+
if (!built.ok) {
|
|
52140
|
+
return respond.failure({ message: built.message, code: built.code }, 2);
|
|
52141
|
+
}
|
|
52142
|
+
const sink = { stdout: [], stderr: [] };
|
|
52143
|
+
process.exitCode = 0;
|
|
52144
|
+
const running = input.capture.run(sink, async () => {
|
|
52145
|
+
try {
|
|
52146
|
+
await input.program.parseAsync(built.argv, { from: "user" });
|
|
52147
|
+
return null;
|
|
52148
|
+
} catch (error) {
|
|
52149
|
+
return error;
|
|
52150
|
+
}
|
|
52151
|
+
});
|
|
52152
|
+
const settled = await raceWithTimeout(running, timeoutMs);
|
|
52153
|
+
const stderr = sink.stderr.join("");
|
|
52154
|
+
if (settled.timedOut) {
|
|
52155
|
+
return respond.failure({ message: `Request timed out after ${timeoutMs}ms.`, code: "session_request_timeout" }, 1, stderr);
|
|
52156
|
+
}
|
|
52157
|
+
const exitCode = typeof process.exitCode === "number" ? process.exitCode : 0;
|
|
52158
|
+
process.exitCode = 0;
|
|
52159
|
+
const stdout = sink.stdout.join("");
|
|
52160
|
+
if (settled.error) {
|
|
52161
|
+
return fromThrownError(respond, settled.error, stdout, stderr);
|
|
52162
|
+
}
|
|
52163
|
+
if (exitCode !== 0) {
|
|
52164
|
+
return respond.failure(errorDetailFrom(stdout, stderr), exitCode, stderr);
|
|
52165
|
+
}
|
|
52166
|
+
return respond.success(stdout, stderr);
|
|
52167
|
+
};
|
|
52168
|
+
var fromThrownError = (respond, error, stdout, stderr) => {
|
|
52169
|
+
if (!(error instanceof CommanderError)) {
|
|
52170
|
+
return respond.failure({ message: formatError(error), code: "session_command_failed" }, 1, stderr);
|
|
52171
|
+
}
|
|
52172
|
+
if (error.exitCode === 0) {
|
|
52173
|
+
return respond.success(stdout, stderr);
|
|
52174
|
+
}
|
|
52175
|
+
return respond.failure({ message: error.message, code: "session_invalid_request" }, error.exitCode || 2, stderr);
|
|
52176
|
+
};
|
|
52177
|
+
var decodeStdout = (stdout) => {
|
|
52178
|
+
const lines = stdout.split(`
|
|
52179
|
+
`).filter((line) => line.trim() !== "");
|
|
52180
|
+
if (lines.length === 0) {
|
|
52181
|
+
return { result: null };
|
|
52182
|
+
}
|
|
52183
|
+
const documents = [];
|
|
52184
|
+
for (const line of lines) {
|
|
52185
|
+
try {
|
|
52186
|
+
documents.push(JSON.parse(line));
|
|
52187
|
+
} catch {
|
|
52188
|
+
return { result: stdout, raw: true };
|
|
52189
|
+
}
|
|
52190
|
+
}
|
|
52191
|
+
return documents.length === 1 ? { result: documents[0] } : { result: documents, stream: true };
|
|
52192
|
+
};
|
|
52193
|
+
var errorDetailFrom = (stdout, stderr) => {
|
|
52194
|
+
const document = decodeStdout(stdout).result;
|
|
52195
|
+
if (document && typeof document === "object" && document.ok === false) {
|
|
52196
|
+
const detail = document.error;
|
|
52197
|
+
if (detail?.message) {
|
|
52198
|
+
return detail;
|
|
52199
|
+
}
|
|
52200
|
+
}
|
|
52201
|
+
const message = stderr.trim().split(`
|
|
52202
|
+
`).filter(Boolean).at(-1);
|
|
52203
|
+
return { message: message ?? "Command failed.", code: "session_command_failed" };
|
|
52204
|
+
};
|
|
52205
|
+
var createResponder = (request, startedAt) => {
|
|
52206
|
+
const id = request.id === undefined ? {} : { id: request.id };
|
|
52207
|
+
const trailer = (stderr) => ({ durationMs: Date.now() - startedAt, ...stderr === "" ? {} : { stderr } });
|
|
52208
|
+
return {
|
|
52209
|
+
success: (stdout, stderr) => ({ ...id, ok: true, ...decodeStdout(stdout), ...trailer(stderr) }),
|
|
52210
|
+
failure: (error, exitCode, stderr = "") => ({ ...id, ok: false, error, exitCode, ...trailer(stderr) })
|
|
52211
|
+
};
|
|
52212
|
+
};
|
|
52213
|
+
var resolveTimeoutMs = (timeout, fallbackMs) => {
|
|
52214
|
+
if (timeout == null) {
|
|
52215
|
+
return fallbackMs;
|
|
52216
|
+
}
|
|
52217
|
+
if (typeof timeout === "number") {
|
|
52218
|
+
return timeout;
|
|
52219
|
+
}
|
|
52220
|
+
return parseDurationMs(timeout, "ms");
|
|
52221
|
+
};
|
|
52222
|
+
var raceWithTimeout = async (running, timeoutMs) => {
|
|
52223
|
+
if (timeoutMs <= 0) {
|
|
52224
|
+
return { timedOut: false, error: await running };
|
|
52225
|
+
}
|
|
52226
|
+
let timer;
|
|
52227
|
+
const watchdog = new Promise((resolve2) => {
|
|
52228
|
+
timer = setTimeout(() => resolve2({ timedOut: true }), timeoutMs);
|
|
52229
|
+
});
|
|
52230
|
+
try {
|
|
52231
|
+
return await Promise.race([running.then((error) => ({ timedOut: false, error })), watchdog]);
|
|
52232
|
+
} finally {
|
|
52233
|
+
clearTimeout(timer);
|
|
52234
|
+
}
|
|
52235
|
+
};
|
|
52236
|
+
|
|
52237
|
+
// dist/session/stdioCapture.js
|
|
52238
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
52239
|
+
var installStdioCapture = () => {
|
|
52240
|
+
const storage2 = new AsyncLocalStorage;
|
|
52241
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
52242
|
+
const originalStderrWrite = process.stderr.write.bind(process.stderr);
|
|
52243
|
+
process.stdout.write = createCapturingWrite(storage2, originalStdoutWrite, (sink) => sink.stdout, false);
|
|
52244
|
+
process.stderr.write = createCapturingWrite(storage2, originalStderrWrite, (sink) => sink.stderr, true);
|
|
52245
|
+
return {
|
|
52246
|
+
run: (sink, body) => storage2.run(sink, body),
|
|
52247
|
+
writeStdout: (text) => {
|
|
52248
|
+
originalStdoutWrite(text);
|
|
52249
|
+
},
|
|
52250
|
+
restore: () => {
|
|
52251
|
+
process.stdout.write = originalStdoutWrite;
|
|
52252
|
+
process.stderr.write = originalStderrWrite;
|
|
52253
|
+
}
|
|
52254
|
+
};
|
|
52255
|
+
};
|
|
52256
|
+
var createCapturingWrite = (storage2, original, select, mirror) => {
|
|
52257
|
+
const forward = original;
|
|
52258
|
+
return (chunk, encoding, callback) => {
|
|
52259
|
+
const sink = storage2.getStore();
|
|
52260
|
+
if (!sink) {
|
|
52261
|
+
return forward(chunk, encoding, callback);
|
|
52262
|
+
}
|
|
52263
|
+
select(sink).push(decodeChunk(chunk, encoding));
|
|
52264
|
+
if (mirror) {
|
|
52265
|
+
forward(chunk, encoding);
|
|
52266
|
+
}
|
|
52267
|
+
const done = typeof encoding === "function" ? encoding : callback;
|
|
52268
|
+
if (typeof done === "function") {
|
|
52269
|
+
done();
|
|
52270
|
+
}
|
|
52271
|
+
return true;
|
|
52272
|
+
};
|
|
52273
|
+
};
|
|
52274
|
+
var decodeChunk = (chunk, encoding) => {
|
|
52275
|
+
if (typeof chunk === "string") {
|
|
52276
|
+
return chunk;
|
|
52277
|
+
}
|
|
52278
|
+
const bufferEncoding = typeof encoding === "string" ? encoding : "utf8";
|
|
52279
|
+
return Buffer.from(chunk).toString(bufferEncoding);
|
|
52280
|
+
};
|
|
52281
|
+
|
|
52282
|
+
// dist/session/runSession.js
|
|
52283
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 120000;
|
|
52284
|
+
var WATCHER_PROBE_TIMEOUT_MS = 1500;
|
|
52285
|
+
var runSession = async (id, options) => {
|
|
52286
|
+
routeConsoleToStderr();
|
|
52287
|
+
const output = createOutput({ json: true });
|
|
52288
|
+
const defaultTimeoutMs = resolveDefaultTimeout(options, output);
|
|
52289
|
+
if (defaultTimeoutMs == null)
|
|
52290
|
+
return;
|
|
52291
|
+
const resolved = await resolveWatcherOrExit({ id }, output);
|
|
52292
|
+
if (!resolved)
|
|
52293
|
+
return;
|
|
52294
|
+
const program2 = await buildSessionProgram();
|
|
52295
|
+
const capture = installStdioCapture();
|
|
52296
|
+
const writeLine = (line) => capture.writeStdout(`${JSON.stringify(line)}
|
|
52297
|
+
`);
|
|
52298
|
+
writeLine(readyEvent(resolved.watcher));
|
|
52299
|
+
const exitCode = await serveRequests({
|
|
52300
|
+
program: program2,
|
|
52301
|
+
capture,
|
|
52302
|
+
writeLine,
|
|
52303
|
+
output,
|
|
52304
|
+
watcher: resolved.watcher,
|
|
52305
|
+
defaultTimeoutMs,
|
|
52306
|
+
reconnect: options.reconnect === true
|
|
52307
|
+
});
|
|
52308
|
+
capture.restore();
|
|
52309
|
+
await flushStdout();
|
|
52310
|
+
process.exit(exitCode);
|
|
52311
|
+
};
|
|
52312
|
+
var serveRequests = async (input) => {
|
|
52313
|
+
const lines = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
52314
|
+
try {
|
|
52315
|
+
for await (const line of lines) {
|
|
52316
|
+
if (line.trim() === "")
|
|
52317
|
+
continue;
|
|
52318
|
+
const request = parseRequestLine(line);
|
|
52319
|
+
if (!request.ok) {
|
|
52320
|
+
input.writeLine(request.response);
|
|
52321
|
+
continue;
|
|
52322
|
+
}
|
|
52323
|
+
if (request.value.cmd === "quit") {
|
|
52324
|
+
input.writeLine(controlResponse(request.value.id, { closed: true }));
|
|
52325
|
+
return 0;
|
|
52326
|
+
}
|
|
52327
|
+
if (request.value.cmd === "ping") {
|
|
52328
|
+
input.writeLine(controlResponse(request.value.id, { pong: true, watcher: input.watcher.id }));
|
|
52329
|
+
continue;
|
|
52330
|
+
}
|
|
52331
|
+
const response = await dispatchSessionRequest({
|
|
52332
|
+
program: input.program,
|
|
52333
|
+
capture: input.capture,
|
|
52334
|
+
request: request.value,
|
|
52335
|
+
watcherId: input.watcher.id,
|
|
52336
|
+
defaultTimeoutMs: input.defaultTimeoutMs
|
|
52337
|
+
});
|
|
52338
|
+
input.writeLine(response);
|
|
52339
|
+
if (await watcherLost(response, input)) {
|
|
52340
|
+
input.output.writeWarn(`Watcher ${input.watcher.id} is no longer reachable; closing session.`);
|
|
52341
|
+
return 1;
|
|
52342
|
+
}
|
|
52343
|
+
}
|
|
52344
|
+
} finally {
|
|
52345
|
+
lines.close();
|
|
52346
|
+
}
|
|
52347
|
+
return 0;
|
|
52348
|
+
};
|
|
52349
|
+
var watcherLost = async (response, input) => {
|
|
52350
|
+
if (response.ok || input.reconnect)
|
|
52351
|
+
return false;
|
|
52352
|
+
if (response.error.code && FRAMING_ERROR_CODES.has(response.error.code))
|
|
52353
|
+
return false;
|
|
52354
|
+
return !await watcherReachable(input.watcher.id);
|
|
52355
|
+
};
|
|
52356
|
+
var FRAMING_ERROR_CODES = new Set(["session_invalid_request", "session_unknown_command", "session_command_rejected"]);
|
|
52357
|
+
var watcherReachable = async (id) => {
|
|
52358
|
+
const resolved = await resolveWatcher({ id });
|
|
52359
|
+
if (!resolved.ok)
|
|
52360
|
+
return false;
|
|
52361
|
+
try {
|
|
52362
|
+
await fetchWatcherJson(resolved.watcher, { path: "/status", timeoutMs: WATCHER_PROBE_TIMEOUT_MS });
|
|
52363
|
+
return true;
|
|
52364
|
+
} catch {
|
|
52365
|
+
return false;
|
|
52366
|
+
}
|
|
52367
|
+
};
|
|
52368
|
+
var parseRequestLine = (line) => {
|
|
52369
|
+
let decoded;
|
|
52370
|
+
try {
|
|
52371
|
+
decoded = JSON.parse(line);
|
|
52372
|
+
} catch (error) {
|
|
52373
|
+
return { ok: false, response: framingError(`Request is not valid JSON: ${error.message}`) };
|
|
52374
|
+
}
|
|
52375
|
+
const parsed = SESSION_REQUEST_SCHEMA.parse(decoded);
|
|
52376
|
+
if (!parsed.ok) {
|
|
52377
|
+
const id = decoded?.id;
|
|
52378
|
+
return { ok: false, response: framingError(formatProtocolValidationIssues(parsed.issues), id) };
|
|
52379
|
+
}
|
|
52380
|
+
return { ok: true, value: parsed.value };
|
|
52381
|
+
};
|
|
52382
|
+
var framingError = (message, id) => ({
|
|
52383
|
+
...idOf(id),
|
|
52384
|
+
ok: false,
|
|
52385
|
+
error: { message, code: "session_invalid_request" },
|
|
52386
|
+
exitCode: 2,
|
|
52387
|
+
durationMs: 0
|
|
52388
|
+
});
|
|
52389
|
+
var controlResponse = (id, result) => ({ ...idOf(id), ok: true, result, durationMs: 0 });
|
|
52390
|
+
var idOf = (id) => id === undefined ? {} : { id };
|
|
52391
|
+
var buildSessionProgram = async () => {
|
|
52392
|
+
const program2 = createProgram({ mode: "session" });
|
|
52393
|
+
for (const registerProgramPart of coreProgramRegistrars) {
|
|
52394
|
+
registerProgramPart(program2);
|
|
52395
|
+
}
|
|
52396
|
+
await registerPlugins(program2);
|
|
52397
|
+
return program2;
|
|
52398
|
+
};
|
|
52399
|
+
var readyEvent = (watcher2) => ({
|
|
52400
|
+
type: "ready",
|
|
52401
|
+
protocolVersion: SESSION_PROTOCOL_VERSION,
|
|
52402
|
+
argusVersion: package_default.version,
|
|
52403
|
+
watcher: { id: watcher2.id, host: watcher2.host, port: watcher2.port }
|
|
52404
|
+
});
|
|
52405
|
+
var resolveDefaultTimeout = (options, output) => {
|
|
52406
|
+
if (options.requestTimeout == null) {
|
|
52407
|
+
return DEFAULT_REQUEST_TIMEOUT_MS;
|
|
52408
|
+
}
|
|
52409
|
+
const parsed = parseDurationMs(options.requestTimeout, "ms");
|
|
52410
|
+
if (parsed == null || parsed < 0) {
|
|
52411
|
+
usageError({ json: output.json }, `Invalid --request-timeout: ${options.requestTimeout}`);
|
|
52412
|
+
return null;
|
|
52413
|
+
}
|
|
52414
|
+
return parsed;
|
|
52415
|
+
};
|
|
52416
|
+
var flushStdout = () => new Promise((resolve2) => process.stdout.write("", () => resolve2()));
|
|
52417
|
+
|
|
52418
|
+
// dist/cli/register/sessionCommands.js
|
|
52419
|
+
var sessionCommands = [
|
|
52420
|
+
{
|
|
52421
|
+
name: "session",
|
|
52422
|
+
description: "Serve JSONL commands over stdin/stdout against one watcher, in a single process",
|
|
52423
|
+
arguments: [{ flags: "[id]", description: "Watcher id to pin the session to" }],
|
|
52424
|
+
options: [
|
|
52425
|
+
{ flags: "--request-timeout <duration>", description: "Per-request watchdog when the request omits one (default: 120s; 0 disables)" },
|
|
52426
|
+
{ flags: "--reconnect", description: "Stay alive when the watcher disappears and re-resolve it by id on the next request" },
|
|
52427
|
+
{ ...jsonOption, description: "Accepted for symmetry; the transport is always JSONL" }
|
|
52428
|
+
],
|
|
52429
|
+
examples: [
|
|
52430
|
+
"argus session app",
|
|
52431
|
+
"argus session app --request-timeout 30s",
|
|
52432
|
+
"argus session app --reconnect",
|
|
52433
|
+
`echo '{"id":1,"cmd":"eval","args":{"expression":"location.href"}}' | argus session app`
|
|
52434
|
+
],
|
|
52435
|
+
action: async (id, options) => {
|
|
52436
|
+
await runSession(id, options);
|
|
52437
|
+
}
|
|
52438
|
+
}
|
|
52439
|
+
];
|
|
52440
|
+
|
|
51862
52441
|
// dist/cli/register/index.js
|
|
51863
52442
|
var coreCommandDefinitions = [
|
|
51864
52443
|
...quickAccessCommands,
|
|
@@ -51885,6 +52464,7 @@ var coreCommandDefinitions = [
|
|
|
51885
52464
|
...recordCommands,
|
|
51886
52465
|
...traceCommands,
|
|
51887
52466
|
...configCommands,
|
|
52467
|
+
...sessionCommands,
|
|
51888
52468
|
...pluginCommands,
|
|
51889
52469
|
...skillCommands,
|
|
51890
52470
|
...extensionCommands
|