@nexum-hub/browser 0.0.3-next.17 → 0.0.3-next.18

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.
@@ -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)
@@ -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
- ? { ...describe(node), ...geometry, tagName: node.tagName }
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
- setValue(unique(true), input.value ?? input.text);
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": {
@@ -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
- await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
1161
- type: "mouseMoved",
1162
- ...p,
1163
- button: "none",
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
- for (let i = 1; i <= count; i++) {
1166
- await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
1167
- type: "mousePressed",
1168
- ...p,
1169
- button,
1170
- clickCount: i,
1171
- modifiers: modifierMask(args.modifiers ?? args.keypress),
1172
- });
1173
- if (args.duration > 0) await ctx.router.delay(ctx, args.duration * 1000);
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: "mouseReleased",
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
- // Only repeat the pre-input observation. Native pointer dispatch happens once
1340
- // after an unobstructed current target is observed, never after a failed action.
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
- found = await ctx.router.page(ctx, {
1443
+ const next = await ctx.router.page(ctx, {
1343
1444
  ...args,
1344
1445
  ...options(args),
1345
1446
  command: "resolve",
1346
1447
  });
1347
- return found !== null;
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
- return click(ctx, { ...options(args), ...found.point }, double);
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
- input.target.tabId ??
3459
- (definition.mutating ? "browser-management" : undefined);
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(
@@ -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)
@@ -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
- ? { ...describe(node), ...geometry, tagName: node.tagName }
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
- setValue(unique(true), input.value ?? input.text);
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": {