@e2e-dev/lightpanda 0.0.0-stage → 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ @e2e-dev/lightpanda
2
+ Copyright 2026 TesterArmy, Inc.
3
+
4
+ This product includes software developed at TesterArmy, Inc.
5
+ (https://tester.army).
package/README.md CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
1
+ # @e2e-dev/lightpanda
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [Lightpanda](https://lightpanda.io), the open-source headless browser, for
4
+ [`e2e`](https://www.npmjs.com/package/e2e): `web({ browser: lightpanda() })`
5
+ runs a web target in a `lightpanda serve` the provider starts for each
6
+ worker slot and stops with the run.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install --save-dev @e2e-dev/lightpanda
12
+ brew install lightpanda-io/browser/lightpanda
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts title="e2e.config.ts"
18
+ import type { E2EConfig } from 'e2e';
19
+ import { web } from '@e2e-dev/web';
20
+ import { lightpanda } from '@e2e-dev/lightpanda';
21
+
22
+ export default {
23
+ targets: [{ engine: web({ browser: lightpanda({ loadResources: ['iframe'] }) }), app: { url: 'http://localhost:3000' } }],
24
+ workers: 4,
25
+ } satisfies E2EConfig;
26
+ ```
27
+
28
+ The binary comes from `binary`, `LIGHTPANDA_PATH` in the run's environment,
29
+ or `lightpanda` on `PATH`, `~/.lightpanda`, or `~/.local/bin`.
30
+ `loadResources` passes `--load-resources` for `iframe`, `image`, and
31
+ `stylesheet`; `args` adds any other `serve` flag. A server already running,
32
+ such as the Docker image in CI, is a `web({ connect })` target instead.
33
+
34
+ Lightpanda has no layout engine: locators, assertions, and agent steps on
35
+ the accessibility tree work, while drags, dialogs, downloads, scrolling,
36
+ and session restore do not. The full list lives at
37
+ [e2e.tester.army/docs/integrations/lightpanda](https://e2e.tester.army/docs/integrations/lightpanda).
38
+
39
+ ## License
40
+
41
+ Apache-2.0
@@ -0,0 +1 @@
1
+ {"version":"0.0.1"}
@@ -0,0 +1,8 @@
1
+ /** Where the `lightpanda` binary is when the config does not say. */
2
+ /**
3
+ * The binary to start: `LIGHTPANDA_PATH` when set, else `lightpanda` on
4
+ * `PATH`, then the places the install guides and agent-browser put it,
5
+ * `~/.lightpanda/lightpanda` and `~/.local/bin/lightpanda`. Throws, naming
6
+ * the install page and `LIGHTPANDA_PATH`, when none exists.
7
+ */
8
+ export declare function findBinary(env: Readonly<Record<string, string | undefined>>): string;
package/dist/binary.js ADDED
@@ -0,0 +1,38 @@
1
+ /** Where the `lightpanda` binary is when the config does not say. */
2
+ import { accessSync, constants, statSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ const INSTALL_URL = 'https://lightpanda.io/docs/open-source/installation';
5
+ const NAME = 'lightpanda';
6
+ const PATH_VARIABLE = 'LIGHTPANDA_PATH';
7
+ /**
8
+ * The binary to start: `LIGHTPANDA_PATH` when set, else `lightpanda` on
9
+ * `PATH`, then the places the install guides and agent-browser put it,
10
+ * `~/.lightpanda/lightpanda` and `~/.local/bin/lightpanda`. Throws, naming
11
+ * the install page and `LIGHTPANDA_PATH`, when none exists.
12
+ */
13
+ export function findBinary(env) {
14
+ const named = env[PATH_VARIABLE]?.trim();
15
+ if (named !== undefined && named !== '')
16
+ return named;
17
+ const onPath = (env['PATH'] ?? '').split(path.delimiter).filter((dir) => dir !== '');
18
+ const home = env['HOME'] ?? env['USERPROFILE'];
19
+ const candidates = [
20
+ ...onPath.map((dir) => path.join(dir, NAME)),
21
+ ...(home === undefined ? [] : [path.join(home, '.lightpanda', NAME), path.join(home, '.local', 'bin', NAME)]),
22
+ ];
23
+ const found = candidates.find(isExecutable);
24
+ if (found === undefined) {
25
+ throw new Error(`lightpanda is not on PATH, in ~/.lightpanda, or in ~/.local/bin; install it (${INSTALL_URL}) or set ${PATH_VARIABLE}`);
26
+ }
27
+ return found;
28
+ }
29
+ /** A regular file the process may execute; a directory of that name on `PATH` is skipped. */
30
+ function isExecutable(file) {
31
+ try {
32
+ accessSync(file, constants.X_OK);
33
+ return statSync(file).isFile();
34
+ }
35
+ catch {
36
+ return false;
37
+ }
38
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `@e2e-dev/lightpanda` public surface: `lightpanda()`, a browser provider
3
+ * that starts and stops Lightpanda CDP servers for `@e2e-dev/web`.
4
+ */
5
+ export { lightpanda } from './provider.ts';
6
+ export type { LightpandaOptions } from './provider.ts';
7
+ export type { LightpandaResource } from './server.ts';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * `@e2e-dev/lightpanda` public surface: `lightpanda()`, a browser provider
3
+ * that starts and stops Lightpanda CDP servers for `@e2e-dev/web`.
4
+ */
5
+ export { lightpanda } from './provider.js';
@@ -0,0 +1,24 @@
1
+ /** Lightpanda as a `BrowserProvider` for the web engine: one `lightpanda serve` per lease. */
2
+ import type { BrowserProvider } from '@e2e-dev/web';
3
+ import { type LightpandaResource } from './server.ts';
4
+ export interface LightpandaOptions {
5
+ /**
6
+ * The `lightpanda` binary to start: a path, or a name on `PATH`. Default
7
+ * `LIGHTPANDA_PATH` from the run's environment, else `lightpanda` on
8
+ * `PATH`, `~/.lightpanda/lightpanda`, or `~/.local/bin/lightpanda`.
9
+ */
10
+ readonly binary?: string | undefined;
11
+ /** Sub-resources the server fetches (`iframe`, `image`, `stylesheet`), which Lightpanda skips by default. */
12
+ readonly loadResources?: readonly LightpandaResource[] | undefined;
13
+ /** Further `lightpanda serve` flags, after `--host`, `--port`, and `--load-resources`. */
14
+ readonly args?: readonly string[] | undefined;
15
+ }
16
+ /**
17
+ * Lightpanda browsers for `web({ browser: lightpanda() })`: one
18
+ * `lightpanda serve` per worker slot, started on a free port when the
19
+ * engine asks and stopped when it gives the lease back. Worker scope only:
20
+ * Lightpanda does not expose the default context identity a per-attempt
21
+ * lease reattaches by. A server already running is a `web({ connect })`
22
+ * target, not a provider.
23
+ */
24
+ export declare function lightpanda(options?: LightpandaOptions): BrowserProvider;
@@ -0,0 +1,34 @@
1
+ /** Lightpanda as a `BrowserProvider` for the web engine: one `lightpanda serve` per lease. */
2
+ import { findBinary } from './binary.js';
3
+ import { serve } from './server.js';
4
+ /** How long a server gets to answer on its port before the lease fails. */
5
+ const STARTUP_TIMEOUT_MS = 10_000;
6
+ /** How long a released server gets to exit on SIGTERM before SIGKILL. */
7
+ const STOP_GRACE_MS = 5_000;
8
+ /**
9
+ * Lightpanda browsers for `web({ browser: lightpanda() })`: one
10
+ * `lightpanda serve` per worker slot, started on a free port when the
11
+ * engine asks and stopped when it gives the lease back. Worker scope only:
12
+ * Lightpanda does not expose the default context identity a per-attempt
13
+ * lease reattaches by. A server already running is a `web({ connect })`
14
+ * target, not a provider.
15
+ */
16
+ export function lightpanda(options = {}) {
17
+ const { loadResources = [], args = [] } = options;
18
+ // `release` gets back the object `acquire` returned, on the side that acquired it.
19
+ const servers = new WeakMap();
20
+ return {
21
+ name: 'lightpanda',
22
+ async acquire(request) {
23
+ const binary = options.binary ?? findBinary(request.env);
24
+ const server = await serve({ binary, env: request.env, loadResources, args, startupTimeoutMs: STARTUP_TIMEOUT_MS, signal: request.signal });
25
+ request.log(`lightpanda ${server.version} at ${server.cdpEndpoint}`);
26
+ const lease = { id: server.cdpEndpoint, cdpEndpoint: server.cdpEndpoint };
27
+ servers.set(lease, server);
28
+ return lease;
29
+ },
30
+ async release(lease) {
31
+ await servers.get(lease)?.stop(STOP_GRACE_MS);
32
+ },
33
+ };
34
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * One `lightpanda serve` process: started on a free port, awaited until its
3
+ * CDP server answers, stopped on release. The runner's managed-process
4
+ * module does the same for app commands but is not part of `e2e/engine`,
5
+ * so the process-group handling is mirrored here.
6
+ */
7
+ /** A sub-resource `lightpanda serve --load-resources` fetches; none are fetched by default. */
8
+ export type LightpandaResource = 'iframe' | 'image' | 'stylesheet';
9
+ export interface ServeOptions {
10
+ /** The binary to run, as `spawn` resolves it: a path, or a name on `env`'s `PATH`. */
11
+ readonly binary: string;
12
+ /** The run's environment, which the server starts in. */
13
+ readonly env: Readonly<Record<string, string | undefined>>;
14
+ readonly loadResources: readonly LightpandaResource[];
15
+ /** Further `serve` flags, after the ones the provider sets. */
16
+ readonly args: readonly string[];
17
+ /** How long the server gets to answer before the start fails. */
18
+ readonly startupTimeoutMs: number;
19
+ readonly signal: AbortSignal;
20
+ }
21
+ export interface LightpandaServer {
22
+ readonly cdpEndpoint: string;
23
+ /** `Lightpanda-Version` from `/json/version`, or `unknown` for a build that reports none. */
24
+ readonly version: string;
25
+ /** Ends the process: SIGTERM, then SIGKILL after `graceMs` if it is still running. Resolves once it exited. */
26
+ stop(graceMs: number): Promise<void>;
27
+ }
28
+ /**
29
+ * Starts `lightpanda serve` on a free loopback port and resolves once
30
+ * `/json/version` answers. The process runs in its own process group so a
31
+ * terminal Ctrl-C reaches the runner, which owns the interrupt, and not the
32
+ * browser; `stop` signals the group. Rejects, with the process ended, when
33
+ * it exits first (its stderr in the message), when `startupTimeoutMs`
34
+ * passes, or when `signal` aborts; either way the port is polled no longer.
35
+ */
36
+ export declare function serve(options: ServeOptions): Promise<LightpandaServer>;
package/dist/server.js ADDED
@@ -0,0 +1,137 @@
1
+ /**
2
+ * One `lightpanda serve` process: started on a free port, awaited until its
3
+ * CDP server answers, stopped on release. The runner's managed-process
4
+ * module does the same for app commands but is not part of `e2e/engine`,
5
+ * so the process-group handling is mirrored here.
6
+ */
7
+ import { spawn } from 'node:child_process';
8
+ import { createServer } from 'node:net';
9
+ const HOST = '127.0.0.1';
10
+ const POLL_MS = 50;
11
+ const PROBE_TIMEOUT_MS = 500;
12
+ /** Stderr kept for the error of a start that fails. */
13
+ const STDERR_CAP = 64 * 1024;
14
+ /**
15
+ * Starts `lightpanda serve` on a free loopback port and resolves once
16
+ * `/json/version` answers. The process runs in its own process group so a
17
+ * terminal Ctrl-C reaches the runner, which owns the interrupt, and not the
18
+ * browser; `stop` signals the group. Rejects, with the process ended, when
19
+ * it exits first (its stderr in the message), when `startupTimeoutMs`
20
+ * passes, or when `signal` aborts; either way the port is polled no longer.
21
+ */
22
+ export async function serve(options) {
23
+ const port = await freePort();
24
+ const args = [
25
+ 'serve',
26
+ '--host',
27
+ HOST,
28
+ '--port',
29
+ String(port),
30
+ ...options.loadResources.flatMap((resource) => ['--load-resources', resource]),
31
+ ...options.args,
32
+ ];
33
+ const child = spawn(options.binary, args, { env: options.env, detached: process.platform !== 'win32', stdio: ['ignore', 'ignore', 'pipe'] });
34
+ const stderr = captureStderr(child);
35
+ const exitReason = new Promise((resolve) => {
36
+ child.once('error', (cause) => resolve(`could not start ${options.binary}: ${cause.message}`));
37
+ child.once('exit', (code, signal) => {
38
+ const tail = stderr().trim();
39
+ resolve(`${options.binary} exited with ${signal ?? `code ${code}`} before its CDP server answered${tail === '' ? '' : `:\n${tail}`}`);
40
+ });
41
+ });
42
+ const cdpEndpoint = `ws://${HOST}:${port}/`;
43
+ const polling = new AbortController();
44
+ try {
45
+ const version = await Promise.race([
46
+ waitForVersion(`http://${HOST}:${port}/json/version`, options.startupTimeoutMs, AbortSignal.any([options.signal, polling.signal])),
47
+ exitReason.then((reason) => {
48
+ throw new Error(reason);
49
+ }),
50
+ ]);
51
+ return { cdpEndpoint, version, stop: (graceMs) => stop(child, graceMs) };
52
+ }
53
+ catch (cause) {
54
+ await stop(child, 1_000);
55
+ throw cause;
56
+ }
57
+ finally {
58
+ polling.abort();
59
+ }
60
+ }
61
+ /** Collects the child's stderr up to the cap; the returned function reads what was kept. */
62
+ function captureStderr(child) {
63
+ const chunks = [];
64
+ let size = 0;
65
+ child.stderr?.on('data', (chunk) => {
66
+ if (size >= STDERR_CAP)
67
+ return;
68
+ chunks.push(chunk);
69
+ size += chunk.length;
70
+ });
71
+ return () => Buffer.concat(chunks).toString('utf8');
72
+ }
73
+ /** Polls `url` until it answers with JSON, resolving to its `Lightpanda-Version`; the caller races it against the process exiting. */
74
+ async function waitForVersion(url, timeoutMs, signal) {
75
+ const deadline = Date.now() + timeoutMs;
76
+ for (;;) {
77
+ if (signal.aborted)
78
+ throw new Error('cancelled before the CDP server answered');
79
+ if (Date.now() > deadline)
80
+ throw new Error(`the CDP server did not answer on ${url} within ${timeoutMs}ms`);
81
+ try {
82
+ const response = await fetch(url, { signal: AbortSignal.any([signal, AbortSignal.timeout(PROBE_TIMEOUT_MS)]) });
83
+ if (response.ok) {
84
+ const body = await response.json();
85
+ const version = typeof body === 'object' && body !== null && 'Lightpanda-Version' in body ? body['Lightpanda-Version'] : undefined;
86
+ return typeof version === 'string' ? version : 'unknown';
87
+ }
88
+ }
89
+ catch {
90
+ // Not listening yet.
91
+ }
92
+ await new Promise((resolve) => setTimeout(resolve, POLL_MS));
93
+ }
94
+ }
95
+ /** Signals the process group, then kills it after the grace period; resolves once the process exited. */
96
+ function stop(child, graceMs) {
97
+ if (child.exitCode !== null || child.signalCode !== null || child.pid === undefined)
98
+ return Promise.resolve();
99
+ return new Promise((resolve) => {
100
+ const timer = setTimeout(() => signalProcessGroup(child, 'SIGKILL'), graceMs);
101
+ child.once('exit', () => {
102
+ clearTimeout(timer);
103
+ resolve();
104
+ });
105
+ signalProcessGroup(child, 'SIGTERM');
106
+ });
107
+ }
108
+ /**
109
+ * Sends `signal` to the whole process group behind `child` (the child alone
110
+ * on Windows, which has no process groups); a group already gone is fine.
111
+ */
112
+ function signalProcessGroup(child, signal) {
113
+ const pid = child.pid;
114
+ if (pid === undefined)
115
+ return;
116
+ try {
117
+ if (process.platform !== 'win32')
118
+ process.kill(-pid, signal);
119
+ else
120
+ child.kill(signal);
121
+ }
122
+ catch {
123
+ // process already gone
124
+ }
125
+ }
126
+ /** A loopback port nothing listens on right now. */
127
+ function freePort() {
128
+ return new Promise((resolve, reject) => {
129
+ const probe = createServer();
130
+ probe.once('error', reject);
131
+ probe.listen(0, HOST, () => {
132
+ const address = probe.address();
133
+ const port = typeof address === 'object' && address !== null ? address.port : undefined;
134
+ probe.close(() => (port === undefined ? reject(new Error('no free port')) : resolve(port)));
135
+ });
136
+ });
137
+ }
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "@e2e-dev/lightpanda",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1",
4
+ "description": "Lightpanda browsers for e2e: run web targets in the open-source headless browser, started and stopped per run",
5
+ "keywords": [
6
+ "e2e",
7
+ "end-to-end",
8
+ "testing",
9
+ "ai-testing",
10
+ "lightpanda",
11
+ "headless-browser",
12
+ "browser-automation",
13
+ "cdp"
14
+ ],
15
+ "license": "Apache-2.0",
16
+ "contributors": [
17
+ "Oskar Kwaśniewski <oskar@tester.army>",
18
+ "Szymon Rybczak <szymon@tester.army>"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/tester-army/e2e.git",
23
+ "directory": "packages/lightpanda"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/tester-army/e2e/issues"
27
+ },
28
+ "homepage": "https://github.com/tester-army/e2e/tree/main/packages/lightpanda#readme",
29
+ "publishConfig": {
30
+ "registry": "https://registry.npmjs.org/",
31
+ "access": "public",
32
+ "tag": "latest"
33
+ },
34
+ "type": "module",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ }
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "NOTICE"
44
+ ],
45
+ "peerDependencies": {
46
+ "@e2e-dev/web": ">=0.11.0 <1",
47
+ "e2e": ">=0.15.0 <1"
48
+ },
49
+ "devDependencies": {
50
+ "@e2e-dev/web": "0.15.2",
51
+ "@types/node": "26.6.2",
52
+ "e2e": "0.21.2",
53
+ "typescript": "7.0.2",
54
+ "vitest": "5.0.1"
55
+ },
56
+ "engines": {
57
+ "node": "^22.22.3 || >=24.8.0"
58
+ },
59
+ "scripts": {
60
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc --project tsconfig.build.json && node ../../scripts/stamp-dist.ts",
61
+ "typecheck": "tsc --noEmit",
62
+ "test": "vitest run",
63
+ "test:watch": "vitest",
64
+ "test:unit": "vitest run tests/unit"
65
+ }
6
66
  }