clearcote 0.65.0 → 0.66.0

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/humanize.js CHANGED
@@ -35,7 +35,7 @@ import { keepInView, trimTo, walk } from "./pacing.js";
35
35
  import { record as traceRecord, traceEnabled } from "./trace.js";
36
36
  import { pressAndHold } from "./hold.js";
37
37
  import { BLANK_POINT, FOCUSABLE, SEARCH_SLIP_RATE, SELECTION_STATE, TAB_DISTANCE, WORD_FIX_RATE, flightMs, modifierLagMs, modifierLeadMs, planGap, planRepeat, splitChord, submitPauseMs, tabPauseMs, typingTraits, } from "./keys.js";
38
- import { COVER_CHECK_MS, COVER_RETRY_MS, ISO_ACTIVE_FIELD, ISO_ACTIVE_VALUE, ISO_CSS_BOX, ISO_DESCRIBE, ISO_FORM_CONTROL, ISO_FRAMES, ISO_HIT_IN_BOX, ISO_LABEL_BY_SEL, ISO_LABEL_OF, ISO_LISTBOX_ROW, ISO_PLATFORM, ISO_SCROLL_BY, ISO_VIEWPORT, roundHalfEven, worldFor, } from "./isolated.js";
38
+ import { COVER_CHECK_MS, COVER_RETRY_MS, SETTLE_MS, SETTLE_TRIES, ISO_COVER, ISO_ACTIVE_FIELD, ISO_ACTIVE_VALUE, ISO_CSS_BOX, ISO_DESCRIBE, ISO_FORM_CONTROL, ISO_FRAMES, ISO_HIT_IN_BOX, ISO_LABEL_BY_SEL, ISO_LABEL_OF, ISO_LISTBOX_ROW, ISO_PLATFORM, ISO_SCROLL_BY, ISO_VIEWPORT, roundHalfEven, worldFor, } from "./isolated.js";
39
39
  import { NATIVE, frameLocatorOf, frameRoute, handleAsLocator, humanized as frameHumanized } from "./frames.js";
40
40
  export { reportFallback, strictMode } from "./frames.js";
41
41
  /** The error a strict-mode tap raises on a touch context (lane F, SC 232). */
@@ -933,6 +933,7 @@ export async function attachHumanize(browser, page, opts) {
933
933
  traceRecord("wheel", wrec, { device, dx, dy });
934
934
  }
935
935
  };
