@humanjs/playwright 0.7.0 → 0.8.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/index.d.cts CHANGED
@@ -3,6 +3,14 @@ export { ActionResult, ActionType, BezierPathOptions, ComputeReadingDwellOptions
3
3
  import { Locator, BrowserContext, Page } from 'playwright';
4
4
  export { Browser, BrowserContext, BrowserContextOptions, ElementHandle, LaunchOptions, Locator, Page, chromium, firefox, webkit } from 'playwright';
5
5
 
6
+ /** Anything that can resolve to a click/move point. */
7
+ type MouseTarget = Locator | string | Point;
8
+
9
+ /** Values accepted by {@link executeSelectOption} — the Playwright `selectOption` shape. */
10
+ type SelectOptionValues = Parameters<Locator['selectOption']>[0];
11
+ /** Files accepted by {@link executeUpload} — the Playwright `setInputFiles` shape. */
12
+ type UploadFiles = Parameters<Locator['setInputFiles']>[0];
13
+
6
14
  /**
7
15
  * Modifier tokens accepted in a `human.press()` chord. `Mod` and `CmdOrCtrl` /
8
16
  * `CommandOrControl` are the magic auto-mapping tokens (Meta on Mac,
@@ -73,9 +81,6 @@ interface PressResult {
73
81
  readonly dispatched: string;
74
82
  }
75
83
 
76
- /** Anything that can resolve to a click/move point. */
77
- type MouseTarget = Locator | string | Point;
78
-
79
84
  /**
80
85
  * What to read:
81
86
  * - `string`: a Playwright-compatible selector (matches `click()` / `type()`).
@@ -536,6 +541,17 @@ interface Human {
536
541
  * `mouse.click({ button: 'right' })` at the coordinates.
537
542
  */
538
543
  rightClick(target: MouseTarget): Promise<void>;
544
+ /**
545
+ * Double-click `target`. Identical humanized approach to `click()` — same
546
+ * Bezier path, hover dwell, and occasional near-miss — but the final
547
+ * dispatch is a double-click (two presses within the OS double-click
548
+ * window). Accepts the same selector / `Locator` / `Point` targets.
549
+ *
550
+ * In `speed: 'instant'`, element targets fall back to
551
+ * `locator.click({ clickCount: 2 })`; a `Point` dispatches
552
+ * `mouse.click(x, y, { clickCount: 2 })`.
553
+ */
554
+ doubleClick(target: MouseTarget): Promise<void>;
539
555
  /**
540
556
  * Move the cursor to `target` along a humanized Bezier path and settle
541
557
  * on it — no click is dispatched. Useful for hover-triggered UI
@@ -602,6 +618,70 @@ interface Human {
602
618
  * by nature.
603
619
  */
604
620
  paste(target: Locator | string, value: string): Promise<void>;
621
+ /**
622
+ * Clear a text field `target` (input, textarea, or contenteditable) with a
623
+ * humanized gesture: click to focus, **select-all**, a beat, then **delete**
624
+ * — the real keyboard motion a person uses to wipe a field before retyping,
625
+ * not a silent value reset. Fires the keydown/up + `input` events the page
626
+ * expects.
627
+ *
628
+ * Pair with `type()` to edit an existing value:
629
+ * `await human.clear('#name'); await human.type('#name', 'New');`
630
+ *
631
+ * In `speed: 'instant'`, delegates to Playwright's native `locator.clear()`.
632
+ */
633
+ clear(target: Locator | string): Promise<void>;
634
+ /**
635
+ * Tick a checkbox or radio `target`. Moves the cursor to the control and
636
+ * clicks it with the same humanized motion as `click()` — but only when
637
+ * needed: if it already reports checked, no click fires (a real user
638
+ * doesn't re-click a box that's already ticked). The resulting state is
639
+ * verified; trying to `check` something that won't toggle throws.
640
+ *
641
+ * `target` is element-bound (selector or `Locator`). In `speed: 'instant'`,
642
+ * delegates to Playwright's native `locator.check()`.
643
+ */
644
+ check(target: Locator | string): Promise<void>;
645
+ /**
646
+ * Untick a checkbox `target`. Mirror of `check()` — humanized click only if
647
+ * currently checked, with state verification afterward. Radios can't be
648
+ * unchecked by clicking (select a different option instead); attempting it
649
+ * throws a clear error.
650
+ *
651
+ * In `speed: 'instant'`, delegates to `locator.uncheck()`.
652
+ */
653
+ uncheck(target: Locator | string): Promise<void>;
654
+ /**
655
+ * Choose option(s) in a native `<select>` `target`. The cursor moves to the
656
+ * dropdown and settles on it (humanized), then the value is set — native
657
+ * selects open an OS menu automation can't drive visually, so the *approach*
658
+ * is humanized while the choice itself is set programmatically (firing
659
+ * `input`/`change`), exactly as Playwright does. For custom DOM dropdowns,
660
+ * drive the rendered options with `click` instead.
661
+ *
662
+ * `values` takes the Playwright `selectOption` shape — a value string, an
663
+ * array of values, or `{ value | label | index }`. Returns the option
664
+ * values that ended up selected.
665
+ *
666
+ * In `speed: 'instant'`, sets the value with no cursor motion.
667
+ */
668
+ selectOption(target: Locator | string, values: SelectOptionValues): Promise<string[]>;
669
+ /**
670
+ * Attach file(s) to a file-input `target`. The cursor moves to the control
671
+ * (visible in recordings / the overlay), then the files are attached via
672
+ * `setInputFiles`. Unlike a real click this never opens the OS file dialog
673
+ * (which would hang) — files are set directly, the way Playwright models
674
+ * uploads.
675
+ *
676
+ * `target` should be the `<input type="file">`. For the common hidden-input-
677
+ * behind-a-styled-button pattern there's no visible control to approach, so
678
+ * the motion is skipped and the files are attached directly. `files` takes
679
+ * the Playwright `setInputFiles` shape (a path, an array of paths, or
680
+ * in-memory `{ name, mimeType, buffer }` payloads).
681
+ *
682
+ * In `speed: 'instant'`, attaches the files with no cursor motion.
683
+ */
684
+ upload(target: Locator | string, files: UploadFiles): Promise<void>;
605
685
  /**
606
686
  * Press a single key (`'Tab'`, `'Enter'`, `'Escape'`, `'ArrowDown'`, …)
607
687
  * or a keyboard chord (`'Mod+S'`, `'Cmd+Shift+P'`, `'Ctrl+C'`, …).
@@ -759,6 +839,22 @@ interface Human {
759
839
  * Not a humanized action: no plugin events fire.
760
840
  */
761
841
  content(): Promise<string>;
842
+ /**
843
+ * Accessibility-tree **outline** of the page (or a region) — every
844
+ * interactive element and landmark by its ARIA role + accessible name,
845
+ * rendered as compact YAML (Playwright's `ariaSnapshot`). The most
846
+ * token-efficient way for an AI agent to see what's actionable and pick a
847
+ * selector: the names map directly to `getByRole` / accessible-name
848
+ * selectors, which HumanJS already favors.
849
+ *
850
+ * Prefer this over {@link Human.content} when the question is "what can I
851
+ * click / fill"; reach for {@link Human.screenshot} when you need the
852
+ * visual layout. Pass `target` to scope the outline to a region.
853
+ *
854
+ * Not a humanized action: no plugin events fire. Requires Playwright ≥ 1.49
855
+ * (when `ariaSnapshot` landed).
856
+ */
857
+ outline(target?: Locator | string): Promise<string>;
762
858
  /**
763
859
  * Current URL of the page. Forwards to `page.url()`. Synchronous return
764
860
  * because Playwright's underlying API is sync.
@@ -886,4 +982,4 @@ interface HumanRecordOptions {
886
982
  */
887
983
  declare function createHuman(page: Page, options?: CreateHumanOptions): Promise<Human>;
888
984
 
889
- export { type CreateHumanOptions, type FfmpegPreset, type FfmpegTune, type Human, type HumanRecordOptions, type InstallMouseHelperOptions, type KeyModifier, type KeyName, type KeyOrChord, type MouseTarget, type PlaywrightTestOptions, type PressResult, type ReadOptions, type ReadResult, type ReadTarget, Recording, type RecordingQuality, type ScrollOptions, type ScrollResult, type ScrollTarget, type Speed, type Timeline, type TimelineEvent, type ToGifOptions, type ToVideoOptions, createHuman, installMouseHelper };
985
+ export { type CreateHumanOptions, type FfmpegPreset, type FfmpegTune, type Human, type HumanRecordOptions, type InstallMouseHelperOptions, type KeyModifier, type KeyName, type KeyOrChord, type MouseTarget, type PlaywrightTestOptions, type PressResult, type ReadOptions, type ReadResult, type ReadTarget, Recording, type RecordingQuality, type ScrollOptions, type ScrollResult, type ScrollTarget, type SelectOptionValues, type Speed, type Timeline, type TimelineEvent, type ToGifOptions, type ToVideoOptions, type UploadFiles, createHuman, installMouseHelper };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,14 @@ export { ActionResult, ActionType, BezierPathOptions, ComputeReadingDwellOptions
3
3
  import { Locator, BrowserContext, Page } from 'playwright';
4
4
  export { Browser, BrowserContext, BrowserContextOptions, ElementHandle, LaunchOptions, Locator, Page, chromium, firefox, webkit } from 'playwright';
5
5
 
6
+ /** Anything that can resolve to a click/move point. */
7
+ type MouseTarget = Locator | string | Point;
8
+
9
+ /** Values accepted by {@link executeSelectOption} — the Playwright `selectOption` shape. */
10
+ type SelectOptionValues = Parameters<Locator['selectOption']>[0];
11
+ /** Files accepted by {@link executeUpload} — the Playwright `setInputFiles` shape. */
12
+ type UploadFiles = Parameters<Locator['setInputFiles']>[0];
13
+
6
14
  /**
7
15
  * Modifier tokens accepted in a `human.press()` chord. `Mod` and `CmdOrCtrl` /
8
16
  * `CommandOrControl` are the magic auto-mapping tokens (Meta on Mac,
@@ -73,9 +81,6 @@ interface PressResult {
73
81
  readonly dispatched: string;
74
82
  }
75
83
 
76
- /** Anything that can resolve to a click/move point. */
77
- type MouseTarget = Locator | string | Point;
78
-
79
84
  /**
80
85
  * What to read:
81
86
  * - `string`: a Playwright-compatible selector (matches `click()` / `type()`).
@@ -536,6 +541,17 @@ interface Human {
536
541
  * `mouse.click({ button: 'right' })` at the coordinates.
537
542
  */
538
543
  rightClick(target: MouseTarget): Promise<void>;
544
+ /**
545
+ * Double-click `target`. Identical humanized approach to `click()` — same
546
+ * Bezier path, hover dwell, and occasional near-miss — but the final
547
+ * dispatch is a double-click (two presses within the OS double-click
548
+ * window). Accepts the same selector / `Locator` / `Point` targets.
549
+ *
550
+ * In `speed: 'instant'`, element targets fall back to
551
+ * `locator.click({ clickCount: 2 })`; a `Point` dispatches
552
+ * `mouse.click(x, y, { clickCount: 2 })`.
553
+ */
554
+ doubleClick(target: MouseTarget): Promise<void>;
539
555
  /**
540
556
  * Move the cursor to `target` along a humanized Bezier path and settle
541
557
  * on it — no click is dispatched. Useful for hover-triggered UI
@@ -602,6 +618,70 @@ interface Human {
602
618
  * by nature.
603
619
  */
604
620
  paste(target: Locator | string, value: string): Promise<void>;
621
+ /**
622
+ * Clear a text field `target` (input, textarea, or contenteditable) with a
623
+ * humanized gesture: click to focus, **select-all**, a beat, then **delete**
624
+ * — the real keyboard motion a person uses to wipe a field before retyping,
625
+ * not a silent value reset. Fires the keydown/up + `input` events the page
626
+ * expects.
627
+ *
628
+ * Pair with `type()` to edit an existing value:
629
+ * `await human.clear('#name'); await human.type('#name', 'New');`
630
+ *
631
+ * In `speed: 'instant'`, delegates to Playwright's native `locator.clear()`.
632
+ */
633
+ clear(target: Locator | string): Promise<void>;
634
+ /**
635
+ * Tick a checkbox or radio `target`. Moves the cursor to the control and
636
+ * clicks it with the same humanized motion as `click()` — but only when
637
+ * needed: if it already reports checked, no click fires (a real user
638
+ * doesn't re-click a box that's already ticked). The resulting state is
639
+ * verified; trying to `check` something that won't toggle throws.
640
+ *
641
+ * `target` is element-bound (selector or `Locator`). In `speed: 'instant'`,
642
+ * delegates to Playwright's native `locator.check()`.
643
+ */
644
+ check(target: Locator | string): Promise<void>;
645
+ /**
646
+ * Untick a checkbox `target`. Mirror of `check()` — humanized click only if
647
+ * currently checked, with state verification afterward. Radios can't be
648
+ * unchecked by clicking (select a different option instead); attempting it
649
+ * throws a clear error.
650
+ *
651
+ * In `speed: 'instant'`, delegates to `locator.uncheck()`.
652
+ */
653
+ uncheck(target: Locator | string): Promise<void>;
654
+ /**
655
+ * Choose option(s) in a native `<select>` `target`. The cursor moves to the
656
+ * dropdown and settles on it (humanized), then the value is set — native
657
+ * selects open an OS menu automation can't drive visually, so the *approach*
658
+ * is humanized while the choice itself is set programmatically (firing
659
+ * `input`/`change`), exactly as Playwright does. For custom DOM dropdowns,
660
+ * drive the rendered options with `click` instead.
661
+ *
662
+ * `values` takes the Playwright `selectOption` shape — a value string, an
663
+ * array of values, or `{ value | label | index }`. Returns the option
664
+ * values that ended up selected.
665
+ *
666
+ * In `speed: 'instant'`, sets the value with no cursor motion.
667
+ */
668
+ selectOption(target: Locator | string, values: SelectOptionValues): Promise<string[]>;
669
+ /**
670
+ * Attach file(s) to a file-input `target`. The cursor moves to the control
671
+ * (visible in recordings / the overlay), then the files are attached via
672
+ * `setInputFiles`. Unlike a real click this never opens the OS file dialog
673
+ * (which would hang) — files are set directly, the way Playwright models
674
+ * uploads.
675
+ *
676
+ * `target` should be the `<input type="file">`. For the common hidden-input-
677
+ * behind-a-styled-button pattern there's no visible control to approach, so
678
+ * the motion is skipped and the files are attached directly. `files` takes
679
+ * the Playwright `setInputFiles` shape (a path, an array of paths, or
680
+ * in-memory `{ name, mimeType, buffer }` payloads).
681
+ *
682
+ * In `speed: 'instant'`, attaches the files with no cursor motion.
683
+ */
684
+ upload(target: Locator | string, files: UploadFiles): Promise<void>;
605
685
  /**
606
686
  * Press a single key (`'Tab'`, `'Enter'`, `'Escape'`, `'ArrowDown'`, …)
607
687
  * or a keyboard chord (`'Mod+S'`, `'Cmd+Shift+P'`, `'Ctrl+C'`, …).
@@ -759,6 +839,22 @@ interface Human {
759
839
  * Not a humanized action: no plugin events fire.
760
840
  */
761
841
  content(): Promise<string>;
842
+ /**
843
+ * Accessibility-tree **outline** of the page (or a region) — every
844
+ * interactive element and landmark by its ARIA role + accessible name,
845
+ * rendered as compact YAML (Playwright's `ariaSnapshot`). The most
846
+ * token-efficient way for an AI agent to see what's actionable and pick a
847
+ * selector: the names map directly to `getByRole` / accessible-name
848
+ * selectors, which HumanJS already favors.
849
+ *
850
+ * Prefer this over {@link Human.content} when the question is "what can I
851
+ * click / fill"; reach for {@link Human.screenshot} when you need the
852
+ * visual layout. Pass `target` to scope the outline to a region.
853
+ *
854
+ * Not a humanized action: no plugin events fire. Requires Playwright ≥ 1.49
855
+ * (when `ariaSnapshot` landed).
856
+ */
857
+ outline(target?: Locator | string): Promise<string>;
762
858
  /**
763
859
  * Current URL of the page. Forwards to `page.url()`. Synchronous return
764
860
  * because Playwright's underlying API is sync.
@@ -886,4 +982,4 @@ interface HumanRecordOptions {
886
982
  */
887
983
  declare function createHuman(page: Page, options?: CreateHumanOptions): Promise<Human>;
888
984
 
889
- export { type CreateHumanOptions, type FfmpegPreset, type FfmpegTune, type Human, type HumanRecordOptions, type InstallMouseHelperOptions, type KeyModifier, type KeyName, type KeyOrChord, type MouseTarget, type PlaywrightTestOptions, type PressResult, type ReadOptions, type ReadResult, type ReadTarget, Recording, type RecordingQuality, type ScrollOptions, type ScrollResult, type ScrollTarget, type Speed, type Timeline, type TimelineEvent, type ToGifOptions, type ToVideoOptions, createHuman, installMouseHelper };
985
+ export { type CreateHumanOptions, type FfmpegPreset, type FfmpegTune, type Human, type HumanRecordOptions, type InstallMouseHelperOptions, type KeyModifier, type KeyName, type KeyOrChord, type MouseTarget, type PlaywrightTestOptions, type PressResult, type ReadOptions, type ReadResult, type ReadTarget, Recording, type RecordingQuality, type ScrollOptions, type ScrollResult, type ScrollTarget, type SelectOptionValues, type Speed, type Timeline, type TimelineEvent, type ToGifOptions, type ToVideoOptions, type UploadFiles, createHuman, installMouseHelper };