@e2e-dev/notte 0.0.0-stage → 0.0.2-nightly-20261119145058
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 +202 -0
- package/NOTICE +5 -0
- package/README.md +41 -2
- package/dist/.build.json +1 -0
- package/dist/client.d.ts +44 -0
- package/dist/client.js +66 -0
- package/dist/env.d.ts +2 -0
- package/dist/env.js +5 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -0
- package/dist/ledger.d.ts +19 -0
- package/dist/ledger.js +63 -0
- package/dist/provider.d.ts +21 -0
- package/dist/provider.js +127 -0
- package/package.json +65 -3
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
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @e2e-dev/notte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Notte](https://notte.cc) cloud browsers for [`e2e`](https://www.npmjs.com/package/e2e):
|
|
4
|
+
`web({ browser: notte() })` runs a web target in Notte's hosted browser sessions.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install --save-dev @e2e-dev/notte notte-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts title="e2e.config.ts"
|
|
15
|
+
import type { E2EConfig } from 'e2e';
|
|
16
|
+
import { web } from '@e2e-dev/web';
|
|
17
|
+
import { notte } from '@e2e-dev/notte';
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
targets: [{ engine: web({ browser: notte({ solve_captchas: true }) }), app: { url: 'https://staging.example.com' } }],
|
|
21
|
+
workers: 4,
|
|
22
|
+
} satisfies E2EConfig;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`NOTTE_API_KEY` comes from the run's environment, and `NOTTE_API_URL` when
|
|
26
|
+
set. `notte(options)` takes Notte's start-session body (`solve_captchas`,
|
|
27
|
+
`proxies`, `browser_type`, `idle_timeout_minutes`, `max_duration_minutes`,
|
|
28
|
+
`viewport_width`, `viewport_height`, `profile`, ...), less `cdp_url` and the
|
|
29
|
+
managed authentication fields (`auth_ids`, `auth_retry`,
|
|
30
|
+
`wait_for_authentication`).
|
|
31
|
+
Each test attempt gets a fresh session, stopped when the attempt ends; a
|
|
32
|
+
Notte session refuses new browser contexts, so the provider leases in
|
|
33
|
+
`attempt` scope only. When the run ends, it stops any session a dead worker
|
|
34
|
+
left. Each session's console link is logged (the session id alone when
|
|
35
|
+
`NOTTE_API_URL` is set), and `browser.waitForDownload` reads files back from
|
|
36
|
+
the session's storage.
|
|
37
|
+
|
|
38
|
+
Full documentation lives at [e2e.com/docs/integrations/notte](https://e2e.com/docs/integrations/notte).
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
Apache-2.0
|
package/dist/.build.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"0.0.2-nightly-20261119145058"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** The slice of the Notte SDK the provider uses, loaded on first use so a config load never pays for it. */
|
|
2
|
+
import type { ApiSessionStartRequest } from 'notte-sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Notte's start-session body, less the fields a browser provider cannot
|
|
5
|
+
* serve: `cdp_url` (a browser from another provider) and managed
|
|
6
|
+
* authentication (`auth_ids`, `auth_retry`, `wait_for_authentication`),
|
|
7
|
+
* which returns the session before it can be attached to.
|
|
8
|
+
*/
|
|
9
|
+
export type NotteSessionParams = Omit<ApiSessionStartRequest, 'cdp_url' | 'auth_ids' | 'auth_retry' | 'wait_for_authentication'>;
|
|
10
|
+
interface NotteSession {
|
|
11
|
+
readonly sessionId: string;
|
|
12
|
+
/** Undefined when Notte gave the session no CDP URL, in the start response or its debug info. */
|
|
13
|
+
readonly cdpUrl: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
/** A file the session's browser downloaded, as Notte's file storage lists it. */
|
|
16
|
+
export interface NotteDownload {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly filename: string;
|
|
19
|
+
readonly createdAt: string;
|
|
20
|
+
}
|
|
21
|
+
export interface NotteSessions {
|
|
22
|
+
/**
|
|
23
|
+
* Starts a session. The request is never aborted: a cancelled request would
|
|
24
|
+
* leave a session Notte started that nobody knows the id of, so the caller
|
|
25
|
+
* waits for it and stops it instead. A start response without a CDP URL
|
|
26
|
+
* falls back to the session's debug info, as the SDK's own `Session` does.
|
|
27
|
+
*/
|
|
28
|
+
start(params: NotteSessionParams): Promise<NotteSession>;
|
|
29
|
+
/** Stops the session; one Notte already closed counts as stopped. Resolves to whether Notte still had it open. */
|
|
30
|
+
stop(sessionId: string, signal: AbortSignal): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Every file the session's browser downloaded, oldest first, read page by
|
|
33
|
+
* page. Files that share a time come out in reverse of Notte's listing
|
|
34
|
+
* order, which is newest first. Notte collects a finished download into
|
|
35
|
+
* the session's file storage when this lists it, after the session's
|
|
36
|
+
* downloads settle.
|
|
37
|
+
*/
|
|
38
|
+
downloads(sessionId: string, signal: AbortSignal): Promise<NotteDownload[]>;
|
|
39
|
+
/** The bytes of one file in the session's storage. */
|
|
40
|
+
readFile(sessionId: string, fileId: string, signal: AbortSignal): Promise<Uint8Array>;
|
|
41
|
+
}
|
|
42
|
+
/** Notte sessions for one API key and API URL, through the SDK. */
|
|
43
|
+
export declare function notteSessions(apiKey: string, baseUrl: string | undefined): NotteSessions;
|
|
44
|
+
export {};
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** The slice of the Notte SDK the provider uses, loaded on first use so a config load never pays for it. */
|
|
2
|
+
/** Whether a failed stop says the session had already ended, the way the SDK's own `Session.stop` reads it. */
|
|
3
|
+
function alreadyClosed(cause, statusCode) {
|
|
4
|
+
if (statusCode === 404)
|
|
5
|
+
return true;
|
|
6
|
+
const text = (cause instanceof Error ? cause.message : String(cause)).toLowerCase();
|
|
7
|
+
return text.includes('already stopped') || text.includes('already closed');
|
|
8
|
+
}
|
|
9
|
+
/** How many files one `files.list` request asks for: Notte's own page size. */
|
|
10
|
+
const FILES_PAGE = 100;
|
|
11
|
+
/** Notte sessions for one API key and API URL, through the SDK. */
|
|
12
|
+
export function notteSessions(apiKey, baseUrl) {
|
|
13
|
+
const sdk = import('notte-sdk').then((module) => ({
|
|
14
|
+
client: new module.NotteClient({ apiKey, ...(baseUrl === undefined ? {} : { baseUrl }) }),
|
|
15
|
+
NotteAPIError: module.NotteAPIError,
|
|
16
|
+
}));
|
|
17
|
+
return {
|
|
18
|
+
async start(params) {
|
|
19
|
+
const { client } = await sdk;
|
|
20
|
+
const session = await client.sessions.start(params);
|
|
21
|
+
if (typeof session.cdp_url === 'string' && session.cdp_url !== '')
|
|
22
|
+
return { sessionId: session.session_id, cdpUrl: session.cdp_url };
|
|
23
|
+
const debug = await client.sessions.debugInfo(session.session_id, { signal: AbortSignal.timeout(30_000) }).catch(() => undefined);
|
|
24
|
+
const cdpUrl = debug?.ws.cdp;
|
|
25
|
+
return { sessionId: session.session_id, cdpUrl: typeof cdpUrl === 'string' && cdpUrl !== '' ? cdpUrl : undefined };
|
|
26
|
+
},
|
|
27
|
+
async stop(sessionId, signal) {
|
|
28
|
+
const { client, NotteAPIError } = await sdk;
|
|
29
|
+
try {
|
|
30
|
+
const session = await client.sessions.stop(sessionId, undefined, { signal });
|
|
31
|
+
if (session.status !== 'closed')
|
|
32
|
+
throw new Error(`session ${sessionId} is still ${session.status} after stop`);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch (cause) {
|
|
36
|
+
if (alreadyClosed(cause, cause instanceof NotteAPIError ? cause.statusCode : undefined))
|
|
37
|
+
return false;
|
|
38
|
+
throw cause;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
async downloads(sessionId, signal) {
|
|
42
|
+
const { client } = await sdk;
|
|
43
|
+
const listed = new Map();
|
|
44
|
+
for (let offset = 0;;) {
|
|
45
|
+
const page = await client.files.list(sessionId, { source: 'session_download', limit: FILES_PAGE, offset }, { signal });
|
|
46
|
+
// A file stored between two pages shifts the newest-first listing down: the next page repeats one, never skips one.
|
|
47
|
+
for (const file of page.files)
|
|
48
|
+
if (!listed.has(file.id))
|
|
49
|
+
listed.set(file.id, { id: file.id, filename: file.filename, createdAt: file.created_at });
|
|
50
|
+
offset += page.files.length;
|
|
51
|
+
if (page.files.length === 0 || offset >= page.total)
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
// Reversed, then a stable sort by time: files that share a time come out in reverse of Notte's listing order.
|
|
55
|
+
return [...listed.values()].toReversed().toSorted((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
|
|
56
|
+
},
|
|
57
|
+
async readFile(sessionId, fileId, signal) {
|
|
58
|
+
const { client } = await sdk;
|
|
59
|
+
// The generated client types the body `unknown`; the typed `Files(id).download` takes no abort signal.
|
|
60
|
+
const body = await client.files.download(sessionId, fileId, { signal });
|
|
61
|
+
if (!(body instanceof Blob))
|
|
62
|
+
throw new Error(`Notte answered file ${fileId} of session ${sessionId} with no file body`);
|
|
63
|
+
return new Uint8Array(await body.arrayBuffer());
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
package/dist/env.d.ts
ADDED
package/dist/env.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@e2e-dev/notte` public surface: `notte()`, a browser provider that leases
|
|
3
|
+
* cloud browsers from Notte for `@e2e-dev/web`.
|
|
4
|
+
*/
|
|
5
|
+
export { notte } from './provider.ts';
|
|
6
|
+
export type { NotteOptions } from './provider.ts';
|
|
7
|
+
export type { NotteSessionParams } from './client.ts';
|
package/dist/index.js
ADDED
package/dist/ledger.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sessions a run holds open, one marker file per session under the
|
|
3
|
+
* system temp directory. Notte sessions carry no tags to find a run's by, but
|
|
4
|
+
* the runner and its workers share one machine: a worker writes a marker when
|
|
5
|
+
* it starts a session and removes it once the session is stopped, so the
|
|
6
|
+
* markers left at the end of the run name the sessions of workers that died.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Records that the run started `sessionId` for `targetName`, before the
|
|
10
|
+
* session is handed to the engine. Rejects when the marker cannot be written,
|
|
11
|
+
* so the caller stops the session rather than run one the sweep cannot find.
|
|
12
|
+
*/
|
|
13
|
+
export declare function remember(runId: string, targetName: string, sessionId: string): Promise<void>;
|
|
14
|
+
/** Records that `sessionId` was stopped; called only after Notte confirmed it. */
|
|
15
|
+
export declare function forget(runId: string, targetName: string, sessionId: string): Promise<void>;
|
|
16
|
+
/** The sessions the run started for `targetName` and never recorded as stopped. Rejects on any read error but a missing directory. */
|
|
17
|
+
export declare function remembered(runId: string, targetName: string): Promise<string[]>;
|
|
18
|
+
/** Removes the target's directory and then the run's, each only once empty, so a marker kept for a failed stop survives. */
|
|
19
|
+
export declare function prune(runId: string, targetName: string): Promise<void>;
|
package/dist/ledger.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sessions a run holds open, one marker file per session under the
|
|
3
|
+
* system temp directory. Notte sessions carry no tags to find a run's by, but
|
|
4
|
+
* the runner and its workers share one machine: a worker writes a marker when
|
|
5
|
+
* it starts a session and removes it once the session is stopped, so the
|
|
6
|
+
* markers left at the end of the run name the sessions of workers that died.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { mkdir, readdir, rm, rmdir, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { tmpdir } from 'node:os';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
/** A session id as a file name: what Notte issues, never anything that could leave the run's directory. */
|
|
13
|
+
const SESSION_ID = /^[A-Za-z0-9-]{1,128}$/;
|
|
14
|
+
/** The run's markers for one target: a path built from ids, never trusted as one. */
|
|
15
|
+
function dirFor(runId, targetName) {
|
|
16
|
+
const run = runId.replace(/[^A-Za-z0-9_-]/g, '_');
|
|
17
|
+
const target = createHash('sha256').update(targetName).digest('hex').slice(0, 16);
|
|
18
|
+
return path.join(tmpdir(), 'e2e-notte', run, target);
|
|
19
|
+
}
|
|
20
|
+
/** The marker of one session; an id Notte would not issue is refused rather than written. */
|
|
21
|
+
function markerFor(runId, targetName, sessionId) {
|
|
22
|
+
if (!SESSION_ID.test(sessionId))
|
|
23
|
+
throw new Error(`session id ${JSON.stringify(sessionId)} is not one Notte issues`);
|
|
24
|
+
return path.join(dirFor(runId, targetName), sessionId);
|
|
25
|
+
}
|
|
26
|
+
/** Whether a filesystem error says the path does not exist. */
|
|
27
|
+
function isMissing(cause) {
|
|
28
|
+
return cause instanceof Error && 'code' in cause && cause.code === 'ENOENT';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Records that the run started `sessionId` for `targetName`, before the
|
|
32
|
+
* session is handed to the engine. Rejects when the marker cannot be written,
|
|
33
|
+
* so the caller stops the session rather than run one the sweep cannot find.
|
|
34
|
+
*/
|
|
35
|
+
export async function remember(runId, targetName, sessionId) {
|
|
36
|
+
const marker = markerFor(runId, targetName, sessionId);
|
|
37
|
+
await mkdir(path.dirname(marker), { recursive: true, mode: 0o700 });
|
|
38
|
+
await writeFile(marker, '', { mode: 0o600 });
|
|
39
|
+
}
|
|
40
|
+
/** Records that `sessionId` was stopped; called only after Notte confirmed it. */
|
|
41
|
+
export async function forget(runId, targetName, sessionId) {
|
|
42
|
+
await rm(markerFor(runId, targetName, sessionId), { force: true });
|
|
43
|
+
}
|
|
44
|
+
/** The sessions the run started for `targetName` and never recorded as stopped. Rejects on any read error but a missing directory. */
|
|
45
|
+
export async function remembered(runId, targetName) {
|
|
46
|
+
const entries = await readdir(dirFor(runId, targetName), { withFileTypes: true }).catch((cause) => {
|
|
47
|
+
if (isMissing(cause))
|
|
48
|
+
return [];
|
|
49
|
+
throw cause;
|
|
50
|
+
});
|
|
51
|
+
return entries.flatMap((entry) => (entry.isFile() && SESSION_ID.test(entry.name) ? [entry.name] : []));
|
|
52
|
+
}
|
|
53
|
+
/** Removes the target's directory and then the run's, each only once empty, so a marker kept for a failed stop survives. */
|
|
54
|
+
export async function prune(runId, targetName) {
|
|
55
|
+
const dir = dirFor(runId, targetName);
|
|
56
|
+
for (const empty of [dir, path.dirname(dir)]) {
|
|
57
|
+
await rmdir(empty).catch((cause) => {
|
|
58
|
+
if (isMissing(cause) || (cause instanceof Error && 'code' in cause && (cause.code === 'ENOTEMPTY' || cause.code === 'EEXIST')))
|
|
59
|
+
return;
|
|
60
|
+
throw cause;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Notte's cloud browsers as a `BrowserProvider` for the web engine. */
|
|
2
|
+
import { type BrowserProvider } from '@e2e-dev/web';
|
|
3
|
+
import { type NotteSessionParams } from './client.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Notte's start-session body as it is: `solve_captchas`, `proxies`,
|
|
6
|
+
* `browser_type`, `idle_timeout_minutes`, `max_duration_minutes`,
|
|
7
|
+
* `viewport_width`, `viewport_height`, `profile`, `user_agent`, ...
|
|
8
|
+
*/
|
|
9
|
+
export type NotteOptions = NotteSessionParams;
|
|
10
|
+
/**
|
|
11
|
+
* Notte cloud browsers for `web({ browser: notte() })`: a fresh session per
|
|
12
|
+
* test attempt, started when the attempt starts and stopped when it ends.
|
|
13
|
+
* The scope is always `attempt`: a Notte session owns its one browser
|
|
14
|
+
* context and refuses `Target.createBrowserContext`, which a shared
|
|
15
|
+
* per-worker browser needs to keep tests apart. When the run ends, `sweep`
|
|
16
|
+
* stops the sessions of workers that died before they could, and Notte ends
|
|
17
|
+
* any session the run itself left after `idle_timeout_minutes`.
|
|
18
|
+
* `NOTTE_API_KEY` comes from the run's environment, and `NOTTE_API_URL`
|
|
19
|
+
* when set.
|
|
20
|
+
*/
|
|
21
|
+
export declare function notte(options?: NotteOptions): BrowserProvider;
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** Notte's cloud browsers as a `BrowserProvider` for the web engine. */
|
|
2
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
3
|
+
import { releaseEach } from '@e2e-dev/web';
|
|
4
|
+
import { envValue } from './env.js';
|
|
5
|
+
import { forget, prune, remember, remembered } from './ledger.js';
|
|
6
|
+
import { notteSessions } from './client.js';
|
|
7
|
+
const NOTTE_API_KEY = 'NOTTE_API_KEY';
|
|
8
|
+
const NOTTE_API_URL = 'NOTTE_API_URL';
|
|
9
|
+
/**
|
|
10
|
+
* Where the engine asks the browser to save downloads. Notte saves every
|
|
11
|
+
* download of a session under `/tmp/session-downloads/<session id>` whatever
|
|
12
|
+
* path a client names, and collects it into the session's file storage.
|
|
13
|
+
*/
|
|
14
|
+
const DOWNLOADS_DIR = '/tmp/session-downloads';
|
|
15
|
+
/** How often `downloads.read` asks Notte again for a download it has not collected yet. */
|
|
16
|
+
const DOWNLOAD_POLL_MS = 500;
|
|
17
|
+
/** An error's message, or the thrown value as text. */
|
|
18
|
+
const messageOf = (cause) => (cause instanceof Error ? cause.message : String(cause));
|
|
19
|
+
/** The Notte console page of one session, which needs a console sign-in rather than a token. */
|
|
20
|
+
const consoleUrl = (sessionId) => `https://console.notte.cc/sessions/${sessionId}`;
|
|
21
|
+
/**
|
|
22
|
+
* Notte cloud browsers for `web({ browser: notte() })`: a fresh session per
|
|
23
|
+
* test attempt, started when the attempt starts and stopped when it ends.
|
|
24
|
+
* The scope is always `attempt`: a Notte session owns its one browser
|
|
25
|
+
* context and refuses `Target.createBrowserContext`, which a shared
|
|
26
|
+
* per-worker browser needs to keep tests apart. When the run ends, `sweep`
|
|
27
|
+
* stops the sessions of workers that died before they could, and Notte ends
|
|
28
|
+
* any session the run itself left after `idle_timeout_minutes`.
|
|
29
|
+
* `NOTTE_API_KEY` comes from the run's environment, and `NOTTE_API_URL`
|
|
30
|
+
* when set.
|
|
31
|
+
*/
|
|
32
|
+
export function notte(options = {}) {
|
|
33
|
+
const params = { ...options };
|
|
34
|
+
/** The storage file ids each session's downloads were already read from, so each finished download is read once. */
|
|
35
|
+
const claimed = new Map();
|
|
36
|
+
/**
|
|
37
|
+
* The bytes of one download of the lease's session, read once. Notte stores
|
|
38
|
+
* a download under the name the site suggested, not the download id the
|
|
39
|
+
* engine knows, so the file is found by `context.suggestedFilename`: the
|
|
40
|
+
* oldest unread file of that name.
|
|
41
|
+
*/
|
|
42
|
+
const readDownload = async (lease, file, context) => {
|
|
43
|
+
const client = clientFor(context.env);
|
|
44
|
+
let seen = claimed.get(lease.id);
|
|
45
|
+
if (seen === undefined) {
|
|
46
|
+
seen = new Set();
|
|
47
|
+
claimed.set(lease.id, seen);
|
|
48
|
+
}
|
|
49
|
+
for (;;) {
|
|
50
|
+
const next = (await client.downloads(lease.id, context.signal)).find((download) => !seen.has(download.id) && download.filename === context.suggestedFilename);
|
|
51
|
+
if (next !== undefined) {
|
|
52
|
+
seen.add(next.id);
|
|
53
|
+
return client.readFile(lease.id, next.id, context.signal);
|
|
54
|
+
}
|
|
55
|
+
await sleep(DOWNLOAD_POLL_MS, undefined, { signal: context.signal }).catch(() => {
|
|
56
|
+
throw new Error(`download ${file} never reached session ${lease.id}'s file storage`);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const clients = new Map();
|
|
61
|
+
const clientFor = (env) => {
|
|
62
|
+
const apiKey = envValue(env, NOTTE_API_KEY);
|
|
63
|
+
if (apiKey === undefined)
|
|
64
|
+
throw new Error(`${NOTTE_API_KEY} is not set`);
|
|
65
|
+
const baseUrl = envValue(env, NOTTE_API_URL);
|
|
66
|
+
const key = `${baseUrl ?? ''}\n${apiKey}`;
|
|
67
|
+
let client = clients.get(key);
|
|
68
|
+
if (client === undefined) {
|
|
69
|
+
client = notteSessions(apiKey, baseUrl);
|
|
70
|
+
clients.set(key, client);
|
|
71
|
+
}
|
|
72
|
+
return client;
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
name: 'notte',
|
|
76
|
+
scope: 'attempt',
|
|
77
|
+
async acquire(request) {
|
|
78
|
+
const client = clientFor(request.env);
|
|
79
|
+
request.signal.throwIfAborted();
|
|
80
|
+
const session = await client.start(params);
|
|
81
|
+
// Recorded before anything can fail, so a worker that dies from here on leaves the session to the sweep.
|
|
82
|
+
const unrecorded = await remember(request.runId, request.targetName, session.sessionId).then(() => undefined, (cause) => cause);
|
|
83
|
+
const { cdpUrl } = session;
|
|
84
|
+
if (unrecorded !== undefined || cdpUrl === undefined || request.signal.aborted) {
|
|
85
|
+
const why = unrecorded !== undefined
|
|
86
|
+
? `could not be recorded for the run's sweep (${messageOf(unrecorded)})`
|
|
87
|
+
: cdpUrl === undefined
|
|
88
|
+
? 'started without a CDP URL'
|
|
89
|
+
: 'arrived after the request was cancelled';
|
|
90
|
+
const fallback = unrecorded === undefined ? "the run's sweep or Notte's idle_timeout_minutes ends it" : "Notte's idle_timeout_minutes ends it";
|
|
91
|
+
const outcome = await client.stop(session.sessionId, AbortSignal.timeout(10_000)).then(async () => {
|
|
92
|
+
if (unrecorded === undefined)
|
|
93
|
+
await forget(request.runId, request.targetName, session.sessionId);
|
|
94
|
+
return 'stopped';
|
|
95
|
+
}, (cause) => `stopping it failed, so ${fallback}: ${messageOf(cause)}`);
|
|
96
|
+
throw new Error(`session ${session.sessionId} ${why}; ${outcome}`);
|
|
97
|
+
}
|
|
98
|
+
// Never the viewer URL: it carries tokens that act on the session, and a run's log is often public CI output.
|
|
99
|
+
request.log(envValue(request.env, NOTTE_API_URL) === undefined ? `session ${session.sessionId}, watch at ${consoleUrl(session.sessionId)}` : `session ${session.sessionId}`);
|
|
100
|
+
return { id: session.sessionId, cdpEndpoint: cdpUrl };
|
|
101
|
+
},
|
|
102
|
+
async release(lease, context) {
|
|
103
|
+
claimed.delete(lease.id);
|
|
104
|
+
await clientFor(context.env).stop(lease.id, context.signal);
|
|
105
|
+
await forget(context.runId, context.targetName, lease.id);
|
|
106
|
+
},
|
|
107
|
+
async sweep(context) {
|
|
108
|
+
const open = await remembered(context.runId, context.targetName);
|
|
109
|
+
if (open.length === 0) {
|
|
110
|
+
await prune(context.runId, context.targetName);
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
const client = clientFor(context.env);
|
|
114
|
+
const { released, failed } = await releaseEach(open, (id) => client.stop(id, context.signal));
|
|
115
|
+
const unstopped = new Set(failed.map(({ id }) => id));
|
|
116
|
+
// A marker goes only once Notte confirmed the stop; the marker of a failed stop stays.
|
|
117
|
+
await Promise.all(open.filter((id) => !unstopped.has(id)).map((id) => forget(context.runId, context.targetName, id)));
|
|
118
|
+
await prune(context.runId, context.targetName);
|
|
119
|
+
if (failed.length > 0) {
|
|
120
|
+
const notStopped = failed.map(({ id, reason }) => `${id} (${reason})`).join(', ');
|
|
121
|
+
throw new Error(`stopped ${released.length === 0 ? 'none' : released.join(', ')}; could not stop ${notStopped}, so Notte ends it after idle_timeout_minutes`);
|
|
122
|
+
}
|
|
123
|
+
return released;
|
|
124
|
+
},
|
|
125
|
+
downloads: { dir: DOWNLOADS_DIR, read: readDownload },
|
|
126
|
+
};
|
|
127
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e2e-dev/notte",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.2-nightly-20261119145058",
|
|
4
|
+
"description": "Notte cloud browsers for e2e: run web targets in Notte's hosted browser sessions",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"e2e",
|
|
7
|
+
"end-to-end",
|
|
8
|
+
"testing",
|
|
9
|
+
"ai-testing",
|
|
10
|
+
"notte",
|
|
11
|
+
"cloud-browsers",
|
|
12
|
+
"hosted-browsers",
|
|
13
|
+
"browser-automation",
|
|
14
|
+
"chromium"
|
|
15
|
+
],
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"contributors": [
|
|
18
|
+
"Andrea Pinto"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/e2e-inc/e2e.git",
|
|
23
|
+
"directory": "packages/notte"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/e2e-inc/e2e/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/e2e-inc/e2e/tree/main/packages/notte#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.16.2-nightly-20261119145058",
|
|
47
|
+
"notte-sdk": ">=1.10.0 <2",
|
|
48
|
+
"e2e": "0.24.1-nightly-20261119145058"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@e2e-dev/web": "0.16.2-nightly-20261119145058",
|
|
52
|
+
"@types/node": "26.6.6",
|
|
53
|
+
"e2e": "0.24.1-nightly-20261119145058",
|
|
54
|
+
"notte-sdk": "1.10.13",
|
|
55
|
+
"typescript": "7.0.2",
|
|
56
|
+
"vitest": "5.1.1"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": "^22.22.3 || >=24.8.0"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc --project tsconfig.build.json && node ../../scripts/stamp-dist.ts",
|
|
63
|
+
"typecheck": "tsc --noEmit",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"test:watch": "vitest",
|
|
66
|
+
"test:unit": "vitest run tests/unit"
|
|
67
|
+
}
|
|
6
68
|
}
|