@nexum-hub/browser 0.0.3-next.17 → 0.0.3-next.19
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/browser-extension/build.mjs +4 -1
- package/browser-extension/connection.js +41 -5
- package/browser-extension/dist/development/connection.js +41 -5
- package/browser-extension/dist/development/frames.js +11 -0
- package/browser-extension/dist/development/manifest.json +1 -1
- package/browser-extension/dist/development/page.js +93 -3
- package/browser-extension/dist/development/router.js +216 -25
- package/browser-extension/dist/production/connection.js +41 -5
- package/browser-extension/dist/production/frames.js +11 -0
- package/browser-extension/dist/production/manifest.json +1 -1
- package/browser-extension/dist/production/page.js +93 -3
- package/browser-extension/dist/production/router.js +216 -25
- package/browser-extension/frames.js +11 -0
- package/browser-extension/page.js +93 -3
- package/browser-extension/release-info.json +5 -3
- package/browser-extension/router.js +216 -25
- package/dist/client/index.js +25 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/routes.js +5 -1
- package/dist/client/routes.js.map +1 -1
- package/dist/client/types.d.ts +20 -0
- package/dist/extension/assets.d.ts +1 -0
- package/dist/extension/assets.js +3 -1
- package/dist/extension/assets.js.map +1 -1
- package/dist/extension/index.js +6 -6
- package/dist/extension/index.js.map +1 -1
- package/dist/extension/service.d.ts +2 -0
- package/dist/extension/service.js +18 -8
- package/dist/extension/service.js.map +1 -1
- package/docs/README.md +5 -5
- package/docs/connection.md +1 -1
- package/docs/usage.md +45 -4
- package/implementation.json +1 -1
- package/package.json +2 -2
- package/skills/browser-control/SKILL.md +14 -5
|
@@ -1127,6 +1127,27 @@ async function point(ctx, args) {
|
|
|
1127
1127
|
return { x: args.x, y: args.y };
|
|
1128
1128
|
}
|
|
1129
1129
|
|
|
1130
|
+
async function readyForInput(ctx, framePath = []) {
|
|
1131
|
+
const ready = await ctx.router.page(ctx, {
|
|
1132
|
+
command: "readyState",
|
|
1133
|
+
framePath,
|
|
1134
|
+
});
|
|
1135
|
+
if (ready === "loading" || ready === "interactive") {
|
|
1136
|
+
const remaining = ctx.budgetMs - (performance.now() - ctx.started);
|
|
1137
|
+
requireValue(remaining > 0, "TIMEOUT", "The page did not become ready.");
|
|
1138
|
+
if (framePath.length)
|
|
1139
|
+
await ctx.router.poll(ctx, async () =>
|
|
1140
|
+
(await ctx.router.page(ctx, { command: "readyState", framePath })) ===
|
|
1141
|
+
"complete",
|
|
1142
|
+
);
|
|
1143
|
+
else
|
|
1144
|
+
await ctx.router.waitForLoadState(ctx, {
|
|
1145
|
+
state: "load",
|
|
1146
|
+
timeoutMs: remaining,
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1130
1151
|
// Build the points for real Chrome Input.dispatchMouseEvent calls, not a
|
|
1131
1152
|
// decorative animation that runs independently of the actual input.
|
|
1132
1153
|
export function humanPointerPath(from, to) {
|
|
@@ -1152,32 +1173,111 @@ export function humanPointerPath(from, to) {
|
|
|
1152
1173
|
return points;
|
|
1153
1174
|
}
|
|
1154
1175
|
async function click(ctx, args, double = false) {
|
|
1176
|
+
if (!args.resolvedTarget) await readyForInput(ctx);
|
|
1155
1177
|
const p = await point(ctx, args),
|
|
1156
1178
|
button = buttons[args.button ?? "left"];
|
|
1157
1179
|
requireValue(button);
|
|
1158
1180
|
const count = double ? 2 : (args.clickCount ?? 1);
|
|
1159
1181
|
requireValue(Number.isInteger(count) && count >= 1 && count <= 3);
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1182
|
+
const framePath = args.framePath ?? [];
|
|
1183
|
+
const originalVersion = ctx.router.version(ctx.target.tabId);
|
|
1184
|
+
const receiptInput = {
|
|
1185
|
+
command: "inputReceipt",
|
|
1186
|
+
token: ctx.actionId,
|
|
1187
|
+
x: args.framePoint?.x ?? p.x,
|
|
1188
|
+
y: args.framePoint?.y ?? p.y,
|
|
1189
|
+
button: { left: 0, middle: 1, right: 2 }[args.button ?? "left"],
|
|
1190
|
+
expiresAt: Date.now() + Math.min(3000, ctx.budgetMs),
|
|
1191
|
+
framePath,
|
|
1192
|
+
...(args.frameId ? { expectedFrameId: args.frameId } : {}),
|
|
1193
|
+
};
|
|
1194
|
+
const armed = await ctx.router.page(ctx, {
|
|
1195
|
+
...receiptInput,
|
|
1196
|
+
action: "arm",
|
|
1164
1197
|
});
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1198
|
+
requireValue(
|
|
1199
|
+
armed?.armed === true && typeof armed.documentToken === "string",
|
|
1200
|
+
"INVALID_TARGET",
|
|
1201
|
+
"The browser could not arm a receipt for the exact input document.",
|
|
1202
|
+
);
|
|
1203
|
+
const receipt = {
|
|
1204
|
+
...receiptInput,
|
|
1205
|
+
expectedDocumentToken: armed.documentToken,
|
|
1206
|
+
};
|
|
1207
|
+
try {
|
|
1174
1208
|
await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
|
|
1175
|
-
type: "
|
|
1209
|
+
type: "mouseMoved",
|
|
1176
1210
|
...p,
|
|
1177
|
-
button,
|
|
1178
|
-
clickCount: i,
|
|
1179
|
-
modifiers: modifierMask(args.modifiers ?? args.keypress),
|
|
1211
|
+
button: "none",
|
|
1180
1212
|
});
|
|
1213
|
+
for (let i = 1; i <= count; i++) {
|
|
1214
|
+
await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
|
|
1215
|
+
type: "mousePressed",
|
|
1216
|
+
...p,
|
|
1217
|
+
button,
|
|
1218
|
+
clickCount: i,
|
|
1219
|
+
modifiers: modifierMask(args.modifiers ?? args.keypress),
|
|
1220
|
+
});
|
|
1221
|
+
if (args.duration > 0) await ctx.router.delay(ctx, args.duration * 1000);
|
|
1222
|
+
await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
|
|
1223
|
+
type: "mouseReleased",
|
|
1224
|
+
...p,
|
|
1225
|
+
button,
|
|
1226
|
+
clickCount: i,
|
|
1227
|
+
modifiers: modifierMask(args.modifiers ?? args.keypress),
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
let observed = false;
|
|
1231
|
+
const expires = Math.min(
|
|
1232
|
+
performance.now() + 450,
|
|
1233
|
+
ctx.started + ctx.budgetMs,
|
|
1234
|
+
);
|
|
1235
|
+
while (performance.now() < expires) {
|
|
1236
|
+
if (
|
|
1237
|
+
!framePath.length &&
|
|
1238
|
+
ctx.router.version(ctx.target.tabId) !== originalVersion
|
|
1239
|
+
) {
|
|
1240
|
+
observed = true; // The main document navigated after input.
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
try {
|
|
1244
|
+
const result = await ctx.router.page(ctx, {
|
|
1245
|
+
...receipt,
|
|
1246
|
+
action: "peek",
|
|
1247
|
+
});
|
|
1248
|
+
if (result.observed >= count) {
|
|
1249
|
+
observed = true;
|
|
1250
|
+
break;
|
|
1251
|
+
}
|
|
1252
|
+
} catch {
|
|
1253
|
+
ctx.signal?.throwIfAborted();
|
|
1254
|
+
if (
|
|
1255
|
+
!framePath.length &&
|
|
1256
|
+
ctx.router.version(ctx.target.tabId) !== originalVersion
|
|
1257
|
+
) {
|
|
1258
|
+
observed = true;
|
|
1259
|
+
break;
|
|
1260
|
+
}
|
|
1261
|
+
// A detached or replaced frame does not prove the target received
|
|
1262
|
+
// input. The action may still have happened, so never replay it.
|
|
1263
|
+
break;
|
|
1264
|
+
}
|
|
1265
|
+
await ctx.router.delay(ctx, Math.min(40, expires - performance.now()));
|
|
1266
|
+
}
|
|
1267
|
+
if (!observed)
|
|
1268
|
+
throw new BrowserActionError(
|
|
1269
|
+
"INPUT_UNCONFIRMED",
|
|
1270
|
+
"Native pointer delivery returned, but the target document did not confirm the expected trusted click event.",
|
|
1271
|
+
{ dispatched: true, effect: "unknown" },
|
|
1272
|
+
);
|
|
1273
|
+
// Let the browser process the resulting task/render turn before the next
|
|
1274
|
+
// input, without misrepresenting arbitrary asynchronous business work.
|
|
1275
|
+
const remaining = ctx.budgetMs - (performance.now() - ctx.started);
|
|
1276
|
+
if (remaining > 120) await ctx.router.delay(ctx, 120);
|
|
1277
|
+
} finally {
|
|
1278
|
+
await ctx.router
|
|
1279
|
+
.page(ctx, { ...receipt, action: "drop" })
|
|
1280
|
+
.catch(() => {});
|
|
1181
1281
|
}
|
|
1182
1282
|
return null;
|
|
1183
1283
|
}
|
|
@@ -1335,22 +1435,105 @@ route(
|
|
|
1335
1435
|
{ needsTab: true, mutating: true },
|
|
1336
1436
|
);
|
|
1337
1437
|
async function resolveActionTarget(ctx, args) {
|
|
1338
|
-
let found;
|
|
1339
|
-
|
|
1340
|
-
//
|
|
1438
|
+
let found, previous;
|
|
1439
|
+
await readyForInput(ctx, args.locator?.framePath ?? args.framePath ?? []);
|
|
1440
|
+
// Two matching native observations give the layout a chance to settle
|
|
1441
|
+
// after scrolling. Only pre-input observations may repeat, never the click.
|
|
1341
1442
|
await ctx.router.poll(ctx, async () => {
|
|
1342
|
-
|
|
1443
|
+
const next = await ctx.router.page(ctx, {
|
|
1343
1444
|
...args,
|
|
1344
1445
|
...options(args),
|
|
1345
1446
|
command: "resolve",
|
|
1346
1447
|
});
|
|
1347
|
-
|
|
1448
|
+
if (!next) {
|
|
1449
|
+
previous = undefined;
|
|
1450
|
+
return false;
|
|
1451
|
+
}
|
|
1452
|
+
const stable =
|
|
1453
|
+
previous &&
|
|
1454
|
+
["x", "y"].every((key) =>
|
|
1455
|
+
Math.abs(previous.point[key] - next.point[key]) <= 1,
|
|
1456
|
+
) &&
|
|
1457
|
+
["x", "y", "width", "height"].every((key) =>
|
|
1458
|
+
Math.abs(previous.rect[key] - next.rect[key]) <= 1,
|
|
1459
|
+
) &&
|
|
1460
|
+
previous.documentToken === next.documentToken &&
|
|
1461
|
+
previous.frameId === next.frameId;
|
|
1462
|
+
previous = next;
|
|
1463
|
+
if (stable) found = next;
|
|
1464
|
+
return !!stable;
|
|
1348
1465
|
});
|
|
1349
1466
|
return found;
|
|
1350
1467
|
}
|
|
1351
1468
|
async function locatorClick(ctx, args, double = false) {
|
|
1352
1469
|
const found = await resolveActionTarget(ctx, args);
|
|
1353
|
-
|
|
1470
|
+
const input = options(args),
|
|
1471
|
+
expect = input.expect,
|
|
1472
|
+
framePath = args.locator?.framePath ?? args.framePath ?? [];
|
|
1473
|
+
// The native navigation event must be armed before input; top-level only.
|
|
1474
|
+
requireValue(
|
|
1475
|
+
!(expect?.kind === "navigation" && framePath.length),
|
|
1476
|
+
"INVALID_ARGUMENT",
|
|
1477
|
+
"For a nested frame, wait for its URL or a frame-local page condition.",
|
|
1478
|
+
);
|
|
1479
|
+
let navigation;
|
|
1480
|
+
if (expect?.kind === "navigation")
|
|
1481
|
+
navigation = await ctx.router.armWaiter(ctx, {
|
|
1482
|
+
event: "navigation",
|
|
1483
|
+
url: expect.url,
|
|
1484
|
+
waitUntil: expect.waitUntil ?? "load",
|
|
1485
|
+
timeoutMs:
|
|
1486
|
+
expect.timeoutMs ??
|
|
1487
|
+
Math.min(15000, ctx.budgetMs - (performance.now() - ctx.started)),
|
|
1488
|
+
});
|
|
1489
|
+
try {
|
|
1490
|
+
await click(
|
|
1491
|
+
ctx,
|
|
1492
|
+
{
|
|
1493
|
+
...input,
|
|
1494
|
+
...found.point,
|
|
1495
|
+
resolvedTarget: true,
|
|
1496
|
+
framePath,
|
|
1497
|
+
framePoint: found.framePoint,
|
|
1498
|
+
frameId: found.frameId,
|
|
1499
|
+
},
|
|
1500
|
+
double,
|
|
1501
|
+
);
|
|
1502
|
+
if (!expect) return null;
|
|
1503
|
+
try {
|
|
1504
|
+
if (navigation) {
|
|
1505
|
+
await ctx.router.getWaiter(ctx, navigation.id);
|
|
1506
|
+
return {
|
|
1507
|
+
matched: true,
|
|
1508
|
+
snapshot: {
|
|
1509
|
+
...ctx.router.target(ctx.target.tabId, ctx.lease),
|
|
1510
|
+
...(await ctx.router.page(ctx, { command: "snapshot" })),
|
|
1511
|
+
},
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
return await ctx.router.waitForCondition(ctx, {
|
|
1515
|
+
condition: expect,
|
|
1516
|
+
framePath,
|
|
1517
|
+
});
|
|
1518
|
+
} catch (cause) {
|
|
1519
|
+
ctx.signal?.throwIfAborted();
|
|
1520
|
+
if (
|
|
1521
|
+
cause instanceof BrowserActionError &&
|
|
1522
|
+
["TIMEOUT", "STALE_REF", "INVALID_TARGET", "WAITER_GONE"].includes(
|
|
1523
|
+
cause.code,
|
|
1524
|
+
)
|
|
1525
|
+
)
|
|
1526
|
+
throw new BrowserActionError(
|
|
1527
|
+
"EXPECTATION_UNCONFIRMED",
|
|
1528
|
+
"The page did not confirm the expected result. Input was already sent; observe before taking further action.",
|
|
1529
|
+
{ dispatched: true, effect: "unknown" },
|
|
1530
|
+
);
|
|
1531
|
+
throw cause;
|
|
1532
|
+
}
|
|
1533
|
+
} finally {
|
|
1534
|
+
if (navigation)
|
|
1535
|
+
await ctx.router.cancelWaiter(ctx, navigation.id).catch(() => {});
|
|
1536
|
+
}
|
|
1354
1537
|
}
|
|
1355
1538
|
route("locator.click", (ctx, args) => locatorClick(ctx, args), {
|
|
1356
1539
|
needsTab: true,
|
|
@@ -3454,9 +3637,14 @@ export function createBrowserRouter(
|
|
|
3454
3637
|
"tabs.closeTemporary",
|
|
3455
3638
|
"tab.getJsDialog",
|
|
3456
3639
|
].includes(input.method);
|
|
3640
|
+
// Native mutations can activate a tab and send shared browser input.
|
|
3641
|
+
// A per-tab queue cannot protect two simultaneous actions that switch
|
|
3642
|
+
// the active tab underneath one another. Reads and event waiters remain
|
|
3643
|
+
// independently schedulable.
|
|
3457
3644
|
const queueKey =
|
|
3458
|
-
|
|
3459
|
-
|
|
3645
|
+
definition.mutating && !nonBlocking
|
|
3646
|
+
? `native-mutation:${input.target.browserId}:${input.target.browserSessionId}`
|
|
3647
|
+
: input.target.tabId;
|
|
3460
3648
|
let task;
|
|
3461
3649
|
if (queueKey && !nonBlocking) {
|
|
3462
3650
|
task = (queues.get(queueKey) ?? Promise.resolve()).then(perform);
|
|
@@ -5018,6 +5206,9 @@ export function createBrowserRouter(
|
|
|
5018
5206
|
},
|
|
5019
5207
|
async screenshot(ctx, input) {
|
|
5020
5208
|
requireValue(!(input.fullPage && input.clip));
|
|
5209
|
+
await readyForInput(ctx);
|
|
5210
|
+
const readyBudget = ctx.budgetMs - (performance.now() - ctx.started);
|
|
5211
|
+
if (readyBudget > 130) await router.delay(ctx, 120);
|
|
5021
5212
|
const quality = input.quality ?? 80,
|
|
5022
5213
|
maxEdgePx = input.maxEdgePx ?? 1920;
|
|
5023
5214
|
requireValue(
|
|
@@ -38,12 +38,17 @@ export function createExtensionConnection({
|
|
|
38
38
|
"PROFILE_MISMATCH",
|
|
39
39
|
"Use a dedicated production or development extension build.",
|
|
40
40
|
);
|
|
41
|
-
const
|
|
41
|
+
const firstPort = profile === "production" ? 29040 : 29030;
|
|
42
|
+
const allowedUrls = Array.from(
|
|
43
|
+
{ length: 10 },
|
|
44
|
+
(_, index) => `ws://127.0.0.1:${firstPort + index}/nexum-browser/v1`,
|
|
45
|
+
);
|
|
42
46
|
requireValue(
|
|
43
|
-
url === undefined || url
|
|
47
|
+
url === undefined || allowedUrls.includes(url),
|
|
44
48
|
"PROFILE_MISMATCH",
|
|
45
|
-
"The extension cannot
|
|
49
|
+
"The extension cannot connect outside its profile's port range.",
|
|
46
50
|
);
|
|
51
|
+
const endpoints = url === undefined ? allowedUrls : [url];
|
|
47
52
|
let started = false,
|
|
48
53
|
stopped = false,
|
|
49
54
|
socket,
|
|
@@ -52,6 +57,10 @@ export function createExtensionConnection({
|
|
|
52
57
|
initialize,
|
|
53
58
|
reconnectTimer,
|
|
54
59
|
keepAlive,
|
|
60
|
+
probeTimer,
|
|
61
|
+
preferredUrl,
|
|
62
|
+
socketUrl,
|
|
63
|
+
scanIndex = 0,
|
|
55
64
|
reconnectAttempt = 0,
|
|
56
65
|
attemptSequence = 0,
|
|
57
66
|
lastMessage = 0,
|
|
@@ -296,8 +305,11 @@ export function createExtensionConnection({
|
|
|
296
305
|
};
|
|
297
306
|
const disconnected = async (expected) => {
|
|
298
307
|
if (expected !== socket) return;
|
|
308
|
+
const wasReady = Boolean(ready);
|
|
299
309
|
socket = undefined;
|
|
300
310
|
ready = undefined;
|
|
311
|
+
clearTimeout(probeTimer);
|
|
312
|
+
probeTimer = undefined;
|
|
301
313
|
clearInterval(keepAlive);
|
|
302
314
|
keepAlive = undefined;
|
|
303
315
|
status(false);
|
|
@@ -314,7 +326,17 @@ export function createExtensionConnection({
|
|
|
314
326
|
);
|
|
315
327
|
inbox.discard();
|
|
316
328
|
for (const lease of leases.values()) void closeLease(lease).catch(() => {});
|
|
317
|
-
if (!stopped)
|
|
329
|
+
if (!stopped) {
|
|
330
|
+
if (wasReady) {
|
|
331
|
+
scanIndex = 0;
|
|
332
|
+
schedule();
|
|
333
|
+
} else if (++scanIndex < endpoints.length) {
|
|
334
|
+
queueMicrotask(() => void connect().catch(schedule));
|
|
335
|
+
} else {
|
|
336
|
+
scanIndex = 0;
|
|
337
|
+
schedule();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
318
340
|
};
|
|
319
341
|
const schedule = () => {
|
|
320
342
|
if (stopped || reconnectTimer) return;
|
|
@@ -491,6 +513,10 @@ export function createExtensionConnection({
|
|
|
491
513
|
"The plugin and package use incompatible wire budgets.",
|
|
492
514
|
);
|
|
493
515
|
ready = Object.freeze(message);
|
|
516
|
+
preferredUrl = socketUrl;
|
|
517
|
+
scanIndex = 0;
|
|
518
|
+
clearTimeout(probeTimer);
|
|
519
|
+
probeTimer = undefined;
|
|
494
520
|
router.bind(message);
|
|
495
521
|
reconnectAttempt = 0;
|
|
496
522
|
status(true);
|
|
@@ -714,8 +740,16 @@ export function createExtensionConnection({
|
|
|
714
740
|
// Recheck after initialization. A socket, including one still closing,
|
|
715
741
|
// remains the current owner until its close handler starts cleanup.
|
|
716
742
|
if (stopped || socket) return;
|
|
717
|
-
const
|
|
743
|
+
const choices = preferredUrl
|
|
744
|
+
? [preferredUrl, ...endpoints.filter((candidate) => candidate !== preferredUrl)]
|
|
745
|
+
: endpoints;
|
|
746
|
+
socketUrl = choices[scanIndex];
|
|
747
|
+
const expected = new Socket(socketUrl);
|
|
718
748
|
socket = expected;
|
|
749
|
+
probeTimer = setTimeout(() => {
|
|
750
|
+
if (expected === socket && !ready && expected.readyState !== Socket.CLOSED)
|
|
751
|
+
expected.close();
|
|
752
|
+
}, 3000);
|
|
719
753
|
expected.binaryType = "arraybuffer";
|
|
720
754
|
expected.addEventListener("open", () => {
|
|
721
755
|
if (expected !== socket || stopped) {
|
|
@@ -757,6 +791,7 @@ export function createExtensionConnection({
|
|
|
757
791
|
});
|
|
758
792
|
});
|
|
759
793
|
expected.addEventListener("close", () => {
|
|
794
|
+
if (expected === socket) clearTimeout(probeTimer);
|
|
760
795
|
void disconnected(expected).catch(() => schedule());
|
|
761
796
|
});
|
|
762
797
|
expected.addEventListener("error", () => {
|
|
@@ -854,6 +889,7 @@ export function createExtensionConnection({
|
|
|
854
889
|
if (stopped) return;
|
|
855
890
|
stopped = true;
|
|
856
891
|
clearTimeout(reconnectTimer);
|
|
892
|
+
clearTimeout(probeTimer);
|
|
857
893
|
clearInterval(keepAlive);
|
|
858
894
|
for (const remove of listeners.splice(0)) remove();
|
|
859
895
|
for (const action of actions.values())
|
|
@@ -150,6 +150,14 @@ export async function framePage(ctx, payload, selectors, execute) {
|
|
|
150
150
|
ctx.router.noteFrameParent(ctx, node.node.frameId, frameId);
|
|
151
151
|
frameId = node.node.frameId;
|
|
152
152
|
}
|
|
153
|
+
// A frame may be replaced between hit-testing and arming the input
|
|
154
|
+
// receipt. Never transfer the receipt to a different frame by selector.
|
|
155
|
+
if (payload.expectedFrameId)
|
|
156
|
+
requireValue(
|
|
157
|
+
payload.expectedFrameId === frameId,
|
|
158
|
+
"STALE_REF",
|
|
159
|
+
"The input frame changed after its native target was observed.",
|
|
160
|
+
);
|
|
153
161
|
const input = {
|
|
154
162
|
...payload,
|
|
155
163
|
framePath: [],
|
|
@@ -179,6 +187,7 @@ export async function framePage(ctx, payload, selectors, execute) {
|
|
|
179
187
|
if (!result.ok)
|
|
180
188
|
throw new BrowserActionError(result.error.code, result.error.message);
|
|
181
189
|
if (input.command === "resolve" && result.value?.rect) {
|
|
190
|
+
const framePoint = { ...result.value.point };
|
|
182
191
|
// scrollIntoView in the resolved descendant can scroll every native ancestor.
|
|
183
192
|
// Coordinates read during traversal are no longer an observation of this input target.
|
|
184
193
|
for (const owner of owners) {
|
|
@@ -243,6 +252,8 @@ export async function framePage(ctx, payload, selectors, execute) {
|
|
|
243
252
|
}
|
|
244
253
|
result.value.point = point;
|
|
245
254
|
result.value.rect = mappedRect(result.value.rect, owners);
|
|
255
|
+
result.value.framePoint = framePoint;
|
|
256
|
+
result.value.frameId = frameId;
|
|
246
257
|
}
|
|
247
258
|
if (input.command === "elementInfo" && Array.isArray(result.value))
|
|
248
259
|
for (const entry of result.value)
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"https://*/*"
|
|
31
31
|
],
|
|
32
32
|
"content_security_policy": {
|
|
33
|
-
"extension_pages": "script-src 'self'; object-src 'self'; connect-src ws://127.0.0.1:
|
|
33
|
+
"extension_pages": "script-src 'self'; object-src 'self'; connect-src ws://127.0.0.1:29040 ws://127.0.0.1:29041 ws://127.0.0.1:29042 ws://127.0.0.1:29043 ws://127.0.0.1:29044 ws://127.0.0.1:29045 ws://127.0.0.1:29046 ws://127.0.0.1:29047 ws://127.0.0.1:29048 ws://127.0.0.1:29049;"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -18,6 +18,10 @@ export async function pageCommand(input) {
|
|
|
18
18
|
state.document !== document ||
|
|
19
19
|
state.version !== input.pageVersion
|
|
20
20
|
) {
|
|
21
|
+
for (const receipt of state?.clickReceipts?.values?.() ?? []) {
|
|
22
|
+
document.removeEventListener(receipt.type, receipt.listener, true);
|
|
23
|
+
clearTimeout(receipt.timer);
|
|
24
|
+
}
|
|
21
25
|
state = {
|
|
22
26
|
document,
|
|
23
27
|
version: input.pageVersion,
|
|
@@ -27,6 +31,7 @@ export async function pageCommand(input) {
|
|
|
27
31
|
next: 0,
|
|
28
32
|
refs: new Map(),
|
|
29
33
|
reverse: new WeakMap(),
|
|
34
|
+
clickReceipts: new Map(),
|
|
30
35
|
};
|
|
31
36
|
Object.defineProperty(globalThis, slot, {
|
|
32
37
|
value: state,
|
|
@@ -415,6 +420,71 @@ export async function pageCommand(input) {
|
|
|
415
420
|
};
|
|
416
421
|
let value;
|
|
417
422
|
switch (input.command) {
|
|
423
|
+
case "inputReceipt": {
|
|
424
|
+
check(
|
|
425
|
+
typeof input.token === "string" &&
|
|
426
|
+
input.token.length > 0 &&
|
|
427
|
+
input.token.length <= 128,
|
|
428
|
+
);
|
|
429
|
+
const receipts = (state.clickReceipts ??= new Map());
|
|
430
|
+
const release = (receipt) => {
|
|
431
|
+
if (!receipt) return;
|
|
432
|
+
document.removeEventListener(receipt.type, receipt.listener, true);
|
|
433
|
+
clearTimeout(receipt.timer);
|
|
434
|
+
receipts.delete(input.token);
|
|
435
|
+
};
|
|
436
|
+
if (input.action === "arm") {
|
|
437
|
+
check(!receipts.has(input.token) && receipts.size < 32, "QUEUE_FULL");
|
|
438
|
+
check(
|
|
439
|
+
Number.isFinite(input.x) &&
|
|
440
|
+
Number.isFinite(input.y) &&
|
|
441
|
+
[0, 1, 2].includes(input.button) &&
|
|
442
|
+
Number.isFinite(input.expiresAt) &&
|
|
443
|
+
input.expiresAt > Date.now(),
|
|
444
|
+
);
|
|
445
|
+
const type =
|
|
446
|
+
input.button === 2
|
|
447
|
+
? "contextmenu"
|
|
448
|
+
: input.button === 1
|
|
449
|
+
? "auxclick"
|
|
450
|
+
: "click";
|
|
451
|
+
const receipt = {
|
|
452
|
+
type,
|
|
453
|
+
count: 0,
|
|
454
|
+
expiresAt: input.expiresAt,
|
|
455
|
+
x: input.x,
|
|
456
|
+
y: input.y,
|
|
457
|
+
button: input.button,
|
|
458
|
+
};
|
|
459
|
+
receipt.listener = (event) => {
|
|
460
|
+
if (
|
|
461
|
+
event.isTrusted &&
|
|
462
|
+
event.button === input.button &&
|
|
463
|
+
Math.abs(event.clientX - input.x) <= 6 &&
|
|
464
|
+
Math.abs(event.clientY - input.y) <= 6
|
|
465
|
+
)
|
|
466
|
+
receipt.count++;
|
|
467
|
+
};
|
|
468
|
+
receipt.timer = setTimeout(
|
|
469
|
+
() => release(receipt),
|
|
470
|
+
Math.min(30000, input.expiresAt - Date.now()),
|
|
471
|
+
);
|
|
472
|
+
document.addEventListener(type, receipt.listener, true);
|
|
473
|
+
receipts.set(input.token, receipt);
|
|
474
|
+
value = { armed: true, documentToken: state.token };
|
|
475
|
+
} else if (input.action === "peek" || input.action === "drop") {
|
|
476
|
+
check(
|
|
477
|
+
!input.expectedDocumentToken ||
|
|
478
|
+
input.expectedDocumentToken === state.token,
|
|
479
|
+
"STALE_REF",
|
|
480
|
+
"The receipt belongs to a replaced document.",
|
|
481
|
+
);
|
|
482
|
+
const receipt = receipts.get(input.token);
|
|
483
|
+
value = { observed: receipt?.count ?? 0 };
|
|
484
|
+
if (input.action === "drop") release(receipt);
|
|
485
|
+
} else check(false);
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
418
488
|
// Core-only native bridge: the caller retains the actual remote Node(s), never serializes them.
|
|
419
489
|
case "nativeNodes":
|
|
420
490
|
return input.multiple ? all() : unique();
|
|
@@ -610,14 +680,27 @@ export async function pageCommand(input) {
|
|
|
610
680
|
const node = unique(false, true),
|
|
611
681
|
geometry = node && actionGeometry(node, true);
|
|
612
682
|
value = geometry
|
|
613
|
-
? {
|
|
683
|
+
? {
|
|
684
|
+
...describe(node),
|
|
685
|
+
...geometry,
|
|
686
|
+
tagName: node.tagName,
|
|
687
|
+
documentToken: state.token,
|
|
688
|
+
}
|
|
614
689
|
: null;
|
|
615
690
|
break;
|
|
616
691
|
}
|
|
617
|
-
case "fill":
|
|
618
|
-
|
|
692
|
+
case "fill": {
|
|
693
|
+
const node = unique(true),
|
|
694
|
+
expected = input.value ?? input.text;
|
|
695
|
+
setValue(node, expected);
|
|
696
|
+
check(
|
|
697
|
+
(node.isContentEditable ? node.textContent : node.value) === expected,
|
|
698
|
+
"INVALID_TARGET",
|
|
699
|
+
"The input did not retain the requested value.",
|
|
700
|
+
);
|
|
619
701
|
value = null;
|
|
620
702
|
break;
|
|
703
|
+
}
|
|
621
704
|
case "focus":
|
|
622
705
|
unique(true).focus();
|
|
623
706
|
value = null;
|
|
@@ -652,6 +735,13 @@ export async function pageCommand(input) {
|
|
|
652
735
|
node.dispatchEvent(new Event("input", { bubbles: true }));
|
|
653
736
|
node.dispatchEvent(new Event("change", { bubbles: true }));
|
|
654
737
|
value = matches.map((o) => o.value);
|
|
738
|
+
const actual = [...node.selectedOptions].map((o) => o.value);
|
|
739
|
+
check(
|
|
740
|
+
actual.length === value.length &&
|
|
741
|
+
actual.every((item) => value.includes(item)),
|
|
742
|
+
"INVALID_TARGET",
|
|
743
|
+
"The select did not retain the requested option values.",
|
|
744
|
+
);
|
|
655
745
|
break;
|
|
656
746
|
}
|
|
657
747
|
case "checked": {
|