@e2e-dev/electron 0.0.0-stage → 0.0.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.
Files changed (75) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +91 -2
  4. package/dist/.build.json +1 -0
  5. package/dist/actionability.d.ts +41 -0
  6. package/dist/actionability.js +121 -0
  7. package/dist/actions.d.ts +52 -0
  8. package/dist/actions.js +418 -0
  9. package/dist/app-process.d.ts +114 -0
  10. package/dist/app-process.js +610 -0
  11. package/dist/budget.d.ts +33 -0
  12. package/dist/budget.js +64 -0
  13. package/dist/capture.d.ts +21 -0
  14. package/dist/capture.js +137 -0
  15. package/dist/cdp/connection.d.ts +68 -0
  16. package/dist/cdp/connection.js +232 -0
  17. package/dist/cdp/input.d.ts +67 -0
  18. package/dist/cdp/input.js +195 -0
  19. package/dist/cdp/keys.d.ts +21 -0
  20. package/dist/cdp/keys.js +114 -0
  21. package/dist/console-text.d.ts +4 -0
  22. package/dist/console-text.js +27 -0
  23. package/dist/devtools.d.ts +36 -0
  24. package/dist/devtools.js +111 -0
  25. package/dist/dialogs.d.ts +38 -0
  26. package/dist/dialogs.js +81 -0
  27. package/dist/electron.d.ts +9 -0
  28. package/dist/electron.js +174 -0
  29. package/dist/engine-entry.d.ts +13 -0
  30. package/dist/engine-entry.js +9 -0
  31. package/dist/engine.d.ts +27 -0
  32. package/dist/engine.js +98 -0
  33. package/dist/errors.d.ts +17 -0
  34. package/dist/errors.js +54 -0
  35. package/dist/evaluate.d.ts +40 -0
  36. package/dist/evaluate.js +115 -0
  37. package/dist/executable.d.ts +29 -0
  38. package/dist/executable.js +249 -0
  39. package/dist/ffmpeg.d.ts +12 -0
  40. package/dist/ffmpeg.js +100 -0
  41. package/dist/fields.d.ts +93 -0
  42. package/dist/fields.js +254 -0
  43. package/dist/file-bound.d.ts +31 -0
  44. package/dist/file-bound.js +104 -0
  45. package/dist/fixtures.d.ts +168 -0
  46. package/dist/fixtures.js +6 -0
  47. package/dist/in-page/masks.d.ts +25 -0
  48. package/dist/in-page/masks.js +140 -0
  49. package/dist/in-page/node-ops.d.ts +96 -0
  50. package/dist/in-page/node-ops.js +406 -0
  51. package/dist/index.d.ts +18 -0
  52. package/dist/index.js +18 -0
  53. package/dist/launcher.d.ts +45 -0
  54. package/dist/launcher.js +167 -0
  55. package/dist/locate.d.ts +46 -0
  56. package/dist/locate.js +103 -0
  57. package/dist/main-process.d.ts +25 -0
  58. package/dist/main-process.js +60 -0
  59. package/dist/options.d.ts +65 -0
  60. package/dist/options.js +120 -0
  61. package/dist/page.d.ts +100 -0
  62. package/dist/page.js +229 -0
  63. package/dist/runner-test.d.ts +15 -0
  64. package/dist/runner-test.js +45 -0
  65. package/dist/snapshot.d.ts +143 -0
  66. package/dist/snapshot.js +260 -0
  67. package/dist/surface.d.ts +158 -0
  68. package/dist/surface.js +602 -0
  69. package/dist/tree.d.ts +51 -0
  70. package/dist/tree.js +406 -0
  71. package/dist/video.d.ts +42 -0
  72. package/dist/video.js +253 -0
  73. package/dist/windows.d.ts +81 -0
  74. package/dist/windows.js +200 -0
  75. package/package.json +72 -3
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Page-side halves of a masked screenshot: a black box painted over every
3
+ * element a selector matches, with the caret hidden and animations stopped,
4
+ * and the cleanup that takes it all away again. Sent as source text: each
5
+ * function is self-contained.
6
+ */
7
+ /**
8
+ * Paints a black box over every element `selector` matches in the document
9
+ * and in each open shadow root, hides the text caret, and stops animations:
10
+ * a finite one jumps to its end, an endless one to its start, so a field an
11
+ * animation moves stays under the box measured for it.
12
+ */
13
+ export function placeMasks(selector) {
14
+ // The cleanup of masks still in place, kept on the isolated world's global between the two calls.
15
+ const earlier = Reflect.get(globalThis, 'e2eRemoveMasks');
16
+ if (typeof earlier === 'function')
17
+ earlier();
18
+ const elements = [];
19
+ const visit = (root) => {
20
+ elements.push(...root.querySelectorAll(selector));
21
+ for (const element of root.querySelectorAll('*'))
22
+ if (element.shadowRoot !== null)
23
+ visit(element.shadowRoot);
24
+ };
25
+ visit(document);
26
+ const resume = [];
27
+ for (const animation of document.getAnimations()) {
28
+ // A paused animation holds still already; one the capture cancelled is played again after it, which would start it.
29
+ if (animation.effect === null || animation.playbackRate === 0 || animation.playState === 'paused')
30
+ continue;
31
+ const end = animation.effect.getComputedTiming().endTime;
32
+ try {
33
+ if (Number.isFinite(Number(end))) {
34
+ animation.finish();
35
+ }
36
+ else {
37
+ animation.cancel();
38
+ resume.push(animation);
39
+ }
40
+ }
41
+ catch {
42
+ // An animation that cannot be finished or cancelled is left running.
43
+ }
44
+ }
45
+ // Every declaration is !important: the app's own rule for a div or a popover, however it is marked, loses to an
46
+ // inline one that is.
47
+ const important = (declarations) => declarations.map((declaration) => `${declaration} !important;`).join(' ');
48
+ const style = document.createElement('style');
49
+ style.textContent = '* { caret-color: transparent !important; }';
50
+ const layer = document.createElement('div');
51
+ // A popover is in the top layer, above a modal dialog and anything else the app put there before it. An Electron
52
+ // older than 25 has none: the layer is then the topmost of the page's own, and anything in the top layer is over it.
53
+ const popover = typeof layer.showPopover === 'function';
54
+ if (popover)
55
+ layer.popover = 'manual';
56
+ layer.style.cssText = important([
57
+ 'all: initial',
58
+ 'display: block',
59
+ 'position: fixed',
60
+ 'inset: 0',
61
+ 'width: 100%',
62
+ 'height: 100%',
63
+ 'margin: 0',
64
+ 'border: 0',
65
+ 'padding: 0',
66
+ 'background: transparent',
67
+ 'overflow: visible',
68
+ 'opacity: 1',
69
+ 'visibility: visible',
70
+ 'z-index: 2147483647',
71
+ 'pointer-events: none',
72
+ ]);
73
+ document.documentElement.append(style, layer);
74
+ let covered = true;
75
+ if (popover) {
76
+ layer.showPopover();
77
+ }
78
+ else {
79
+ // What the app holds in the top layer would paint over the masks: there is no telling pixels under one are covered.
80
+ try {
81
+ covered = document.querySelector('dialog:modal, :fullscreen') === null;
82
+ }
83
+ catch {
84
+ covered = false;
85
+ }
86
+ }
87
+ // A zoom on the root scales the layer's own lengths, which the measured boxes already include. Where the page
88
+ // cannot say its zoom, the boxes are measured below all the same, and one that misses its element withholds the capture.
89
+ const zoom = layer.currentCSSZoom ?? 1;
90
+ const boxes = [];
91
+ for (const element of elements) {
92
+ const { x, y, width, height } = element.getBoundingClientRect();
93
+ boxes.push([x, y, width, height].map(Math.round).join(','));
94
+ const box = document.createElement('div');
95
+ box.style.cssText = important(['all: initial', 'display: block', 'position: fixed', `left: ${x / zoom}px`, `top: ${y / zoom}px`, `width: ${width / zoom}px`, `height: ${height / zoom}px`, 'background: #000000', 'opacity: 1', 'visibility: visible']);
96
+ layer.append(box);
97
+ // Measured, not assumed: a page can lay the layer out in ways no formula here foresees.
98
+ const drawn = box.getBoundingClientRect();
99
+ covered &&= drawn.left <= x + 1 && drawn.top <= y + 1 && drawn.right >= x + width - 1 && drawn.bottom >= y + height - 1;
100
+ }
101
+ const painted = layer.outerHTML;
102
+ Reflect.set(globalThis, 'e2eRemoveMasks', () => {
103
+ // A page script can reach the masks through the document: they count only as painted, each one, to the end.
104
+ const whole = layer.parentNode === document.documentElement && (!popover || layer.matches(':popover-open')) && layer.outerHTML === painted;
105
+ style.remove();
106
+ layer.remove();
107
+ for (const animation of resume) {
108
+ try {
109
+ animation.play();
110
+ }
111
+ catch {
112
+ // The animation's element is gone.
113
+ }
114
+ }
115
+ Reflect.deleteProperty(globalThis, 'e2eRemoveMasks');
116
+ return whole;
117
+ });
118
+ return { count: elements.length, boxes: boxes.join(';'), placed: covered };
119
+ }
120
+ /** Takes the masks away, and says what `selector` matches now: an element that appeared or moved since was not under one. */
121
+ export function removeMasks(selector) {
122
+ const remove = Reflect.get(globalThis, 'e2eRemoveMasks');
123
+ const placed = typeof remove === 'function' && remove() === true;
124
+ const boxes = [];
125
+ const visit = (root) => {
126
+ for (const element of root.querySelectorAll(selector)) {
127
+ const { x, y, width, height } = element.getBoundingClientRect();
128
+ boxes.push([x, y, width, height].map(Math.round).join(','));
129
+ }
130
+ for (const element of root.querySelectorAll('*'))
131
+ if (element.shadowRoot !== null)
132
+ visit(element.shadowRoot);
133
+ };
134
+ visit(document);
135
+ return { count: boxes.length, boxes: boxes.join(';'), placed };
136
+ }
137
+ /** How many device pixels one CSS pixel covers. */
138
+ export function pixelRatio() {
139
+ return devicePixelRatio;
140
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The engine's page-side work on one node, run in its isolated world with
3
+ * the node as its first argument. `devtools.ts` sends `nodeOp` as source text
4
+ * (`toString()`), so it stays one self-contained function: no imports beyond
5
+ * types, nothing referenced outside its body.
6
+ */
7
+ /** A page-side check's answer: ok, or why the node cannot take the action yet. */
8
+ export type Readiness = {
9
+ readonly ok: true;
10
+ } | {
11
+ readonly ok: false;
12
+ readonly reason: string;
13
+ };
14
+ /** The option `selectOption` names: by label (the default), value, or position. */
15
+ export interface WantedOption {
16
+ readonly label?: string;
17
+ readonly value?: string;
18
+ readonly index?: number;
19
+ }
20
+ /** Every operation `nodeOp` runs, by name. A text node acts through its element. */
21
+ export interface NodeOps {
22
+ /** In the document. */
23
+ checkConnected(): Readiness;
24
+ /** In the document, visible, and enabled when `enabled` asks. */
25
+ checkEnabled(enabled: boolean): Readiness;
26
+ /** Whether a click at the viewport point lands on the element, a node inside it, or a label for it. */
27
+ hitTest(x: number, y: number): Readiness;
28
+ scrollIntoView(): void;
29
+ /**
30
+ * For a checkbox or radio with no box that a label of its own draws: the
31
+ * viewport point at that label's centre, scrolled into view, which a click
32
+ * reaches the control through. Null for any other node.
33
+ */
34
+ labelPoint(): {
35
+ readonly x: number;
36
+ readonly y: number;
37
+ } | null;
38
+ /** Focuses the element: `held` when it holds focus after, `moved` when the app sent focus elsewhere, `none` when it cannot take focus and focus stayed where it was. */
39
+ focus(): 'held' | 'moved' | 'none';
40
+ blur(): void;
41
+ /** A text field or editing host that is enabled and not read-only. */
42
+ checkEditable(): Readiness;
43
+ /**
44
+ * Sets the value of an input that takes no typed text, with its input and
45
+ * change events; null when the value is to be typed instead.
46
+ */
47
+ setValue(value: string): Readiness | null;
48
+ /** Focuses the element and selects its whole content; false when the app moved focus away. */
49
+ selectContents(): boolean;
50
+ /** A checkbox's or radio's checked state, or `aria-checked` on a role that has one; null when it has none (a toggle button's `aria-pressed` is not a checked state, as on the web). */
51
+ readChecked(): boolean | null;
52
+ /** A `<select>` that is enabled and holds the option, enabled. */
53
+ checkSelect(wanted: WantedOption): Readiness;
54
+ selectOption(wanted: WantedOption): Readiness;
55
+ /** An enabled file input. */
56
+ checkFileInput(): Readiness;
57
+ /** Whether the file input takes `count` files: more than one needs `multiple`. */
58
+ takesFiles(count: number): Readiness;
59
+ /** Empties a file input, with its input and change events. */
60
+ clearFiles(): void;
61
+ /** A native radio: one a click never clears. A custom one clears if its app says so. */
62
+ isNativeRadio(): boolean;
63
+ /** Whether the node is a file input, which takes files itself. */
64
+ isFileInput(): boolean;
65
+ /** Whether the node, the focused element, takes typed text, typed keys as a widget's typeahead, or keys the app handles itself. */
66
+ takesText(): boolean;
67
+ /** The element's computed value of each named CSS property. */
68
+ readStyle(names: readonly string[]): Record<string, string>;
69
+ /** How much of the element's box is inside the window, past what its scrolling ancestors clip. */
70
+ viewportIntersection(): {
71
+ readonly intersects: boolean;
72
+ readonly ratio: number;
73
+ };
74
+ }
75
+ /** Runs one of `NodeOps` on `node`. */
76
+ export declare function nodeOp<K extends keyof NodeOps>(node: Node, name: K, args: Parameters<NodeOps[K]>): ReturnType<NodeOps[K]>;
77
+ /**
78
+ * The focused element under a document or shadow root, through every open
79
+ * shadow root; it stops at a closed root's host. Its answer is a handle, which
80
+ * only the protocol can hold, so it is no `NodeOps` entry: those answer in
81
+ * JSON. Sent as source text: self-contained.
82
+ */
83
+ export declare function activeUnder(root: Node): Element | null;
84
+ /**
85
+ * The backend-resolvable elements a CSS selector matches in the document and
86
+ * in each open shadow root, one root at a time as `querySelectorAll` does. It
87
+ * never enters a frame. Sent as source text: self-contained.
88
+ */
89
+ export declare function queryAll(selector: string): Element[];
90
+ /** Resolves after the next frame renders, or at once in a hidden window, which renders none. Sent as source text: self-contained. */
91
+ export declare function nextFrame(): Promise<void>;
92
+ /** The window's inner size in CSS pixels. Sent as source text: self-contained. */
93
+ export declare function viewportSize(): {
94
+ readonly width: number;
95
+ readonly height: number;
96
+ };
@@ -0,0 +1,406 @@
1
+ /**
2
+ * The engine's page-side work on one node, run in its isolated world with
3
+ * the node as its first argument. `devtools.ts` sends `nodeOp` as source text
4
+ * (`toString()`), so it stays one self-contained function: no imports beyond
5
+ * types, nothing referenced outside its body.
6
+ */
7
+ /** Runs one of `NodeOps` on `node`. */
8
+ export function nodeOp(node, name, args) {
9
+ const owner = node instanceof Element ? node : node.parentElement;
10
+ const TEXT_INPUT_TYPES = new Set(['', 'text', 'password', 'email', 'search', 'tel', 'url', 'number']);
11
+ /** Input types whose value is set rather than typed. */
12
+ const SET_VALUE_TYPES = new Set(['date', 'time', 'datetime-local', 'month', 'week', 'color', 'range']);
13
+ /** Roles whose `aria-checked` is a checked state, as the web reads them. */
14
+ const CHECKED_ROLES = new Set(['checkbox', 'menuitemcheckbox', 'menuitemradio', 'option', 'radio', 'switch', 'treeitem']);
15
+ /** Widgets that take typed keys as typeahead: a key moves to the item it starts. */
16
+ const TYPEAHEAD_ROLES = new Set(['listbox', 'option', 'tree', 'treeitem', 'menu', 'menubar', 'menuitem', 'combobox', 'grid', 'gridcell', 'radiogroup', 'tablist', 'tab']);
17
+ /** Of those, the ones that also take typed text: digits a key at a time. */
18
+ const TYPED_PICKER_TYPES = new Set(['date', 'time', 'datetime-local', 'month', 'week']);
19
+ /** What a click inside a label presses instead of the label's own control. */
20
+ const INTERACTIVE = 'a,button,input,select,textarea,summary,[contenteditable],[role="button"],[role="link"]';
21
+ /** The node's element. A node the document dropped fails as one: the harness locates it again, where a reason would only wait out the deadline. */
22
+ const live = () => {
23
+ if (owner?.isConnected !== true)
24
+ throw new Error('Node is detached: it is no longer in the document');
25
+ return owner;
26
+ };
27
+ /** An input's type as the browser reads it (an unknown type is `text`); another element's type attribute. */
28
+ const typeOf = (target) => (target instanceof HTMLInputElement ? target.type : (target.getAttribute('type') ?? '').toLowerCase());
29
+ /** The nearest element matching `selector`, from `target` up through the hosts of the shadow roots it sits in: `closest` stops at a root. */
30
+ const above = (target, selector) => {
31
+ for (let at = target; at !== null;) {
32
+ const found = at.closest(selector);
33
+ if (found !== null)
34
+ return found;
35
+ const root = at.getRootNode();
36
+ at = root instanceof ShadowRoot ? root.host : null;
37
+ }
38
+ return null;
39
+ };
40
+ /**
41
+ * Whether the element is disabled, as Chromium's tree and Playwright read
42
+ * it: its nearest form control's :disabled (a disabled fieldset disables its
43
+ * controls, not a link in it), or the nearest aria-disabled attribute above
44
+ * it saying true (a nearer aria-disabled="false" enables it again).
45
+ */
46
+ const isDisabled = (target) => {
47
+ const control = target.closest('button, input, select, textarea, option, optgroup');
48
+ if (control?.matches(':disabled') === true)
49
+ return true;
50
+ return above(target, '[aria-disabled]')?.getAttribute('aria-disabled')?.toLowerCase() === 'true';
51
+ };
52
+ /**
53
+ * Whether an `inert` element holds the element in the tree as rendered:
54
+ * through the slot it is assigned to and the shadow host of each root it
55
+ * sits in. An open modal dialog is in the top layer, out of reach of an
56
+ * `inert` above it, though not of its own. What a modal dialog makes inert
57
+ * has no attribute to show it, and only Chromium orders the top layer:
58
+ * `waitReady` asks it.
59
+ */
60
+ const isInert = (target) => {
61
+ for (let at = target; at !== null;) {
62
+ if (at.hasAttribute('inert'))
63
+ return true;
64
+ if (at.matches('dialog:modal'))
65
+ return false;
66
+ const root = at.getRootNode();
67
+ at = at.assignedSlot ?? at.parentElement ?? (root instanceof ShadowRoot ? root.host : null);
68
+ }
69
+ return false;
70
+ };
71
+ /** Whether the element holds focus within its own document or shadow root. */
72
+ const holdsFocus = (target) => {
73
+ const root = target.getRootNode();
74
+ return (root instanceof Document || root instanceof ShadowRoot) && root.activeElement === target;
75
+ };
76
+ /**
77
+ * The index of the option `wanted` names, or a reason it cannot be chosen. A
78
+ * label matches an option's label, which is its text unless it has a label
79
+ * attribute: then its text never matches, as on the web.
80
+ */
81
+ const findOption = (select, wanted) => {
82
+ const options = [...select.options];
83
+ const byLabel = options.findIndex((option) => option.label === wanted.label);
84
+ let index;
85
+ if (wanted.index !== undefined)
86
+ index = wanted.index >= 0 && wanted.index < options.length ? wanted.index : -1;
87
+ else if (wanted.value !== undefined)
88
+ index = options.findIndex((option) => option.value === wanted.value);
89
+ else
90
+ index = byLabel >= 0 ? byLabel : options.findIndex((option) => !option.hasAttribute('label') && option.text.trim() === wanted.label);
91
+ const option = options[index];
92
+ if (option === undefined) {
93
+ const byValue = wanted.label !== undefined && options.some((each) => each.value === wanted.label) ? `; an option has the value ${JSON.stringify(wanted.label)}: pass { value: ${JSON.stringify(wanted.label)} }` : '';
94
+ return { ok: false, reason: `no option matches ${JSON.stringify(wanted)}; the options are ${options.map((each) => JSON.stringify(each.label)).join(', ')}${byValue}` };
95
+ }
96
+ // :disabled covers an option a disabled group holds.
97
+ if (option.matches(':disabled'))
98
+ return { ok: false, reason: `option ${JSON.stringify(option.label)} is disabled` };
99
+ return { index };
100
+ };
101
+ const fire = (target) => {
102
+ target.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
103
+ target.dispatchEvent(new Event('change', { bubbles: true }));
104
+ };
105
+ const ops = {
106
+ checkConnected() {
107
+ live();
108
+ return { ok: true };
109
+ },
110
+ checkEnabled(enabled) {
111
+ const element = live();
112
+ if (enabled && isDisabled(element))
113
+ return { ok: false, reason: 'it is disabled' };
114
+ if (isInert(element))
115
+ return { ok: false, reason: 'it is inert (a modal or the app blocks it)' };
116
+ if (getComputedStyle(element).visibility !== 'visible')
117
+ return { ok: false, reason: 'it is not visible' };
118
+ return { ok: true };
119
+ },
120
+ hitTest(x, y) {
121
+ const element = live();
122
+ const root = element.getRootNode();
123
+ const hit = (root instanceof ShadowRoot ? root : document).elementFromPoint(x, y);
124
+ if (hit === null)
125
+ return { ok: false, reason: 'its centre is outside the window' };
126
+ // Walk up from the hit through slots, parents, and shadow hosts: Node.contains stops at a slot and a shadow root.
127
+ for (let at = hit; at !== null; at = at instanceof Element && at.assignedSlot !== null ? at.assignedSlot : (at.parentNode ?? (at instanceof ShadowRoot ? at.host : null))) {
128
+ if (at === element)
129
+ return { ok: true };
130
+ }
131
+ // A click inside the label of the element reaches it, unless it presses another control the label holds. Only
132
+ // the control the label activates: a link in the same label, covered, is not what the click would press.
133
+ const label = hit.closest('label');
134
+ if (label !== null && label.control === element && !label.contains(hit.closest(INTERACTIVE)))
135
+ return { ok: true };
136
+ return { ok: false, reason: `another element (${hit.tagName.toLowerCase()}${hit.id === '' ? '' : `#${hit.id}`}) would receive the click` };
137
+ },
138
+ labelPoint() {
139
+ const element = live();
140
+ if (!(element instanceof HTMLInputElement) || (element.type !== 'checkbox' && element.type !== 'radio'))
141
+ return null;
142
+ const own = element.getBoundingClientRect();
143
+ if (own.width > 0 && own.height > 0)
144
+ return null;
145
+ for (const label of element.labels ?? []) {
146
+ if (!label.checkVisibility({ visibilityProperty: true }))
147
+ continue;
148
+ label.scrollIntoView({ block: 'nearest', inline: 'nearest' });
149
+ const box = label.getBoundingClientRect();
150
+ if (box.width > 0 && box.height > 0)
151
+ return { x: Math.round(box.left + box.width / 2), y: Math.round(box.top + box.height / 2) };
152
+ }
153
+ return null;
154
+ },
155
+ scrollIntoView() {
156
+ live().scrollIntoView({ block: 'center', inline: 'center', behavior: 'instant' });
157
+ },
158
+ focus() {
159
+ const target = live();
160
+ // Whether the element took focus at all, even for a moment: an app's focus handler can send it on at once.
161
+ let took = false;
162
+ const onFocus = () => {
163
+ took = true;
164
+ };
165
+ target.addEventListener('focus', onFocus, { once: true });
166
+ if (target instanceof HTMLElement || target instanceof SVGElement)
167
+ target.focus();
168
+ target.removeEventListener('focus', onFocus);
169
+ if (holdsFocus(target))
170
+ return 'held';
171
+ // A composite widget hands focus to a part of itself (a grid row to its editor): the element holds it through
172
+ // that part, and what is typed next goes where a person who tabbed here would type.
173
+ const root = target.getRootNode();
174
+ const active = root instanceof Document || root instanceof ShadowRoot ? root.activeElement : null;
175
+ if (took && active !== null && target.contains(active))
176
+ return 'held';
177
+ return took ? 'moved' : 'none';
178
+ },
179
+ blur() {
180
+ const target = live();
181
+ if (target instanceof HTMLElement || target instanceof SVGElement)
182
+ target.blur();
183
+ },
184
+ checkEditable() {
185
+ const element = live();
186
+ const type = typeOf(element);
187
+ const field = element instanceof HTMLTextAreaElement || (element instanceof HTMLInputElement && (TEXT_INPUT_TYPES.has(type) || SET_VALUE_TYPES.has(type))) ? element : undefined;
188
+ if (field === undefined && !(element instanceof HTMLElement && element.isContentEditable))
189
+ return { ok: false, reason: 'it is not a text field' };
190
+ if (isDisabled(element))
191
+ return { ok: false, reason: 'it is disabled' };
192
+ if (isInert(element))
193
+ return { ok: false, reason: 'it is inert (a modal or the app blocks it)' };
194
+ // An editing host says so itself: it has no readOnly of its own.
195
+ if (field?.readOnly === true || (field === undefined && element.getAttribute('aria-readonly')?.toLowerCase() === 'true'))
196
+ return { ok: false, reason: 'it is read-only' };
197
+ // A value can be set on a field no user reaches; typing into one would fail on its own.
198
+ if (!element.checkVisibility({ visibilityProperty: true }))
199
+ return { ok: false, reason: 'it is not visible' };
200
+ return { ok: true };
201
+ },
202
+ setValue(value) {
203
+ const element = live();
204
+ if (!(element instanceof HTMLInputElement))
205
+ return null;
206
+ const type = typeOf(element);
207
+ const refused = { ok: false, reason: `the ${type} input does not take ${JSON.stringify(value)}` };
208
+ if (type === 'number' && value.trim() !== '' && Number.isNaN(Number(value)))
209
+ return refused;
210
+ if (!SET_VALUE_TYPES.has(type))
211
+ return null;
212
+ // As Playwright's fill: the value trimmed, a color in the lower case the input keeps, a range clamped by the input.
213
+ const set = type === 'color' ? value.trim().toLowerCase() : value.trim();
214
+ if (type !== 'range') {
215
+ // Tried on a detached input of the same type first: the field would sanitize a malformed value to "" and lose what it held.
216
+ const probe = element.ownerDocument.createElement('input');
217
+ probe.type = type;
218
+ probe.value = set;
219
+ if (probe.value !== set)
220
+ return refused;
221
+ }
222
+ element.focus();
223
+ element.value = set;
224
+ fire(element);
225
+ return { ok: true };
226
+ },
227
+ selectContents() {
228
+ const target = live();
229
+ if (target instanceof HTMLElement)
230
+ target.focus();
231
+ if (!holdsFocus(target))
232
+ return false;
233
+ if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
234
+ target.select();
235
+ return true;
236
+ }
237
+ const range = target.ownerDocument.createRange();
238
+ range.selectNodeContents(target);
239
+ const selection = target.ownerDocument.getSelection();
240
+ selection?.removeAllRanges();
241
+ selection?.addRange(range);
242
+ return true;
243
+ },
244
+ readChecked() {
245
+ const target = live();
246
+ if (target instanceof HTMLInputElement && (target.type === 'checkbox' || target.type === 'radio'))
247
+ return target.checked;
248
+ if (!CHECKED_ROLES.has(target.getAttribute('role') ?? ''))
249
+ return null;
250
+ const aria = target.getAttribute('aria-checked');
251
+ // A mixed checkbox is not checked: check() clicks it.
252
+ return aria === 'true' ? true : aria === 'false' || aria === 'mixed' ? false : null;
253
+ },
254
+ checkSelect(wanted) {
255
+ const element = live();
256
+ if (!(element instanceof HTMLSelectElement))
257
+ return { ok: false, reason: 'it is not a <select>' };
258
+ if (isDisabled(element))
259
+ return { ok: false, reason: 'it is disabled' };
260
+ if (isInert(element))
261
+ return { ok: false, reason: 'it is inert (a modal or the app blocks it)' };
262
+ if (!element.checkVisibility({ visibilityProperty: true }))
263
+ return { ok: false, reason: 'it is not visible' };
264
+ const found = findOption(element, wanted);
265
+ return 'index' in found ? { ok: true } : found;
266
+ },
267
+ selectOption(wanted) {
268
+ const element = live();
269
+ if (!(element instanceof HTMLSelectElement))
270
+ return { ok: false, reason: 'it is not a <select>' };
271
+ const found = findOption(element, wanted);
272
+ if (!('index' in found))
273
+ return found;
274
+ element.focus();
275
+ element.selectedIndex = found.index;
276
+ fire(element);
277
+ return { ok: true };
278
+ },
279
+ checkFileInput() {
280
+ const element = live();
281
+ if (!(element instanceof HTMLInputElement) || element.type !== 'file')
282
+ return { ok: false, reason: 'it is not a file input' };
283
+ if (isDisabled(element))
284
+ return { ok: false, reason: 'it is disabled' };
285
+ if (isInert(element))
286
+ return { ok: false, reason: 'it is inert (a modal or the app blocks it)' };
287
+ return { ok: true };
288
+ },
289
+ takesFiles(count) {
290
+ const input = live();
291
+ if (count > 1 && input instanceof HTMLInputElement && !input.multiple)
292
+ return { ok: false, reason: `the file input takes one file, not ${count}: it has no multiple attribute` };
293
+ return { ok: true };
294
+ },
295
+ clearFiles() {
296
+ const input = live();
297
+ if (!(input instanceof HTMLInputElement) || input.files === null || input.files.length === 0)
298
+ return;
299
+ input.value = '';
300
+ fire(input);
301
+ },
302
+ isNativeRadio() {
303
+ const target = live();
304
+ return target instanceof HTMLInputElement && target.type === 'radio';
305
+ },
306
+ isFileInput() {
307
+ const target = live();
308
+ return target instanceof HTMLInputElement && target.type === 'file';
309
+ },
310
+ readStyle(names) {
311
+ const computed = getComputedStyle(live());
312
+ return Object.fromEntries(names.map((property) => [property, computed.getPropertyValue(property)]));
313
+ },
314
+ // Measured from the boxes rather than with an IntersectionObserver, which answers at the page's next frame: a
315
+ // window the app keeps hidden draws none.
316
+ viewportIntersection() {
317
+ const target = live();
318
+ const box = target.getBoundingClientRect();
319
+ if (box.width <= 0 || box.height <= 0)
320
+ return { intersects: false, ratio: 0 };
321
+ let { left, top, right, bottom } = box;
322
+ const clip = (by, x, y) => {
323
+ if (x)
324
+ [left, right] = [Math.max(left, by.left), Math.min(right, by.right)];
325
+ if (y)
326
+ [top, bottom] = [Math.max(top, by.top), Math.min(bottom, by.bottom)];
327
+ };
328
+ // A fixed box is clipped by the window alone; an absolute one by the scrollers that position it.
329
+ let position = getComputedStyle(target).position;
330
+ for (let parent = target.parentElement ?? target.getRootNode().host ?? null; parent !== null && position !== 'fixed'; parent = parent.parentElement ?? parent.getRootNode().host ?? null) {
331
+ const style = getComputedStyle(parent);
332
+ if (position !== 'absolute' || style.position !== 'static') {
333
+ const inner = parent.getBoundingClientRect();
334
+ const edge = { left: inner.left + parent.clientLeft, top: inner.top + parent.clientTop, right: inner.left + parent.clientLeft + parent.clientWidth, bottom: inner.top + parent.clientTop + parent.clientHeight };
335
+ if (parent !== document.documentElement && parent !== document.body)
336
+ clip(edge, style.overflowX !== 'visible', style.overflowY !== 'visible');
337
+ position = style.position;
338
+ }
339
+ }
340
+ clip({ left: 0, top: 0, right: innerWidth, bottom: innerHeight }, true, true);
341
+ const inside = Math.max(0, right - left) * Math.max(0, bottom - top);
342
+ const ratio = Math.min(1, inside / (box.width * box.height));
343
+ return { intersects: inside > 0, ratio };
344
+ },
345
+ takesText() {
346
+ const active = live();
347
+ if (active.tagName === 'IFRAME' || active.tagName === 'WEBVIEW')
348
+ return true;
349
+ if (active instanceof HTMLElement && active.isContentEditable)
350
+ return true;
351
+ if (active instanceof HTMLTextAreaElement)
352
+ return !active.readOnly && !active.disabled;
353
+ if (TYPEAHEAD_ROLES.has(active.getAttribute('role') ?? ''))
354
+ return true;
355
+ // A date or time input takes typed digits; a range or color picker takes none.
356
+ if (active instanceof HTMLInputElement)
357
+ return (TEXT_INPUT_TYPES.has(typeOf(active)) || TYPED_PICKER_TYPES.has(typeOf(active))) && !active.readOnly && !active.disabled;
358
+ // Keys to the page itself, a select, a button, or a link (HTML or SVG) are lost or click. Any other element the app made
359
+ // focusable (a canvas, a widget with a tabindex and key handlers of its own) opted into keys, as on the web.
360
+ if (active === active.ownerDocument.body || active === active.ownerDocument.documentElement)
361
+ return false;
362
+ return !(active instanceof HTMLSelectElement || active instanceof HTMLButtonElement || active instanceof HTMLAnchorElement || active instanceof SVGAElement);
363
+ },
364
+ };
365
+ // TypeScript cannot tie `args` to the method `name` picks; `NodeOps` holds the two together for callers.
366
+ const run = ops[name];
367
+ return run.apply(ops, args);
368
+ }
369
+ /**
370
+ * The focused element under a document or shadow root, through every open
371
+ * shadow root; it stops at a closed root's host. Its answer is a handle, which
372
+ * only the protocol can hold, so it is no `NodeOps` entry: those answer in
373
+ * JSON. Sent as source text: self-contained.
374
+ */
375
+ export function activeUnder(root) {
376
+ let active = root instanceof Document || root instanceof ShadowRoot ? root.activeElement : null;
377
+ while (active?.shadowRoot?.activeElement != null)
378
+ active = active.shadowRoot.activeElement;
379
+ return active;
380
+ }
381
+ /**
382
+ * The backend-resolvable elements a CSS selector matches in the document and
383
+ * in each open shadow root, one root at a time as `querySelectorAll` does. It
384
+ * never enters a frame. Sent as source text: self-contained.
385
+ */
386
+ export function queryAll(selector) {
387
+ const found = [];
388
+ const visit = (root) => {
389
+ found.push(...root.querySelectorAll(selector));
390
+ for (const element of root.querySelectorAll('*'))
391
+ if (element.shadowRoot !== null)
392
+ visit(element.shadowRoot);
393
+ };
394
+ visit(document);
395
+ return found;
396
+ }
397
+ /** Resolves after the next frame renders, or at once in a hidden window, which renders none. Sent as source text: self-contained. */
398
+ export function nextFrame() {
399
+ if (document.visibilityState === 'hidden')
400
+ return Promise.resolve();
401
+ return new Promise((resolve) => requestAnimationFrame(() => setTimeout(resolve, 0)));
402
+ }
403
+ /** The window's inner size in CSS pixels. Sent as source text: self-contained. */
404
+ export function viewportSize() {
405
+ return { width: innerWidth, height: innerHeight };
406
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `@e2e-dev/electron` public surface: the `electron()` engine factory, the
3
+ * `electron` fixture types, and `test`, `describe`, and the hooks typed with
4
+ * that fixture. `expect`, `credentials`, and `secrets` still come from
5
+ * `e2e`. Without `e2e` installed, `electron()` still loads and `test` throws
6
+ * when used.
7
+ */
8
+ import type { ElectronFixtures } from './fixtures.ts';
9
+ export * from './engine-entry.ts';
10
+ /** The engine factory as the default export: what `e2e mcp` calls when `open_session` names this package as its `engine`. */
11
+ export { default } from './engine-entry.ts';
12
+ /**
13
+ * `test` typed with this engine's contributed `electron` fixture. The same
14
+ * runtime `test` as `e2e`'s; only the fixture types differ.
15
+ */
16
+ export declare const test: import("e2e").TestAPI<import("e2e").TestFixtures & ElectronFixtures, import("e2e").WorkerFixtures>;
17
+ /** `describe` and the hooks, the same functions as `test.describe` and `test.beforeEach`, typed with the `electron` fixture. */
18
+ export declare const describe: import("e2e").DescribeAPI, beforeEach: (fn: import("e2e").TestHookFn<import("e2e").TestFixtures & ElectronFixtures & import("e2e").WorkerFixtures>) => void, afterEach: (fn: import("e2e").TestHookFn<import("e2e").TestFixtures & ElectronFixtures & import("e2e").WorkerFixtures>) => void, beforeAll: (fn: import("e2e").TestHookFn<import("e2e").WorkerFixtures>) => void, afterAll: (fn: import("e2e").TestHookFn<import("e2e").WorkerFixtures>) => void;