936
+ const wheelHuman = mouse.wheel; // unlocked: for use inside a locked action
936
937
  const wheelRun = async (device, dx, dy, sendWheel) => {
937
938
  if (device === "trackpad") {
938
939
  // A trackpad persona swipes the exact distance: 2-40 px events at the persona's 60-120/s on a min-jerk
@@ -2834,6 +2835,60 @@ export async function attachHumanize(browser, page, opts) {
2834
2835
  }
2835
2836
  return hit;
2836
2837
  };
2838
+ // The element's box once it has stopped moving: two reads ~100 ms apart within 1 px, for up to SETTLE_MS.
2839
+ // null when it never settles or has no box. Read like boxOf (the isolated CSS read, else boundingBox),
2840
+ // with the wheel, so a target the settling scroll left out of view is brought back in.
2841
+ const sameBox = (a, b) => Math.abs(a.x - b.x) <= 1 && Math.abs(a.y - b.y) <= 1
2842
+ && Math.abs(a.width - b.width) <= 1 && Math.abs(a.height - b.height) <= 1;
2843
+ const settledBox = async (loc, timeout, selector) => {
2844
+ const deadline = Date.now() + SETTLE_MS;
2845
+ let prev = await boxOf(loc, timeout, false, selector);
2846
+ while (prev && Date.now() < deadline) {
2847
+ await sleep(100);
2848
+ const next = await boxOf(loc, timeout, false, selector);
2849
+ if (!next)
2850
+ return null;
2851
+ if (sameBox(prev, next))
2852
+ return next;
2853
+ prev = next;
2854
+ }
2855
+ return null;
2856
+ };
2857
+ // A target that is not moving yet fails the hit test is covered. Two covers a person deals with without
2858
+ // thinking, which used to send the click to Playwright (r53 /audit, seed 2, 2026-10-28):
2859
+ // - something the pointer itself opened: it rested on a header link and a hover menu dropped over the
2860
+ // target. The hand moves off it (below it where there is room, else above) and the menu closes;
2861
+ // - a fixed or sticky bar (a site header) over a target the scroll left under it: the wheel brings the
2862
+ // target down into the band a reader looks at.
2863
+ // true when it did one of them (the caller re-reads the box and hit-tests again).
2864
+ const uncover = async (box, x, y) => {
2865
+ const c = await worldFor(page).evaluate(ISO_COVER, { x, y, b: { x: box.x, y: box.y, width: box.width, height: box.height } });
2866
+ if (!c || !Array.isArray(c.rect))
2867
+ return false;
2868
+ const [cx, cy, cw, ch] = c.rect.map(Number);
2869
+ const vp = await viewport();
2870
+ if (st.x >= cx && st.x <= cx + cw && st.y >= cy && st.y <= cy + ch) {
2871
+ // Off its edge by 6-80 px where the viewport has room (a mega menu can leave only a strip), below first.
2872
+ const roomBelow = vp.height - 4 - (cy + ch + 6), roomAbove = cy - 6 - 4;
2873
+ const ty = roomBelow >= 0 ? cy + ch + 6 + rand(0, Math.min(74, roomBelow))
2874
+ : roomAbove >= 0 ? cy - 6 - rand(0, Math.min(74, roomAbove)) : null;
2875
+ if (ty === null)
2876
+ return false;
2877
+ const tx = Math.min(vp.width - 8, Math.max(8, box.x + box.width / 2 + rand(-60, 60)));
2878
+ await glide(tx, ty);
2879
+ await sleep(rand(250, 450)); // a hover menu's close transition
2880
+ return true;
2881
+ }
2882
+ // A cover filling most of the viewport is a modal or a cookie wall, not a bar to scroll out from under.
2883
+ if (c.fixed && cw * ch <= 0.8 * vp.width * vp.height) {
2884
+ const dy = box.y + box.height / 2 - vp.height * rand(0.3, 0.5);
2885
+ if (Math.abs(dy) < 1)
2886
+ return false;
2887
+ await wheelHuman(0, dy);
2888
+ return true;
2889
+ }
2890
+ return false;
2891
+ };
2837
2892
  // The viewport point of Playwright's `position` (relative to the PADDING box: the border widths are added).
2838
2893
  const positionPoint = async (box, pos) => {
2839
2894
  const info = await describe(box, null);
@@ -2919,31 +2974,55 @@ export async function attachHumanize(browser, page, opts) {
2919
2974
  const loc = page.locator(selector).first();
2920
2975
  // Playwright skips actionability with force: no wait then -- a target it would click hidden goes
2921
2976
  // native at once instead of timing out first.
2922
- const box = await boxOf(loc, timeout, o.force, selector);
2977
+ let box = await boxOf(loc, timeout, o.force, selector);
2923
2978
  if (!box)
2924
2979
  throw new NativeSignal("the element has no box");
2925
- aim = { x: box.x + box.width / 2, y: box.y + box.height / 2 };
2926
2980
  if (!o.force && !(await loc.isEnabled()))
2927
2981
  throw new NativeSignal("the element is not enabled");
2928
- let x, y;
2929
- if (o.position) {
2930
- ({ x, y } = await positionPoint(box, o.position));
2931
- aim = { x, y };
2932
- }
2933
- else {
2934
- ({ x, y } = clickPoint(box, st, persona));
2935
- }
2936
- // Whole pixels: the hit test below answers for the pixel DOM.getNodeForLocation rounds to, so the
2937
- // press goes to that pixel too. A press at 971.6 next to a badge ending at 972 was proven at 972 and
2938
- // landed on the badge, reported as a success (verifier B, SC 210).
2939
- x = roundHalfEven(x);
2940
- y = roundHalfEven(y);
2982
+ let x = 0, y = 0;
2983
+ const aimAt = async (b) => {
2984
+ aim = { x: b.x + b.width / 2, y: b.y + b.height / 2 };
2985
+ if (o.position) {
2986
+ ({ x, y } = await positionPoint(b, o.position));
2987
+ aim = { x, y };
2988
+ }
2989
+ else {
2990
+ ({ x, y } = clickPoint(b, st, persona));
2991
+ }
2992
+ // Whole pixels: the hit test below answers for the pixel DOM.getNodeForLocation rounds to, so the
2993
+ // press goes to that pixel too. A press at 971.6 next to a badge ending at 972 was proven at 972 and
2994
+ // landed on the badge, reported as a success (verifier B, SC 210).
2995
+ x = roundHalfEven(x);
2996
+ y = roundHalfEven(y);
2997
+ };
2998
+ await aimAt(box);
2941
2999
  if (!o.force && orig) {
2942
3000
  // Stability, then covered-by: 50 ms on, the element must still fill `box` (an animation in
2943
3001
  // flight does not) and own the click point -- no trusted press at a point some overlay owns.
2944
3002
  // Either failing goes native: Playwright waits for it.
2945
3003
  await sleep(50);
2946
- const hit = await reachesPoint(box, x, y, selector);
3004
+ let hit = await reachesPoint(box, x, y, selector);
3005
+ // A target still moving (the scroll that brought it in settling, a layout shift) fails the test with
3006
+ // the box it had. Re-aim at the box it settles at rather than hand the click to Playwright, whose
3007
+ // press and release land in the same millisecond with a one-report jump from rest (/audit
3008
+ // pointer-press-dwell-duration, pointer-jump-from-rest; r53 seed 2, 2026-10-28).
3009
+ // A target that is covered rather than moving is uncovered first (uncover); what stays covered is
3010
+ // handled below.
3011
+ for (let tries = 0; hit === false && tries < SETTLE_TRIES; tries++) {
3012
+ let next = await settledBox(loc, timeout, selector);
3013
+ if (!next)
3014
+ break;
3015
+ if (sameBox(next, box)) {
3016
+ if (!(await uncover(next, x, y)))
3017
+ break;
3018
+ next = await settledBox(loc, timeout, selector);
3019
+ if (!next)
3020
+ break;
3021
+ }
3022
+ box = next;
3023
+ await aimAt(box);
3024
+ hit = await reachesPoint(box, x, y, selector);
3025
+ }
2947
3026
  if (hit === false && !o.position) {
2948
3027
  // The persona's point is covered (a badge, an icon, a floating label over the centre). Before
2949
3028
  // giving the click to Playwright -- which waited out its timeout on 5-7 of 16 badge-covered