@nexum-hub/browser 0.0.3-next.20 → 0.0.3-next.22
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/dist/development/page.js +22 -5
- package/browser-extension/dist/development/router.js +111 -44
- package/browser-extension/dist/production/page.js +22 -5
- package/browser-extension/dist/production/router.js +111 -44
- package/browser-extension/page.js +22 -5
- package/browser-extension/release-info.json +1 -1
- package/browser-extension/router.js +111 -44
- package/dist/extension/scope.d.ts +3 -1
- package/dist/extension/scope.js +19 -3
- package/implementation.json +1 -1
- package/package.json +4 -3
- package/dist/client/index.js.map +0 -1
- package/dist/client/routes.js.map +0 -1
- package/dist/client/serialize.js.map +0 -1
- package/dist/client/types.js.map +0 -1
- package/dist/extension/artifacts.js.map +0 -1
- package/dist/extension/assets.js.map +0 -1
- package/dist/extension/batch.js.map +0 -1
- package/dist/extension/files.js.map +0 -1
- package/dist/extension/index.js.map +0 -1
- package/dist/extension/protocol.js.map +0 -1
- package/dist/extension/scope.js.map +0 -1
- package/dist/extension/service.js.map +0 -1
|
@@ -347,11 +347,15 @@ export async function pageCommand(input) {
|
|
|
347
347
|
"INVALID_TARGET",
|
|
348
348
|
"The current element is not visible and enabled.",
|
|
349
349
|
);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
350
|
+
// The first preflight scrolls the target into view. Later checks must
|
|
351
|
+
// observe the compositor's settled position without requesting another
|
|
352
|
+
// scroll that can move the target after coordinates were captured.
|
|
353
|
+
if (!input.noScroll)
|
|
354
|
+
node.scrollIntoView({
|
|
355
|
+
block: "center",
|
|
356
|
+
inline: "center",
|
|
357
|
+
behavior: "instant",
|
|
358
|
+
});
|
|
355
359
|
const r = rect(node),
|
|
356
360
|
position = input.command === "resolve" ? input.position : undefined;
|
|
357
361
|
const x = position?.x ?? r.width / 2,
|
|
@@ -448,6 +452,16 @@ export async function pageCommand(input) {
|
|
|
448
452
|
: input.button === 1
|
|
449
453
|
? "auxclick"
|
|
450
454
|
: "click";
|
|
455
|
+
const expected = input.expectedRef
|
|
456
|
+
? getRef(input.expectedRef)
|
|
457
|
+
: null;
|
|
458
|
+
if (expected) {
|
|
459
|
+
const hit = document.elementFromPoint(input.x, input.y);
|
|
460
|
+
if (hit !== expected && !expected.contains(hit)) {
|
|
461
|
+
value = { armed: false, documentToken: state.token };
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
451
465
|
const receipt = {
|
|
452
466
|
type,
|
|
453
467
|
count: 0,
|
|
@@ -455,11 +469,14 @@ export async function pageCommand(input) {
|
|
|
455
469
|
x: input.x,
|
|
456
470
|
y: input.y,
|
|
457
471
|
button: input.button,
|
|
472
|
+
expected,
|
|
458
473
|
};
|
|
459
474
|
receipt.listener = (event) => {
|
|
460
475
|
if (
|
|
461
476
|
event.isTrusted &&
|
|
462
477
|
event.button === input.button &&
|
|
478
|
+
(!receipt.expected ||
|
|
479
|
+
event.composedPath().includes(receipt.expected)) &&
|
|
463
480
|
Math.abs(event.clientX - input.x) <= 6 &&
|
|
464
481
|
Math.abs(event.clientY - input.y) <= 6
|
|
465
482
|
)
|
|
@@ -1150,12 +1150,12 @@ async function readyForInput(ctx, framePath = []) {
|
|
|
1150
1150
|
|
|
1151
1151
|
// Build the points for real Chrome Input.dispatchMouseEvent calls, not a
|
|
1152
1152
|
// decorative animation that runs independently of the actual input.
|
|
1153
|
-
export function humanPointerPath(from, to) {
|
|
1153
|
+
export function humanPointerPath(from, to, maxSteps = 28) {
|
|
1154
1154
|
const dx = to.x - from.x,
|
|
1155
1155
|
dy = to.y - from.y,
|
|
1156
1156
|
distance = Math.hypot(dx, dy);
|
|
1157
1157
|
if (distance < 12) return [{ x: to.x, y: to.y, delayMs: 0 }];
|
|
1158
|
-
const steps = Math.min(
|
|
1158
|
+
const steps = Math.min(maxSteps, Math.max(3, Math.ceil(distance / 28))),
|
|
1159
1159
|
durationMs = Math.min(420, Math.max(110, 85 + distance * 0.35)),
|
|
1160
1160
|
bend = Math.min(18, distance * 0.08) *
|
|
1161
1161
|
(Math.sin(from.x * 0.013 + to.y * 0.017) < 0 ? -1 : 1);
|
|
@@ -1174,42 +1174,85 @@ export function humanPointerPath(from, to) {
|
|
|
1174
1174
|
}
|
|
1175
1175
|
async function click(ctx, args, double = false) {
|
|
1176
1176
|
if (!args.resolvedTarget) await readyForInput(ctx);
|
|
1177
|
-
|
|
1178
|
-
|
|
1177
|
+
let p = await point(ctx, args);
|
|
1178
|
+
const button = buttons[args.button ?? "left"];
|
|
1179
1179
|
requireValue(button);
|
|
1180
1180
|
const count = double ? 2 : (args.clickCount ?? 1);
|
|
1181
1181
|
requireValue(Number.isInteger(count) && count >= 1 && count <= 3);
|
|
1182
1182
|
const framePath = args.framePath ?? [];
|
|
1183
1183
|
const originalVersion = ctx.router.version(ctx.target.tabId);
|
|
1184
|
-
|
|
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",
|
|
1197
|
-
});
|
|
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
|
-
};
|
|
1184
|
+
let receipt;
|
|
1207
1185
|
try {
|
|
1208
1186
|
await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
|
|
1209
1187
|
type: "mouseMoved",
|
|
1210
1188
|
...p,
|
|
1211
1189
|
button: "none",
|
|
1212
1190
|
});
|
|
1191
|
+
let framePoint = args.framePoint;
|
|
1192
|
+
if (args.expectedRef) {
|
|
1193
|
+
// The first native pointer movement can cause Chromium's visible
|
|
1194
|
+
// viewport to change. Re-observe the same element after that movement,
|
|
1195
|
+
// before the first mouse press; no click is ever replayed.
|
|
1196
|
+
let stable = false;
|
|
1197
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
1198
|
+
const current = await ctx.router.page(ctx, {
|
|
1199
|
+
command: "resolve",
|
|
1200
|
+
ref: args.expectedRef,
|
|
1201
|
+
framePath,
|
|
1202
|
+
noScroll: true,
|
|
1203
|
+
...(args.position ? { position: args.position } : {}),
|
|
1204
|
+
});
|
|
1205
|
+
requireValue(
|
|
1206
|
+
current && (!args.frameId || current.frameId === args.frameId),
|
|
1207
|
+
"INVALID_TARGET",
|
|
1208
|
+
"The original click element is no longer at a controllable point.",
|
|
1209
|
+
);
|
|
1210
|
+
if (
|
|
1211
|
+
Math.abs(current.point.x - p.x) <= 1 &&
|
|
1212
|
+
Math.abs(current.point.y - p.y) <= 1
|
|
1213
|
+
) {
|
|
1214
|
+
framePoint = current.framePoint ?? framePoint;
|
|
1215
|
+
stable = true;
|
|
1216
|
+
break;
|
|
1217
|
+
}
|
|
1218
|
+
p = current.point;
|
|
1219
|
+
framePoint = current.framePoint ?? framePoint;
|
|
1220
|
+
await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
|
|
1221
|
+
type: "mouseMoved",
|
|
1222
|
+
...p,
|
|
1223
|
+
button: "none",
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
requireValue(
|
|
1227
|
+
stable,
|
|
1228
|
+
"INVALID_TARGET",
|
|
1229
|
+
"The click target continued moving after native pointer preparation.",
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
const receiptInput = {
|
|
1233
|
+
command: "inputReceipt",
|
|
1234
|
+
token: ctx.actionId,
|
|
1235
|
+
x: framePoint?.x ?? p.x,
|
|
1236
|
+
y: framePoint?.y ?? p.y,
|
|
1237
|
+
button: { left: 0, middle: 1, right: 2 }[args.button ?? "left"],
|
|
1238
|
+
expiresAt: Date.now() + Math.min(3000, ctx.budgetMs),
|
|
1239
|
+
framePath,
|
|
1240
|
+
...(args.frameId ? { expectedFrameId: args.frameId } : {}),
|
|
1241
|
+
...(args.expectedRef ? { expectedRef: args.expectedRef } : {}),
|
|
1242
|
+
};
|
|
1243
|
+
const armed = await ctx.router.page(ctx, {
|
|
1244
|
+
...receiptInput,
|
|
1245
|
+
action: "arm",
|
|
1246
|
+
});
|
|
1247
|
+
requireValue(
|
|
1248
|
+
armed?.armed === true && typeof armed.documentToken === "string",
|
|
1249
|
+
"INVALID_TARGET",
|
|
1250
|
+
"The browser could not arm a receipt for the exact input document.",
|
|
1251
|
+
);
|
|
1252
|
+
receipt = {
|
|
1253
|
+
...receiptInput,
|
|
1254
|
+
expectedDocumentToken: armed.documentToken,
|
|
1255
|
+
};
|
|
1213
1256
|
for (let i = 1; i <= count; i++) {
|
|
1214
1257
|
await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
|
|
1215
1258
|
type: "mousePressed",
|
|
@@ -1275,9 +1318,10 @@ async function click(ctx, args, double = false) {
|
|
|
1275
1318
|
const remaining = ctx.budgetMs - (performance.now() - ctx.started);
|
|
1276
1319
|
if (remaining > 120) await ctx.router.delay(ctx, 120);
|
|
1277
1320
|
} finally {
|
|
1278
|
-
|
|
1279
|
-
.
|
|
1280
|
-
|
|
1321
|
+
if (receipt)
|
|
1322
|
+
await ctx.router
|
|
1323
|
+
.page(ctx, { ...receipt, action: "drop" })
|
|
1324
|
+
.catch(() => {});
|
|
1281
1325
|
}
|
|
1282
1326
|
return null;
|
|
1283
1327
|
}
|
|
@@ -1436,7 +1480,24 @@ route(
|
|
|
1436
1480
|
);
|
|
1437
1481
|
async function resolveActionTarget(ctx, args) {
|
|
1438
1482
|
let found, previous;
|
|
1483
|
+
let scrollRequested = false;
|
|
1484
|
+
// Chromium can change the page viewport when its native debugger attaches
|
|
1485
|
+
// (notably by adding a debugging infobar). Attach before measuring or
|
|
1486
|
+
// scrolling the target; attaching only on the first mouse event can shift
|
|
1487
|
+
// the page after preflight and send a trusted click to the wrong element.
|
|
1488
|
+
await ctx.router.attach(ctx);
|
|
1439
1489
|
await readyForInput(ctx, args.locator?.framePath ?? args.framePath ?? []);
|
|
1490
|
+
const sameLayout = (left, right) =>
|
|
1491
|
+
left && right &&
|
|
1492
|
+
["x", "y"].every((key) =>
|
|
1493
|
+
Math.abs(left.point[key] - right.point[key]) <= 1,
|
|
1494
|
+
) &&
|
|
1495
|
+
["x", "y", "width", "height"].every((key) =>
|
|
1496
|
+
Math.abs(left.rect[key] - right.rect[key]) <= 1,
|
|
1497
|
+
) &&
|
|
1498
|
+
left.ref === right.ref &&
|
|
1499
|
+
left.documentToken === right.documentToken &&
|
|
1500
|
+
left.frameId === right.frameId;
|
|
1440
1501
|
// Two matching native observations give the layout a chance to settle
|
|
1441
1502
|
// after scrolling. Only pre-input observations may repeat, never the click.
|
|
1442
1503
|
await ctx.router.poll(ctx, async () => {
|
|
@@ -1444,24 +1505,23 @@ async function resolveActionTarget(ctx, args) {
|
|
|
1444
1505
|
...args,
|
|
1445
1506
|
...options(args),
|
|
1446
1507
|
command: "resolve",
|
|
1508
|
+
...(scrollRequested ? { noScroll: true } : {}),
|
|
1447
1509
|
});
|
|
1448
1510
|
if (!next) {
|
|
1449
1511
|
previous = undefined;
|
|
1450
1512
|
return false;
|
|
1451
1513
|
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
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;
|
|
1514
|
+
// A missing target did not establish a usable scroll position. If it
|
|
1515
|
+
// appears later below the viewport, its first observation must still be
|
|
1516
|
+
// allowed to scroll it into view.
|
|
1517
|
+
scrollRequested = true;
|
|
1518
|
+
const stable = sameLayout(previous, next);
|
|
1462
1519
|
previous = next;
|
|
1463
|
-
if (stable)
|
|
1464
|
-
|
|
1520
|
+
if (!stable) return false;
|
|
1521
|
+
// Native mouse movement later re-resolves this exact ref before pressing,
|
|
1522
|
+
// so another pre-move snapshot cannot prove that the final point is safe.
|
|
1523
|
+
found = next;
|
|
1524
|
+
return true;
|
|
1465
1525
|
});
|
|
1466
1526
|
return found;
|
|
1467
1527
|
}
|
|
@@ -1496,6 +1556,7 @@ async function locatorClick(ctx, args, double = false) {
|
|
|
1496
1556
|
framePath,
|
|
1497
1557
|
framePoint: found.framePoint,
|
|
1498
1558
|
frameId: found.frameId,
|
|
1559
|
+
expectedRef: found.ref,
|
|
1499
1560
|
},
|
|
1500
1561
|
double,
|
|
1501
1562
|
);
|
|
@@ -4183,8 +4244,14 @@ export function createBrowserRouter(
|
|
|
4183
4244
|
Number.isFinite(params.y)
|
|
4184
4245
|
) {
|
|
4185
4246
|
const tabId = nativeId(ctx.target.tabId),
|
|
4186
|
-
previous = pointerPositions.get(tabId) ?? { x: 32, y: 72 }
|
|
4187
|
-
|
|
4247
|
+
previous = pointerPositions.get(tabId) ?? { x: 32, y: 72 };
|
|
4248
|
+
// Chromium can heavily throttle input acknowledgement in an inactive
|
|
4249
|
+
// tab. Keep a real multi-point native trajectory, but bound its steps
|
|
4250
|
+
// so one background move cannot outlive the original SDK request.
|
|
4251
|
+
const tab = await chrome.tabs.get(tabId);
|
|
4252
|
+
const clickMove = /(^|\.)(click|dblclick|doubleClick)$/.test(ctx.method);
|
|
4253
|
+
const maxSteps = tab.active ? 28 : clickMove ? 2 : 3;
|
|
4254
|
+
const path = humanPointerPath(previous, { x: params.x, y: params.y }, maxSteps);
|
|
4188
4255
|
let result;
|
|
4189
4256
|
for (const step of path) {
|
|
4190
4257
|
result = await router.send(
|
|
@@ -347,11 +347,15 @@ export async function pageCommand(input) {
|
|
|
347
347
|
"INVALID_TARGET",
|
|
348
348
|
"The current element is not visible and enabled.",
|
|
349
349
|
);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
350
|
+
// The first preflight scrolls the target into view. Later checks must
|
|
351
|
+
// observe the compositor's settled position without requesting another
|
|
352
|
+
// scroll that can move the target after coordinates were captured.
|
|
353
|
+
if (!input.noScroll)
|
|
354
|
+
node.scrollIntoView({
|
|
355
|
+
block: "center",
|
|
356
|
+
inline: "center",
|
|
357
|
+
behavior: "instant",
|
|
358
|
+
});
|
|
355
359
|
const r = rect(node),
|
|
356
360
|
position = input.command === "resolve" ? input.position : undefined;
|
|
357
361
|
const x = position?.x ?? r.width / 2,
|
|
@@ -448,6 +452,16 @@ export async function pageCommand(input) {
|
|
|
448
452
|
: input.button === 1
|
|
449
453
|
? "auxclick"
|
|
450
454
|
: "click";
|
|
455
|
+
const expected = input.expectedRef
|
|
456
|
+
? getRef(input.expectedRef)
|
|
457
|
+
: null;
|
|
458
|
+
if (expected) {
|
|
459
|
+
const hit = document.elementFromPoint(input.x, input.y);
|
|
460
|
+
if (hit !== expected && !expected.contains(hit)) {
|
|
461
|
+
value = { armed: false, documentToken: state.token };
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
451
465
|
const receipt = {
|
|
452
466
|
type,
|
|
453
467
|
count: 0,
|
|
@@ -455,11 +469,14 @@ export async function pageCommand(input) {
|
|
|
455
469
|
x: input.x,
|
|
456
470
|
y: input.y,
|
|
457
471
|
button: input.button,
|
|
472
|
+
expected,
|
|
458
473
|
};
|
|
459
474
|
receipt.listener = (event) => {
|
|
460
475
|
if (
|
|
461
476
|
event.isTrusted &&
|
|
462
477
|
event.button === input.button &&
|
|
478
|
+
(!receipt.expected ||
|
|
479
|
+
event.composedPath().includes(receipt.expected)) &&
|
|
463
480
|
Math.abs(event.clientX - input.x) <= 6 &&
|
|
464
481
|
Math.abs(event.clientY - input.y) <= 6
|
|
465
482
|
)
|
|
@@ -1150,12 +1150,12 @@ async function readyForInput(ctx, framePath = []) {
|
|
|
1150
1150
|
|
|
1151
1151
|
// Build the points for real Chrome Input.dispatchMouseEvent calls, not a
|
|
1152
1152
|
// decorative animation that runs independently of the actual input.
|
|
1153
|
-
export function humanPointerPath(from, to) {
|
|
1153
|
+
export function humanPointerPath(from, to, maxSteps = 28) {
|
|
1154
1154
|
const dx = to.x - from.x,
|
|
1155
1155
|
dy = to.y - from.y,
|
|
1156
1156
|
distance = Math.hypot(dx, dy);
|
|
1157
1157
|
if (distance < 12) return [{ x: to.x, y: to.y, delayMs: 0 }];
|
|
1158
|
-
const steps = Math.min(
|
|
1158
|
+
const steps = Math.min(maxSteps, Math.max(3, Math.ceil(distance / 28))),
|
|
1159
1159
|
durationMs = Math.min(420, Math.max(110, 85 + distance * 0.35)),
|
|
1160
1160
|
bend = Math.min(18, distance * 0.08) *
|
|
1161
1161
|
(Math.sin(from.x * 0.013 + to.y * 0.017) < 0 ? -1 : 1);
|
|
@@ -1174,42 +1174,85 @@ export function humanPointerPath(from, to) {
|
|
|
1174
1174
|
}
|
|
1175
1175
|
async function click(ctx, args, double = false) {
|
|
1176
1176
|
if (!args.resolvedTarget) await readyForInput(ctx);
|
|
1177
|
-
|
|
1178
|
-
|
|
1177
|
+
let p = await point(ctx, args);
|
|
1178
|
+
const button = buttons[args.button ?? "left"];
|
|
1179
1179
|
requireValue(button);
|
|
1180
1180
|
const count = double ? 2 : (args.clickCount ?? 1);
|
|
1181
1181
|
requireValue(Number.isInteger(count) && count >= 1 && count <= 3);
|
|
1182
1182
|
const framePath = args.framePath ?? [];
|
|
1183
1183
|
const originalVersion = ctx.router.version(ctx.target.tabId);
|
|
1184
|
-
|
|
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",
|
|
1197
|
-
});
|
|
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
|
-
};
|
|
1184
|
+
let receipt;
|
|
1207
1185
|
try {
|
|
1208
1186
|
await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
|
|
1209
1187
|
type: "mouseMoved",
|
|
1210
1188
|
...p,
|
|
1211
1189
|
button: "none",
|
|
1212
1190
|
});
|
|
1191
|
+
let framePoint = args.framePoint;
|
|
1192
|
+
if (args.expectedRef) {
|
|
1193
|
+
// The first native pointer movement can cause Chromium's visible
|
|
1194
|
+
// viewport to change. Re-observe the same element after that movement,
|
|
1195
|
+
// before the first mouse press; no click is ever replayed.
|
|
1196
|
+
let stable = false;
|
|
1197
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
1198
|
+
const current = await ctx.router.page(ctx, {
|
|
1199
|
+
command: "resolve",
|
|
1200
|
+
ref: args.expectedRef,
|
|
1201
|
+
framePath,
|
|
1202
|
+
noScroll: true,
|
|
1203
|
+
...(args.position ? { position: args.position } : {}),
|
|
1204
|
+
});
|
|
1205
|
+
requireValue(
|
|
1206
|
+
current && (!args.frameId || current.frameId === args.frameId),
|
|
1207
|
+
"INVALID_TARGET",
|
|
1208
|
+
"The original click element is no longer at a controllable point.",
|
|
1209
|
+
);
|
|
1210
|
+
if (
|
|
1211
|
+
Math.abs(current.point.x - p.x) <= 1 &&
|
|
1212
|
+
Math.abs(current.point.y - p.y) <= 1
|
|
1213
|
+
) {
|
|
1214
|
+
framePoint = current.framePoint ?? framePoint;
|
|
1215
|
+
stable = true;
|
|
1216
|
+
break;
|
|
1217
|
+
}
|
|
1218
|
+
p = current.point;
|
|
1219
|
+
framePoint = current.framePoint ?? framePoint;
|
|
1220
|
+
await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
|
|
1221
|
+
type: "mouseMoved",
|
|
1222
|
+
...p,
|
|
1223
|
+
button: "none",
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
requireValue(
|
|
1227
|
+
stable,
|
|
1228
|
+
"INVALID_TARGET",
|
|
1229
|
+
"The click target continued moving after native pointer preparation.",
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
const receiptInput = {
|
|
1233
|
+
command: "inputReceipt",
|
|
1234
|
+
token: ctx.actionId,
|
|
1235
|
+
x: framePoint?.x ?? p.x,
|
|
1236
|
+
y: framePoint?.y ?? p.y,
|
|
1237
|
+
button: { left: 0, middle: 1, right: 2 }[args.button ?? "left"],
|
|
1238
|
+
expiresAt: Date.now() + Math.min(3000, ctx.budgetMs),
|
|
1239
|
+
framePath,
|
|
1240
|
+
...(args.frameId ? { expectedFrameId: args.frameId } : {}),
|
|
1241
|
+
...(args.expectedRef ? { expectedRef: args.expectedRef } : {}),
|
|
1242
|
+
};
|
|
1243
|
+
const armed = await ctx.router.page(ctx, {
|
|
1244
|
+
...receiptInput,
|
|
1245
|
+
action: "arm",
|
|
1246
|
+
});
|
|
1247
|
+
requireValue(
|
|
1248
|
+
armed?.armed === true && typeof armed.documentToken === "string",
|
|
1249
|
+
"INVALID_TARGET",
|
|
1250
|
+
"The browser could not arm a receipt for the exact input document.",
|
|
1251
|
+
);
|
|
1252
|
+
receipt = {
|
|
1253
|
+
...receiptInput,
|
|
1254
|
+
expectedDocumentToken: armed.documentToken,
|
|
1255
|
+
};
|
|
1213
1256
|
for (let i = 1; i <= count; i++) {
|
|
1214
1257
|
await ctx.router.send(ctx, "Input.dispatchMouseEvent", {
|
|
1215
1258
|
type: "mousePressed",
|
|
@@ -1275,9 +1318,10 @@ async function click(ctx, args, double = false) {
|
|
|
1275
1318
|
const remaining = ctx.budgetMs - (performance.now() - ctx.started);
|
|
1276
1319
|
if (remaining > 120) await ctx.router.delay(ctx, 120);
|
|
1277
1320
|
} finally {
|
|
1278
|
-
|
|
1279
|
-
.
|
|
1280
|
-
|
|
1321
|
+
if (receipt)
|
|
1322
|
+
await ctx.router
|
|
1323
|
+
.page(ctx, { ...receipt, action: "drop" })
|
|
1324
|
+
.catch(() => {});
|
|
1281
1325
|
}
|
|
1282
1326
|
return null;
|
|
1283
1327
|
}
|
|
@@ -1436,7 +1480,24 @@ route(
|
|
|
1436
1480
|
);
|
|
1437
1481
|
async function resolveActionTarget(ctx, args) {
|
|
1438
1482
|
let found, previous;
|
|
1483
|
+
let scrollRequested = false;
|
|
1484
|
+
// Chromium can change the page viewport when its native debugger attaches
|
|
1485
|
+
// (notably by adding a debugging infobar). Attach before measuring or
|
|
1486
|
+
// scrolling the target; attaching only on the first mouse event can shift
|
|
1487
|
+
// the page after preflight and send a trusted click to the wrong element.
|
|
1488
|
+
await ctx.router.attach(ctx);
|
|
1439
1489
|
await readyForInput(ctx, args.locator?.framePath ?? args.framePath ?? []);
|
|
1490
|
+
const sameLayout = (left, right) =>
|
|
1491
|
+
left && right &&
|
|
1492
|
+
["x", "y"].every((key) =>
|
|
1493
|
+
Math.abs(left.point[key] - right.point[key]) <= 1,
|
|
1494
|
+
) &&
|
|
1495
|
+
["x", "y", "width", "height"].every((key) =>
|
|
1496
|
+
Math.abs(left.rect[key] - right.rect[key]) <= 1,
|
|
1497
|
+
) &&
|
|
1498
|
+
left.ref === right.ref &&
|
|
1499
|
+
left.documentToken === right.documentToken &&
|
|
1500
|
+
left.frameId === right.frameId;
|
|
1440
1501
|
// Two matching native observations give the layout a chance to settle
|
|
1441
1502
|
// after scrolling. Only pre-input observations may repeat, never the click.
|
|
1442
1503
|
await ctx.router.poll(ctx, async () => {
|
|
@@ -1444,24 +1505,23 @@ async function resolveActionTarget(ctx, args) {
|
|
|
1444
1505
|
...args,
|
|
1445
1506
|
...options(args),
|
|
1446
1507
|
command: "resolve",
|
|
1508
|
+
...(scrollRequested ? { noScroll: true } : {}),
|
|
1447
1509
|
});
|
|
1448
1510
|
if (!next) {
|
|
1449
1511
|
previous = undefined;
|
|
1450
1512
|
return false;
|
|
1451
1513
|
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
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;
|
|
1514
|
+
// A missing target did not establish a usable scroll position. If it
|
|
1515
|
+
// appears later below the viewport, its first observation must still be
|
|
1516
|
+
// allowed to scroll it into view.
|
|
1517
|
+
scrollRequested = true;
|
|
1518
|
+
const stable = sameLayout(previous, next);
|
|
1462
1519
|
previous = next;
|
|
1463
|
-
if (stable)
|
|
1464
|
-
|
|
1520
|
+
if (!stable) return false;
|
|
1521
|
+
// Native mouse movement later re-resolves this exact ref before pressing,
|
|
1522
|
+
// so another pre-move snapshot cannot prove that the final point is safe.
|
|
1523
|
+
found = next;
|
|
1524
|
+
return true;
|
|
1465
1525
|
});
|
|
1466
1526
|
return found;
|
|
1467
1527
|
}
|
|
@@ -1496,6 +1556,7 @@ async function locatorClick(ctx, args, double = false) {
|
|
|
1496
1556
|
framePath,
|
|
1497
1557
|
framePoint: found.framePoint,
|
|
1498
1558
|
frameId: found.frameId,
|
|
1559
|
+
expectedRef: found.ref,
|
|
1499
1560
|
},
|
|
1500
1561
|
double,
|
|
1501
1562
|
);
|
|
@@ -4183,8 +4244,14 @@ export function createBrowserRouter(
|
|
|
4183
4244
|
Number.isFinite(params.y)
|
|
4184
4245
|
) {
|
|
4185
4246
|
const tabId = nativeId(ctx.target.tabId),
|
|
4186
|
-
previous = pointerPositions.get(tabId) ?? { x: 32, y: 72 }
|
|
4187
|
-
|
|
4247
|
+
previous = pointerPositions.get(tabId) ?? { x: 32, y: 72 };
|
|
4248
|
+
// Chromium can heavily throttle input acknowledgement in an inactive
|
|
4249
|
+
// tab. Keep a real multi-point native trajectory, but bound its steps
|
|
4250
|
+
// so one background move cannot outlive the original SDK request.
|
|
4251
|
+
const tab = await chrome.tabs.get(tabId);
|
|
4252
|
+
const clickMove = /(^|\.)(click|dblclick|doubleClick)$/.test(ctx.method);
|
|
4253
|
+
const maxSteps = tab.active ? 28 : clickMove ? 2 : 3;
|
|
4254
|
+
const path = humanPointerPath(previous, { x: params.x, y: params.y }, maxSteps);
|
|
4188
4255
|
let result;
|
|
4189
4256
|
for (const step of path) {
|
|
4190
4257
|
result = await router.send(
|
|
@@ -347,11 +347,15 @@ export async function pageCommand(input) {
|
|
|
347
347
|
"INVALID_TARGET",
|
|
348
348
|
"The current element is not visible and enabled.",
|
|
349
349
|
);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
350
|
+
// The first preflight scrolls the target into view. Later checks must
|
|
351
|
+
// observe the compositor's settled position without requesting another
|
|
352
|
+
// scroll that can move the target after coordinates were captured.
|
|
353
|
+
if (!input.noScroll)
|
|
354
|
+
node.scrollIntoView({
|
|
355
|
+
block: "center",
|
|
356
|
+
inline: "center",
|
|
357
|
+
behavior: "instant",
|
|
358
|
+
});
|
|
355
359
|
const r = rect(node),
|
|
356
360
|
position = input.command === "resolve" ? input.position : undefined;
|
|
357
361
|
const x = position?.x ?? r.width / 2,
|
|
@@ -448,6 +452,16 @@ export async function pageCommand(input) {
|
|
|
448
452
|
: input.button === 1
|
|
449
453
|
? "auxclick"
|
|
450
454
|
: "click";
|
|
455
|
+
const expected = input.expectedRef
|
|
456
|
+
? getRef(input.expectedRef)
|
|
457
|
+
: null;
|
|
458
|
+
if (expected) {
|
|
459
|
+
const hit = document.elementFromPoint(input.x, input.y);
|
|
460
|
+
if (hit !== expected && !expected.contains(hit)) {
|
|
461
|
+
value = { armed: false, documentToken: state.token };
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
451
465
|
const receipt = {
|
|
452
466
|
type,
|
|
453
467
|
count: 0,
|
|
@@ -455,11 +469,14 @@ export async function pageCommand(input) {
|
|
|
455
469
|
x: input.x,
|
|
456
470
|
y: input.y,
|
|
457
471
|
button: input.button,
|
|
472
|
+
expected,
|
|
458
473
|
};
|
|
459
474
|
receipt.listener = (event) => {
|
|
460
475
|
if (
|
|
461
476
|
event.isTrusted &&
|
|
462
477
|
event.button === input.button &&
|
|
478
|
+
(!receipt.expected ||
|
|
479
|
+
event.composedPath().includes(receipt.expected)) &&
|
|
463
480
|
Math.abs(event.clientX - input.x) <= 6 &&
|
|
464
481
|
Math.abs(event.clientY - input.y) <= 6
|
|
465
482
|
)
|