@e2e-dev/electron 0.0.1-nightly-20261130030410 → 0.1.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/README.md +8 -2
- package/dist/.build.json +1 -1
- package/dist/app-process.d.ts +3 -1
- package/dist/app-process.js +68 -18
- package/dist/dialogs.d.ts +3 -1
- package/dist/dialogs.js +10 -3
- package/dist/errors.js +4 -3
- package/dist/executable.js +65 -14
- package/dist/ffmpeg.js +2 -1
- package/dist/fields.js +80 -7
- package/dist/in-page/node-ops.js +8 -7
- package/dist/install-lock.d.ts +15 -0
- package/dist/install-lock.js +165 -0
- package/dist/install-process.d.ts +7 -0
- package/dist/install-process.js +37 -0
- package/dist/launcher.d.ts +2 -2
- package/dist/launcher.js +14 -2
- package/dist/snapshot.d.ts +69 -4
- package/dist/snapshot.js +214 -18
- package/dist/surface.js +71 -19
- package/dist/video.d.ts +13 -0
- package/dist/video.js +75 -22
- package/package.json +5 -5
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lock a process holds while it writes a project's Electron binary, so
|
|
3
|
+
* two never extract into one `electron` package at once. A file that names
|
|
4
|
+
* its holder, as `e2e` keeps for its login store (`internal/file-lock.ts`),
|
|
5
|
+
* which an engine cannot import.
|
|
6
|
+
*/
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
import { closeSync, openSync, readFileSync, readlinkSync, rmSync, statSync, utimesSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { hostname } from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { sleep } from '@e2e-dev/core/engine';
|
|
12
|
+
/** Where the lock of the `electron` package at `directory` is: beside its `install.js`, so projects that link to one package share one lock. */
|
|
13
|
+
export function installLockPath(directory) {
|
|
14
|
+
return path.join(directory, '.e2e-install.lock');
|
|
15
|
+
}
|
|
16
|
+
/** Beside install.js while its dist is incomplete, including after an interrupted extraction. */
|
|
17
|
+
export const INCOMPLETE_INSTALL = '.e2e-install.incomplete';
|
|
18
|
+
const RETRY_MS = 50;
|
|
19
|
+
/** How long a waiter watches a lock go untouched before it takes it over, whoever it names. */
|
|
20
|
+
const STALE_MS = 10_000;
|
|
21
|
+
/** What a waiter has seen of the file at `file` after one more look. */
|
|
22
|
+
function watch(seen, file) {
|
|
23
|
+
const state = lockState(file);
|
|
24
|
+
return { state, polls: state === seen.state ? seen.polls + 1 : 0 };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* True when the file's holder ran on this host and has exited, or the waiter
|
|
28
|
+
* has watched the file go unchanged for the stale bound. The bound is counted
|
|
29
|
+
* in the waiter's own polls, never read off a clock: a laptop can sleep
|
|
30
|
+
* through a download, and hosts that share a directory need not agree on the
|
|
31
|
+
* time.
|
|
32
|
+
*/
|
|
33
|
+
function abandoned(seen) {
|
|
34
|
+
return holderExited(seen.state) || seen.polls * RETRY_MS >= STALE_MS;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Waits for the lock at `lockPath` and returns its release. `onWait` is
|
|
38
|
+
* called once, when another process holds it.
|
|
39
|
+
*/
|
|
40
|
+
export async function holdInstallLock(lockPath, onWait) {
|
|
41
|
+
const token = `${holderHost()} ${process.pid} ${randomUUID()}`;
|
|
42
|
+
let lock = { state: '', polls: 0 };
|
|
43
|
+
let turn = { state: '', polls: 0 };
|
|
44
|
+
let waited = false;
|
|
45
|
+
for (;;) {
|
|
46
|
+
if (claim(lockPath, token)) {
|
|
47
|
+
const heartbeat = setInterval(() => {
|
|
48
|
+
if (readLock(lockPath) === token)
|
|
49
|
+
touch(lockPath);
|
|
50
|
+
}, STALE_MS / 4);
|
|
51
|
+
heartbeat.unref();
|
|
52
|
+
return () => {
|
|
53
|
+
clearInterval(heartbeat);
|
|
54
|
+
if (readLock(lockPath) === token)
|
|
55
|
+
rmSync(lockPath, { force: true });
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
lock = watch(lock, lockPath);
|
|
59
|
+
turn = watch(turn, `${lockPath}.break`);
|
|
60
|
+
if (abandoned(lock) && breakAbandoned(lockPath, lock, turn))
|
|
61
|
+
continue;
|
|
62
|
+
if (!waited)
|
|
63
|
+
onWait();
|
|
64
|
+
waited = true;
|
|
65
|
+
await sleep(RETRY_MS);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Creates `lockPath` holding `token`, false when it exists; a lock whose write failed is removed. */
|
|
69
|
+
function claim(lockPath, token) {
|
|
70
|
+
let fd;
|
|
71
|
+
try {
|
|
72
|
+
fd = openSync(lockPath, 'wx', 0o600);
|
|
73
|
+
}
|
|
74
|
+
catch (cause) {
|
|
75
|
+
if (cause.code === 'EEXIST')
|
|
76
|
+
return false;
|
|
77
|
+
throw cause;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
writeFileSync(fd, token);
|
|
81
|
+
}
|
|
82
|
+
catch (cause) {
|
|
83
|
+
rmSync(lockPath, { force: true });
|
|
84
|
+
throw cause;
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
closeSync(fd);
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
/** This host and, where the system has them, its pid namespace: a container on the same host sees none of the pids outside it. */
|
|
92
|
+
function holderHost() {
|
|
93
|
+
try {
|
|
94
|
+
return `${hostname()}/${readlinkSync('/proc/self/ns/pid')}`;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return hostname();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Marks the lock as held now. */
|
|
101
|
+
function touch(lockPath) {
|
|
102
|
+
const now = new Date();
|
|
103
|
+
try {
|
|
104
|
+
utimesSync(lockPath, now, now);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// Released meanwhile.
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** The lock's holder token, undefined when there is no lock. */
|
|
111
|
+
function readLock(lockPath) {
|
|
112
|
+
try {
|
|
113
|
+
return readFileSync(lockPath, 'utf8');
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** The lock's holder token and when the holder last touched it, empty when there is no lock. */
|
|
120
|
+
function lockState(lockPath) {
|
|
121
|
+
try {
|
|
122
|
+
return `${readLock(lockPath) ?? ''} ${statSync(lockPath).mtimeMs}`;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** True when the holder a lock names ran on this host and pid namespace and has exited. */
|
|
129
|
+
function holderExited(state) {
|
|
130
|
+
const [host, pid] = state.split(' ');
|
|
131
|
+
return host === holderHost() && pid !== undefined && /^\d+$/.test(pid) && !running(Number(pid));
|
|
132
|
+
}
|
|
133
|
+
/** True while `pid` exists, whoever owns it. */
|
|
134
|
+
function running(pid) {
|
|
135
|
+
try {
|
|
136
|
+
process.kill(pid, 0);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
catch (cause) {
|
|
140
|
+
// EPERM: the process exists but belongs to another user.
|
|
141
|
+
return cause.code === 'EPERM';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Removes the lock a waiter found abandoned, false when another waiter is
|
|
146
|
+
* removing one. Waiters take turns through a second file, and a waiter
|
|
147
|
+
* removes the lock only if it is still the one it watched. A turn lasts
|
|
148
|
+
* microseconds, so one left behind is abandoned by the lock's own rule.
|
|
149
|
+
*/
|
|
150
|
+
function breakAbandoned(lockPath, lock, turn) {
|
|
151
|
+
const breaker = `${lockPath}.break`;
|
|
152
|
+
if (!claim(breaker, `${holderHost()} ${process.pid} ${randomUUID()}`)) {
|
|
153
|
+
if (abandoned(turn) && lockState(breaker) === turn.state)
|
|
154
|
+
rmSync(breaker, { force: true });
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
if (lockState(lockPath) === lock.state)
|
|
159
|
+
rmSync(lockPath, { force: true });
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
rmSync(breaker, { force: true });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the `electron` package's `install.js`, named in argv[2], while it
|
|
3
|
+
* holds that package's install lock. The writer holds the lock, so a run
|
|
4
|
+
* that is killed leaves no unlocked writer behind. `install.js` leaves at
|
|
5
|
+
* once when the binary is in place: the check a process that waited needs.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the `electron` package's `install.js`, named in argv[2], while it
|
|
3
|
+
* holds that package's install lock. The writer holds the lock, so a run
|
|
4
|
+
* that is killed leaves no unlocked writer behind. `install.js` leaves at
|
|
5
|
+
* once when the binary is in place: the check a process that waited needs.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { holdInstallLock, INCOMPLETE_INSTALL, installLockPath } from './install-lock.js';
|
|
11
|
+
const [script] = process.argv.slice(2);
|
|
12
|
+
const directory = path.dirname(script);
|
|
13
|
+
const release = await holdInstallLock(installLockPath(directory), () => {
|
|
14
|
+
console.log('waiting for another run that is downloading the Electron binary');
|
|
15
|
+
});
|
|
16
|
+
// No signal handler: a cancelled run's signal ends this process at once, and its lock is taken over only once it is gone.
|
|
17
|
+
const incomplete = path.join(directory, INCOMPLETE_INSTALL);
|
|
18
|
+
const pathFile = path.join(directory, 'path.txt');
|
|
19
|
+
process.on('exit', (code) => {
|
|
20
|
+
try {
|
|
21
|
+
if (code === 0 && existsSync(pathFile))
|
|
22
|
+
rmSync(incomplete, { force: true });
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
release();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
// `install.js` writes `path.txt` last. One left by an earlier download would call this one's binary ready while it is still being written.
|
|
29
|
+
const name = existsSync(pathFile) ? readFileSync(pathFile, 'utf8').trim() : '';
|
|
30
|
+
const dist = path.join(directory, 'dist');
|
|
31
|
+
if (!name || !existsSync(path.join(dist, name))) {
|
|
32
|
+
// Linked overrides can resolve the destination while install.js is still fetching the archive.
|
|
33
|
+
mkdirSync(dist, { recursive: true });
|
|
34
|
+
writeFileSync(incomplete, '');
|
|
35
|
+
rmSync(pathFile, { force: true });
|
|
36
|
+
}
|
|
37
|
+
createRequire(script)(script);
|
package/dist/launcher.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export interface ProcessExit {
|
|
|
15
15
|
readonly code: number | null;
|
|
16
16
|
readonly signal: NodeJS.Signals | null;
|
|
17
17
|
}
|
|
18
|
-
/** The
|
|
19
|
-
export declare function
|
|
18
|
+
/** The command line an app starts with: the engine's switches, the caller's own (the app path first), then the engine's for the OS. */
|
|
19
|
+
export declare function processArguments(args: readonly string[], platform?: NodeJS.Platform): string[];
|
|
20
20
|
export declare class ElectronProcess {
|
|
21
21
|
/** The DevTools protocol of the app's browser process, over the pipe. */
|
|
22
22
|
readonly browser: Connection;
|
package/dist/launcher.js
CHANGED
|
@@ -16,8 +16,20 @@ const INSPECTOR_LISTENING = /^Debugger listening on (ws:\/\/\S+)/;
|
|
|
16
16
|
const INSPECTOR_NOISE = /^(Debugger listening on |For help, see: https:\/\/nodejs\.org\/|Debugger attached\.|Waiting for the debugger to disconnect)/;
|
|
17
17
|
/** Printed when the process is done and only the inspector's client keeps it alive. */
|
|
18
18
|
const INSPECTOR_WAITING = /Waiting for the debugger to disconnect/;
|
|
19
|
+
/** The command line an app starts with: the engine's switches, the caller's own (the app path first), then the engine's for the OS. */
|
|
20
|
+
export function processArguments(args, platform = process.platform) {
|
|
21
|
+
return [
|
|
22
|
+
...engineArguments(args, platform),
|
|
23
|
+
...args,
|
|
24
|
+
// macOS asks, in a modal alert before the app is ready, whether to reopen the windows of an app that quit uncleanly,
|
|
25
|
+
// as the engine's kills leave it: the launch would wait out its timeout. After the app's own arguments, since Electron
|
|
26
|
+
// takes the first one that is no switch as the app's path. Two arguments, both left in the app's argv, the YES no switch: macOS
|
|
27
|
+
// reads no one-argument form (`-ApplePersistenceIgnoreState=YES` sets nothing on Electron 45).
|
|
28
|
+
...(platform === 'darwin' ? ['-ApplePersistenceIgnoreState', 'YES'] : []),
|
|
29
|
+
];
|
|
30
|
+
}
|
|
19
31
|
/** The switches the engine starts every app with, before the caller's own. */
|
|
20
|
-
|
|
32
|
+
function engineArguments(args, platform) {
|
|
21
33
|
return [
|
|
22
34
|
// The main process's inspector, on a port of its own choosing, for electron.evaluate.
|
|
23
35
|
'--inspect=0',
|
|
@@ -64,7 +76,7 @@ export class ElectronProcess {
|
|
|
64
76
|
waitingHandlers = [];
|
|
65
77
|
constructor(command) {
|
|
66
78
|
killAtExit();
|
|
67
|
-
this.child = spawn(command.executable,
|
|
79
|
+
this.child = spawn(command.executable, processArguments(command.args), {
|
|
68
80
|
cwd: command.cwd,
|
|
69
81
|
env: command.env,
|
|
70
82
|
// fd 3 carries the engine's commands and fd 4 the browser's answers. stdout is not read: an unread pipe would stall the app.
|
package/dist/snapshot.d.ts
CHANGED
|
@@ -43,6 +43,12 @@ export interface SnapshotDocument {
|
|
|
43
43
|
export declare const SNAPSHOT_STYLES: readonly string[];
|
|
44
44
|
/** Elements a screenshot paints over besides a secure field's value: the nested documents the engine does not read. */
|
|
45
45
|
export declare const MASKED_TAGS: readonly string[];
|
|
46
|
+
/**
|
|
47
|
+
* An element's explicit role: the first token of its `role` that names a
|
|
48
|
+
* concrete WAI-ARIA role, as the web engine's `explicitRole` reads it (case
|
|
49
|
+
* as written), so `role="x-foo button"` is a button.
|
|
50
|
+
*/
|
|
51
|
+
export declare function explicitRoleOf(attributes: Readonly<Record<string, string>>): string | undefined;
|
|
46
52
|
/** One element's facts from the snapshot. */
|
|
47
53
|
export interface DomFacts {
|
|
48
54
|
/** The node's position in the snapshot, its document order. */
|
|
@@ -55,14 +61,36 @@ export interface DomFacts {
|
|
|
55
61
|
readonly textValue?: string;
|
|
56
62
|
/** Whether the node's text content holds anything but white space, as `textContent` reads it. */
|
|
57
63
|
readonly hasText: boolean;
|
|
64
|
+
/** An editing host's (`contenteditable`) text content, white space as written. */
|
|
65
|
+
readonly editorText?: string;
|
|
58
66
|
/** A select's value: what its first selected option submits. */
|
|
59
67
|
readonly selectValue?: string;
|
|
68
|
+
/** An option's value: its value attribute, else its text. */
|
|
69
|
+
readonly optionValue?: string;
|
|
70
|
+
/** An option that is selected now. */
|
|
71
|
+
readonly selected: boolean;
|
|
60
72
|
/** A checkbox or radio that is checked now, whatever its `checked` attribute says. */
|
|
61
73
|
readonly checked: boolean;
|
|
62
74
|
/** Device-pixel document bounds; none for a node with no layout box. */
|
|
63
75
|
readonly bounds?: readonly number[];
|
|
64
76
|
/** Its computed `visibility` is `hidden` or `collapse`. */
|
|
65
77
|
readonly invisible: boolean;
|
|
78
|
+
/** The nearest aria-disabled, its own included, says true: a nearer "false" enables it again. */
|
|
79
|
+
readonly ariaDisabled: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* A native control disabled by what holds it: for an option, a disabled
|
|
82
|
+
* optgroup; for another control in the document's tree, a disabled fieldset
|
|
83
|
+
* there holding it outside its first legend.
|
|
84
|
+
*/
|
|
85
|
+
readonly inheritsDisabled: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* A `td`'s or `th`'s role from its table, as the web engine's `tagRole`
|
|
88
|
+
* reads it: `gridcell` in a grid's or treegrid's table, else `cell`;
|
|
89
|
+
* `rowheader` or `columnheader`, or none for a lone header in a table of
|
|
90
|
+
* one row. Absent on any other element. Worked out only when asked: only
|
|
91
|
+
* an element the accessibility tree leaves out needs it.
|
|
92
|
+
*/
|
|
93
|
+
readonly cellRole?: () => string | undefined;
|
|
66
94
|
}
|
|
67
95
|
/** A password input: it reports no value and no text, and a screenshot paints it over. */
|
|
68
96
|
export declare function isSecureField(nodeName: string, attributes: Readonly<Record<string, string>>): boolean;
|
|
@@ -87,6 +115,18 @@ export declare class DomSnapshot {
|
|
|
87
115
|
private readonly blanks;
|
|
88
116
|
/** Per node, its nearest table cell, or -1. */
|
|
89
117
|
private readonly cells;
|
|
118
|
+
/**
|
|
119
|
+
* The nodes inside a shadow tree. The snapshot has no node for a shadow
|
|
120
|
+
* root: every node in one carries its type, and the root's children have
|
|
121
|
+
* the host as their parent.
|
|
122
|
+
*/
|
|
123
|
+
private readonly inShadowTree;
|
|
124
|
+
/** The nodes whose computed `visibility` is `hidden` or `collapse`. */
|
|
125
|
+
private readonly invisible;
|
|
126
|
+
/** Per element, its element children in order; built on the first table cell's read. */
|
|
127
|
+
private elementChildren;
|
|
128
|
+
/** Per table, how many rows it lists; filled as lone headers ask. */
|
|
129
|
+
private readonly rowCounts;
|
|
90
130
|
constructor(document: SnapshotDocument, strings: readonly string[]);
|
|
91
131
|
/** The element with this backend DOM node id, if the snapshot holds it. */
|
|
92
132
|
element(backendNodeId: number): DomFacts | undefined;
|
|
@@ -115,6 +155,20 @@ export declare class DomSnapshot {
|
|
|
115
155
|
* screen as the label, as the web reads it.
|
|
116
156
|
*/
|
|
117
157
|
drawnByLabel(index: number): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* The node's ancestors in its own tree, nearest first: the snapshot follows
|
|
160
|
+
* the tree as drawn, where a slotted node's parent is its slot, so the
|
|
161
|
+
* nodes of a shadow tree it is slotted through are passed over to reach its
|
|
162
|
+
* host and the host's own ancestors. A node in a shadow tree stops at its
|
|
163
|
+
* host.
|
|
164
|
+
*/
|
|
165
|
+
private ancestorsInTree;
|
|
166
|
+
/**
|
|
167
|
+
* The tree a node is in: the host of the shadow tree it is in, or -1 for
|
|
168
|
+
* the document's own. A shadow tree inside another one's is taken as the
|
|
169
|
+
* outer one: the snapshot marks the nodes of both alike.
|
|
170
|
+
*/
|
|
171
|
+
private scopeOf;
|
|
118
172
|
/**
|
|
119
173
|
* How many rendered elements a screenshot must paint over and a selector
|
|
120
174
|
* cannot reach: password inputs and nested documents inside a closed shadow
|
|
@@ -129,15 +183,26 @@ export declare class DomSnapshot {
|
|
|
129
183
|
private attributesAt;
|
|
130
184
|
private rare;
|
|
131
185
|
private indexFacts;
|
|
186
|
+
/** See `DomFacts.cellRole`; undefined for a header with no role. `withText` holds the nodes whose text is not blank. */
|
|
187
|
+
private cellRoleOf;
|
|
188
|
+
/** A node's element children, in order. */
|
|
189
|
+
private childrenOf;
|
|
190
|
+
/** How many rows `HTMLTableElement.rows` lists: the table's own rows and those of its row groups. Counted once per table. */
|
|
191
|
+
private rowCount;
|
|
192
|
+
/** See `DomFacts.ariaDisabled`. */
|
|
193
|
+
private ariaDisabled;
|
|
194
|
+
/** See `DomFacts.inheritsDisabled`. */
|
|
195
|
+
private inheritsDisabled;
|
|
132
196
|
/** The node indices whose text content holds anything but white space: every ancestor of such a text node. */
|
|
133
197
|
private nodesWithText;
|
|
134
198
|
/**
|
|
135
|
-
* Each
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* under it, with ASCII white space collapsed and no other: a no-break
|
|
199
|
+
* Each option's value, by node index: its `value` attribute or else its
|
|
200
|
+
* text, as `HTMLOptionElement.value` reads it. An option's text is all the
|
|
201
|
+
* text under it, with ASCII white space collapsed and no other: a no-break
|
|
139
202
|
* space stays one.
|
|
140
203
|
*/
|
|
204
|
+
private optionValues;
|
|
205
|
+
/** Each select's value, by node index: what its first selected option submits, as `HTMLSelectElement.value` reads it. */
|
|
141
206
|
private selectValues;
|
|
142
207
|
}
|
|
143
208
|
export {};
|