@open-wa/driver-interface 5.0.0-alpha.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.
@@ -0,0 +1,15 @@
1
+
2
+ > @open-wa/driver-interface@5.0.0-alpha.0 build /Users/Mohammed/projects/tools/wa/packages/driver-interface
3
+ > tsdown src/index.ts --format cjs
4
+
5
+ ℹ tsdown v0.21.7 powered by rolldown v1.0.0-rc.12
6
+ ℹ entry: src/index.ts
7
+ ℹ tsconfig: tsconfig.json
8
+ ℹ Build start
9
+ ℹ Cleaning 3 files
10
+ ℹ dist/index.cjs 0.83 kB │ gzip: 0.39 kB
11
+ ℹ 1 files, total: 0.83 kB
12
+ ℹ dist/index.d.cts.map 5.31 kB │ gzip: 1.44 kB
13
+ ℹ dist/index.d.cts 9.09 kB │ gzip: 2.36 kB
14
+ ℹ 2 files, total: 14.40 kB
15
+ âś” Build complete in 1469ms
@@ -0,0 +1,6 @@
1
+
2
+ > @open-wa/driver-interface@5.0.0-alpha.1 lint /Users/Mohammed/projects/tools/wa/packages/driver-interface
3
+ > oxlint src
4
+
5
+ Found 0 warnings and 0 errors.
6
+ Finished in 151ms on 4 files with 93 rules using 8 threads.
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @open-wa/driver-interface
2
+
3
+ ## 6.0.0-alpha.2
4
+
5
+ ### Minor Changes
6
+
7
+ - Dry run minor bump
8
+
9
+ ## 5.0.1-alpha.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Dry run patch bump
package/LICENSE.md ADDED
@@ -0,0 +1,67 @@
1
+ ### Copyright (c) 2020 Mohammed Shah
2
+
3
+ # Hippocratic + Do Not Harm (H-DNH) Version 1.1
4
+
5
+ ## Preamble
6
+
7
+ Most software today is developed with little to no thought of how it will be used, or the consequences for our society and planet.
8
+
9
+ As software developers, we engineer the infrastructure of the 21st century. We recognise that our infrastructure has great power to shape the world and the lives of those we share it with, and we choose to consciously take responsibility for the social and environmental impacts of what we build.
10
+
11
+ We envisage a world free from injustice, inequality, and the reckless destruction of lives and our planet. We reject slavery in all its forms, whether by force, indebtedness, or by algorithms that hack human vulnerabilities. We seek a world where humankind is at peace with our neighbours, nature, and ourselves. We want our work to enrich the physical, mental and spiritual wellbeing of all society.
12
+
13
+ We build software to further this vision of a just world, or at the very least, to not put that vision further from reach.
14
+
15
+ ## Terms
16
+
17
+ Licensor hereby grants permission by this license ("License"), free of charge, to any person or entity (the "Licensee") obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18
+
19
+ 1. All redistribution of source code or binary form, including any modifications must be under these terms. You must inform recipients that the code is governed by these conditions, and how they can obtain a copy of this license. You may not attempt to alter the conditions of who may/may not use this software.
20
+
21
+ 2. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22
+
23
+ 3. This software must not be used by any organisation, website, product or service that:
24
+
25
+ a) lobbies for, promotes, or derives a majority of income from actions that support or contribute to:
26
+ * sex trafficking
27
+ * human trafficking
28
+ * slavery
29
+ * indentured servitude
30
+ * gambling
31
+ * tobacco
32
+ * adversely addictive behaviours
33
+ * nuclear energy
34
+ * warfare
35
+ * weapons manufacturing
36
+ * war crimes
37
+ * settler colonialism
38
+ * apartheid
39
+ * vaccine misinformation
40
+ * climate misinformation
41
+ * child endangerment
42
+ * violence (except when required to protect public safety)
43
+ * burning of forests
44
+ * deforestation
45
+ * hate speech or discrimination based on age, gender, gender identity, race, sexuality, religion, nationality
46
+
47
+ b) lobbies against, or derives a majority of income from actions that discourage or frustrate:
48
+ * peace
49
+ * access to the rights set out in the Universal Declaration of Human Rights and the Convention on the Rights of the Child
50
+ * peaceful assembly and association (including worker associations)
51
+ * a safe environment or action to curtail the use of fossil fuels or prevent climate change
52
+ * democratic processes
53
+
54
+
55
+ 4. Compliance with Human Rights Laws and Human Rights Principles:
56
+
57
+ a. **Human Rights Laws**. The Software shall not be used by any person or entity for any systems, activities, or other uses that violate any applicable laws, regulations, or rules that protect human, civil, labor, privacy, political, environmental, security, economic, due process, or similar rights (the "Human Rights Laws"). Where the Human Rights Laws of more than one jurisdiction are applicable to the use of the Software, the Human Rights Laws that are most protective of the individuals or groups harmed shall apply.
58
+
59
+ b. **Human Rights Principles**. Licensee is advised to consult the articles of the United Nations Universal Declaration of Human Rights (https://www.un.org/en/universal-declaration-human-rights/) and the United Nations Global Compact (https://www.unglobalcompact.org/ what-is-gc/mission/principles) that define recognized principles of international human rights (the "Human Rights Principles"). It is Licensor's express intent that all use of the Software be consistent with Human Rights Principles. If Licensor receives notification or otherwise learns of an alleged violation of any Human Rights Principles relating to Licensee's use of the Software, Licensor may in its discretion and without obligation (i) (a) notify Licensee of such allegation and (b) allow Licensee 90 days from notification under (i)(a) to investigate and respond to Licensor regarding the allegation and (ii) (a) after the earlier of 90 days from notification under (i)(a), or Licensee's response under (i)(b), notify Licensee of License termination and (b) allow Licensee an additional 90 days from notification under (ii)(a) to cease use of the Software.
60
+
61
+ c. **Indemnity**. Licensee shall hold harmless and indemnify Licensor against all losses, damages, liabilities, deficiencies, claims, actions, judgments, settlements, interest, awards, penalties, fines, costs, or expenses of whatever kind, including Licensor's reasonable attorneys' fees, arising out of or relating to Licensee's non-compliance with this License or use of the Software in violation of Human Rights Laws or Human Rights Principles. 
62
+
63
+ 5. Enforceability: If any portion or provision of this License is determined to be invalid, illegal, or unenforceable by a court of competent jurisdiction, then such invalidity, illegality, or unenforceability shall not affect any other term or provision of this License or invalidate or render unenforceable such term or provision in any other jurisdiction. Upon a determination that any term or provision is invalid, illegal, or unenforceable, to the extent permitted by applicable law, the court may modify this License to affect the original intent of the parties as closely as possible. The section headings are for convenience only and are not intended to affect the construction or interpretation of this License. Any rule of construction to the effect that ambiguities are to be resolved against the drafting party shall not apply in interpreting this License. The language in this License shall be interpreted as to its fair meaning and not strictly for or against any party.
64
+
65
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66
+
67
+ This license is an extension of the Hippocratic License - an Ethical Source license (https://ethicalsource.dev) and the Do Not Harm License - (https://github.com/raisely/NoHarm)
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @open-wa/driver-interface
2
+
3
+ Browser driver abstraction interfaces for open-wa
4
+
5
+ Part of the [@open-wa v5 monorepo](https://github.com/open-wa/wa-automate-nodejs).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @open-wa/driver-interface
11
+ ```
12
+
13
+ ## Documentation
14
+
15
+ See the [docs site](https://docs.openwa.dev).
16
+
17
+ ## License
18
+
19
+ [H-DNH V1.0](https://github.com/open-wa/wa-automate-nodejs/blob/main/LICENSE.md) — Hippocratic + Do Not Harm
package/dist/index.cjs ADDED
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/capabilities.ts
3
+ var DriverCapabilityError = class extends Error {
4
+ constructor(driverName, capability, reason) {
5
+ super(`Driver '${driverName}' does not support capability '${capability}'${reason ? `: ${reason}` : ""}`);
6
+ this.driverName = driverName;
7
+ this.capability = capability;
8
+ this.reason = reason;
9
+ this.name = "DriverCapabilityError";
10
+ }
11
+ };
12
+ function requireCapability(subject, capability) {
13
+ const support = subject.capabilities[capability];
14
+ if (support.supported) return;
15
+ throw subject.createCapabilityError?.(capability, support.reason) ?? new DriverCapabilityError(subject.name, capability, support.reason);
16
+ }
17
+ //#endregion
18
+ exports.DriverCapabilityError = DriverCapabilityError;
19
+ exports.requireCapability = requireCapability;
@@ -0,0 +1,264 @@
1
+ //#region src/types.d.ts
2
+ type DriverName = 'puppeteer' | 'playwright' | 'remote' | 'lightpanda' | string;
3
+ interface IDriverContext {
4
+ logger?: {
5
+ debug(msg: string, meta?: Record<string, unknown>): void;
6
+ info(msg: string, meta?: Record<string, unknown>): void;
7
+ warn(msg: string, meta?: Record<string, unknown>): void;
8
+ error(msg: string, meta?: Record<string, unknown>): void;
9
+ };
10
+ }
11
+ interface LightpandaOptions {
12
+ executablePath?: string;
13
+ portStart?: number;
14
+ host?: string;
15
+ startupTimeoutMs?: number;
16
+ disableTelemetry?: boolean;
17
+ }
18
+ interface LaunchOptions {
19
+ headless?: boolean;
20
+ executablePath?: string;
21
+ args?: string[];
22
+ proxy?: {
23
+ server: string;
24
+ username?: string;
25
+ password?: string;
26
+ };
27
+ userDataDir?: string;
28
+ timeoutMs?: number;
29
+ defaultViewport?: {
30
+ width: number;
31
+ height: number;
32
+ } | null;
33
+ lightpanda?: LightpandaOptions;
34
+ }
35
+ interface ConnectOptions {
36
+ wsEndpoint?: string;
37
+ cdpEndpoint?: string;
38
+ headers?: Record<string, string>;
39
+ timeoutMs?: number;
40
+ }
41
+ //#endregion
42
+ //#region src/driver.d.ts
43
+ type NavigationWaitUntil = 'load' | 'domcontentloaded' | 'networkidle' | 'networkidle0' | 'networkidle2';
44
+ interface DisposableHandle {
45
+ dispose(): Promise<void> | void;
46
+ }
47
+ interface WaitForFunctionOptions {
48
+ timeoutMs?: number;
49
+ polling?: number | 'raf' | 'mutation';
50
+ }
51
+ interface IFrame {
52
+ url(): string;
53
+ name(): string;
54
+ isMainFrame(): boolean;
55
+ parentFrame(): IFrame | null;
56
+ content?(): Promise<string>;
57
+ unwrap(): unknown;
58
+ }
59
+ interface IRequestContinueOverrides {
60
+ url?: string;
61
+ method?: string;
62
+ postData?: string;
63
+ headers?: Record<string, string>;
64
+ }
65
+ interface IRequestResponse {
66
+ status?: number;
67
+ headers?: Record<string, string>;
68
+ contentType?: string;
69
+ body?: string | Uint8Array;
70
+ }
71
+ interface IRequest {
72
+ url(): string;
73
+ method(): string;
74
+ headers(): Record<string, string>;
75
+ resourceType(): string | null;
76
+ isNavigationRequest(): boolean;
77
+ frame(): IFrame | null;
78
+ abort(errorCode?: string): Promise<void>;
79
+ continue(overrides?: IRequestContinueOverrides): Promise<void>;
80
+ respond(response: IRequestResponse): Promise<void>;
81
+ unwrap(): unknown;
82
+ }
83
+ interface IConsoleMessage {
84
+ type(): string;
85
+ text(): string;
86
+ location?(): {
87
+ url?: string;
88
+ lineNumber?: number;
89
+ columnNumber?: number;
90
+ };
91
+ args?(): unknown[];
92
+ unwrap(): unknown;
93
+ }
94
+ interface IPageEventMap {
95
+ close: void;
96
+ console: IConsoleMessage;
97
+ pageerror: Error;
98
+ request: IRequest;
99
+ requestfailed: IRequest;
100
+ requestfinished: IRequest;
101
+ framenavigated: IFrame;
102
+ }
103
+ type PageEventHandler<K extends keyof IPageEventMap> = IPageEventMap[K] extends void ? () => void | Promise<void> : (payload: IPageEventMap[K]) => void | Promise<void>;
104
+ interface IDriver {
105
+ readonly name: DriverName;
106
+ readonly version?: string;
107
+ init(ctx?: IDriverContext): Promise<void>;
108
+ launch(options?: LaunchOptions): Promise<IBrowser>;
109
+ connect(options: ConnectOptions): Promise<IBrowser>;
110
+ unwrap(): unknown;
111
+ }
112
+ interface IBrowser {
113
+ readonly name: DriverName;
114
+ newPage(options?: {
115
+ clearFirstPage?: boolean;
116
+ }): Promise<IPage>;
117
+ pages(): Promise<IPage[]>;
118
+ close(): Promise<void>;
119
+ isConnected(): boolean;
120
+ versionString(): Promise<string>;
121
+ unwrap(): unknown;
122
+ }
123
+ interface IPage {
124
+ readonly name: DriverName;
125
+ goto(url: string, options?: {
126
+ waitUntil?: NavigationWaitUntil;
127
+ timeoutMs?: number;
128
+ }): Promise<void>;
129
+ url(): string;
130
+ reload(): Promise<void>;
131
+ mainFrame(): IFrame | null;
132
+ evaluateOnNewDocument<Arg, Ret>(fn: (arg: Arg) => Ret | Promise<Ret>, arg: Arg): Promise<void>;
133
+ evaluate<Arg, Ret>(fn: (arg: Arg) => Ret | Promise<Ret>, arg: Arg): Promise<Ret>;
134
+ evaluateScript<Ret = unknown>(script: string): Promise<Ret>;
135
+ addInitScript(script: string): Promise<DisposableHandle>;
136
+ setViewport(viewport: {
137
+ width: number;
138
+ height: number;
139
+ }): Promise<void>;
140
+ setUserAgent(ua: string): Promise<void>;
141
+ setRequestInterception(enabled: boolean): Promise<void>;
142
+ waitForSelector(selector: string, options?: {
143
+ timeoutMs?: number;
144
+ }): Promise<IElementHandle | null>;
145
+ waitForFunction(script: string, options?: WaitForFunctionOptions): Promise<void>;
146
+ waitForFunction<Arg>(fn: (arg: Arg) => boolean, arg: Arg, options?: WaitForFunctionOptions): Promise<void>;
147
+ $(selector: string): Promise<IElementHandle | null>;
148
+ $$(selector: string): Promise<IElementHandle[]>;
149
+ click(selector: string): Promise<void>;
150
+ type(selector: string, text: string, options?: {
151
+ delayMs?: number;
152
+ }): Promise<void>;
153
+ screenshot(options?: {
154
+ type?: 'png' | 'jpeg';
155
+ fullPage?: boolean;
156
+ }): Promise<Uint8Array>;
157
+ exposeFunction(name: string, fn: (...args: any[]) => any): Promise<void>;
158
+ on<K extends keyof IPageEventMap>(event: K, handler: PageEventHandler<K>): DisposableHandle;
159
+ on(event: string, handler: (...args: any[]) => void | Promise<void>): DisposableHandle;
160
+ off<K extends keyof IPageEventMap>(event: K, handler: PageEventHandler<K>): void;
161
+ off(event: string, handler: (...args: any[]) => void | Promise<void>): void;
162
+ close(): Promise<void>;
163
+ isClosed(): boolean;
164
+ unwrap(): unknown;
165
+ }
166
+ interface IElementHandle {
167
+ click(): Promise<void>;
168
+ type(text: string): Promise<void>;
169
+ getAttribute(name: string): Promise<string | null>;
170
+ textContent(): Promise<string | null>;
171
+ dispose(): Promise<void>;
172
+ unwrap(): unknown;
173
+ }
174
+ //#endregion
175
+ //#region src/capabilities.d.ts
176
+ type DriverCapabilityKey = 'cdp' | 'requestInterception' | 'serviceWorkerBypass' | 'stealth' | 'pdf' | 'tracing' | 'persistentContext' | 'browserExtensions' | 'exposeBinding' | 'screenshot' | 'rendering';
177
+ type CapabilitySupport = {
178
+ supported: true;
179
+ notes?: string;
180
+ } | {
181
+ supported: false;
182
+ reason: string;
183
+ };
184
+ type DriverCapabilities = Record<DriverCapabilityKey, CapabilitySupport>;
185
+ interface IHasCapabilities {
186
+ readonly name: string;
187
+ readonly version?: string;
188
+ readonly capabilities: DriverCapabilities;
189
+ has<C extends DriverCapabilityKey>(cap: C): this is this & CapabilityExtensionMap[C];
190
+ require<C extends DriverCapabilityKey>(cap: C): void;
191
+ }
192
+ interface ICapabilityErrorFactory {
193
+ createCapabilityError?<C extends DriverCapabilityKey>(capability: C, reason?: string): Error;
194
+ }
195
+ type CapabilitySubject = Pick<IHasCapabilities, 'name' | 'capabilities'> & ICapabilityErrorFactory;
196
+ interface CapabilityExtensionMap {
197
+ cdp: ICDPSupport;
198
+ requestInterception: IRequestInterceptionSupport;
199
+ serviceWorkerBypass: IServiceWorkerBypassSupport;
200
+ stealth: IStealthSupport;
201
+ pdf: IPdfSupport;
202
+ tracing: ITracingSupport;
203
+ persistentContext: IPersistentContextSupport;
204
+ browserExtensions: IBrowserExtensionsSupport;
205
+ exposeBinding: IExposeBindingSupport;
206
+ screenshot: IScreenshotSupport;
207
+ rendering: IRenderingSupport;
208
+ }
209
+ interface ICDPSupport {
210
+ cdp(): ICDPSession;
211
+ }
212
+ interface ICDPSession {
213
+ send<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
214
+ detach(): Promise<void>;
215
+ }
216
+ interface IRequestInterceptionSupport {
217
+ setRequestInterception(enabled: boolean): Promise<void>;
218
+ }
219
+ interface IServiceWorkerBypassSupport {
220
+ setBypassServiceWorker(bypass: boolean): Promise<void>;
221
+ }
222
+ interface IStealthSupport {
223
+ enableStealth(enabled: boolean): Promise<void>;
224
+ }
225
+ interface IPdfSupport {
226
+ pdf(options?: {
227
+ path?: string;
228
+ format?: 'A4' | 'Letter';
229
+ }): Promise<Uint8Array>;
230
+ }
231
+ interface ITracingSupport {
232
+ startTracing(options?: {
233
+ categories?: string[];
234
+ }): Promise<void>;
235
+ stopTracing(): Promise<Uint8Array>;
236
+ }
237
+ interface IPersistentContextSupport {
238
+ getPersistentContext(): unknown;
239
+ }
240
+ interface IBrowserExtensionsSupport {
241
+ loadExtension(path: string): Promise<void>;
242
+ }
243
+ interface IExposeBindingSupport {
244
+ exposeBinding(name: string, fn: (...args: any[]) => any): Promise<void>;
245
+ }
246
+ interface IScreenshotSupport {
247
+ screenshot(options?: {
248
+ type?: 'png' | 'jpeg';
249
+ fullPage?: boolean;
250
+ }): Promise<Uint8Array>;
251
+ }
252
+ interface IRenderingSupport {
253
+ readonly rendering?: true;
254
+ }
255
+ declare class DriverCapabilityError extends Error {
256
+ readonly driverName: string;
257
+ readonly capability: DriverCapabilityKey;
258
+ readonly reason?: string | undefined;
259
+ constructor(driverName: string, capability: DriverCapabilityKey, reason?: string | undefined);
260
+ }
261
+ declare function requireCapability<C extends DriverCapabilityKey>(subject: CapabilitySubject, capability: C): void;
262
+ //#endregion
263
+ export { CapabilityExtensionMap, CapabilitySubject, CapabilitySupport, ConnectOptions, DisposableHandle, DriverCapabilities, DriverCapabilityError, DriverCapabilityKey, DriverName, IBrowser, IBrowserExtensionsSupport, ICDPSession, ICDPSupport, ICapabilityErrorFactory, IConsoleMessage, IDriver, IDriverContext, IElementHandle, IExposeBindingSupport, IFrame, IHasCapabilities, IPage, IPageEventMap, IPdfSupport, IPersistentContextSupport, IRenderingSupport, IRequest, IRequestContinueOverrides, IRequestInterceptionSupport, IRequestResponse, IScreenshotSupport, IServiceWorkerBypassSupport, IStealthSupport, ITracingSupport, LaunchOptions, LightpandaOptions, NavigationWaitUntil, PageEventHandler, WaitForFunctionOptions, requireCapability };
264
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/driver.ts","../src/capabilities.ts"],"mappings":";KAAY,UAAA;AAAA,UAEK,cAAA;EACb,MAAA;IACI,KAAA,CAAM,GAAA,UAAa,IAAA,GAAO,MAAA;IAC1B,IAAA,CAAK,GAAA,UAAa,IAAA,GAAO,MAAA;IACzB,IAAA,CAAK,GAAA,UAAa,IAAA,GAAO,MAAA;IACzB,KAAA,CAAM,GAAA,UAAa,IAAA,GAAO,MAAA;EAAA;AAAA;AAAA,UAIjB,iBAAA;EACb,cAAA;EACA,SAAA;EACA,IAAA;EACA,gBAAA;EACA,gBAAA;AAAA;AAAA,UAGa,aAAA;EACb,QAAA;EACA,cAAA;EACA,IAAA;EACA,KAAA;IAAU,MAAA;IAAgB,QAAA;IAAmB,QAAA;EAAA;EAC7C,WAAA;EACA,SAAA;EACA,eAAA;IAAoB,KAAA;IAAe,MAAA;EAAA;EACnC,UAAA,GAAa,iBAAA;AAAA;AAAA,UAGA,cAAA;EACb,UAAA;EACA,WAAA;EACA,OAAA,GAAU,MAAA;EACV,SAAA;AAAA;;;KChCQ,mBAAA;AAAA,UAEK,gBAAA;EACb,OAAA,IAAW,OAAA;AAAA;AAAA,UAGE,sBAAA;EACb,SAAA;EACA,OAAA;AAAA;AAAA,UAGa,MAAA;EACb,GAAA;EACA,IAAA;EACA,WAAA;EACA,WAAA,IAAe,MAAA;EACf,OAAA,KAAY,OAAA;EACZ,MAAA;AAAA;AAAA,UAGa,yBAAA;EACb,GAAA;EACA,MAAA;EACA,QAAA;EACA,OAAA,GAAU,MAAA;AAAA;AAAA,UAGG,gBAAA;EACb,MAAA;EACA,OAAA,GAAU,MAAA;EACV,WAAA;EACA,IAAA,YAAgB,UAAA;AAAA;AAAA,UAGH,QAAA;EACb,GAAA;EACA,MAAA;EACA,OAAA,IAAW,MAAA;EACX,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BAAA,EACZ,MAAA;AAAA;AAAA,iBAWR,iBAAA,WAA4B,mBAAA,CAAA,CAAqB,OAAA,EAAS,iBAAA,EAAmB,UAAA,EAAY,CAAA"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@open-wa/driver-interface",
3
+ "version": "5.0.0-alpha.0",
4
+ "description": "Browser driver abstraction interfaces for open-wa",
5
+ "main": "./dist/index.cjs",
6
+ "types": "./dist/index.d.cts",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./dist/index.cjs",
10
+ "import": "./dist/index.cjs",
11
+ "types": "./dist/index.d.cts"
12
+ }
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^6.0.3"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/open-wa/wa-automate-nodejs.git"
23
+ },
24
+ "scripts": {
25
+ "build": "tsdown src/index.ts --format cjs",
26
+ "dev": "tsdown src/index.ts --format cjs --watch",
27
+ "lint": "oxlint src"
28
+ }
29
+ }
@@ -0,0 +1,123 @@
1
+ export type DriverCapabilityKey =
2
+ | 'cdp'
3
+ | 'requestInterception'
4
+ | 'serviceWorkerBypass'
5
+ | 'stealth'
6
+ | 'pdf'
7
+ | 'tracing'
8
+ | 'persistentContext'
9
+ | 'browserExtensions'
10
+ | 'exposeBinding'
11
+ | 'screenshot'
12
+ | 'rendering';
13
+
14
+ export type CapabilitySupport =
15
+ | { supported: true; notes?: string }
16
+ | { supported: false; reason: string };
17
+
18
+ export type DriverCapabilities = Record<DriverCapabilityKey, CapabilitySupport>;
19
+
20
+ export interface IHasCapabilities {
21
+ readonly name: string;
22
+ readonly version?: string;
23
+ readonly capabilities: DriverCapabilities;
24
+
25
+ has<C extends DriverCapabilityKey>(cap: C): this is this & CapabilityExtensionMap[C];
26
+
27
+ require<C extends DriverCapabilityKey>(cap: C): void;
28
+ }
29
+
30
+ export interface ICapabilityErrorFactory {
31
+ createCapabilityError?<C extends DriverCapabilityKey>(capability: C, reason?: string): Error;
32
+ }
33
+
34
+ export type CapabilitySubject = Pick<IHasCapabilities, 'name' | 'capabilities'> & ICapabilityErrorFactory;
35
+
36
+ export interface CapabilityExtensionMap {
37
+ cdp: ICDPSupport;
38
+ requestInterception: IRequestInterceptionSupport;
39
+ serviceWorkerBypass: IServiceWorkerBypassSupport;
40
+ stealth: IStealthSupport;
41
+ pdf: IPdfSupport;
42
+ tracing: ITracingSupport;
43
+ persistentContext: IPersistentContextSupport;
44
+ browserExtensions: IBrowserExtensionsSupport;
45
+ exposeBinding: IExposeBindingSupport;
46
+ screenshot: IScreenshotSupport;
47
+ rendering: IRenderingSupport;
48
+ }
49
+
50
+ export interface ICDPSupport {
51
+ cdp(): ICDPSession;
52
+ }
53
+
54
+ export interface ICDPSession {
55
+ send<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
56
+ detach(): Promise<void>;
57
+ }
58
+
59
+ export interface IRequestInterceptionSupport {
60
+ setRequestInterception(enabled: boolean): Promise<void>;
61
+ }
62
+
63
+ export interface IServiceWorkerBypassSupport {
64
+ setBypassServiceWorker(bypass: boolean): Promise<void>;
65
+ }
66
+
67
+ export interface IStealthSupport {
68
+ enableStealth(enabled: boolean): Promise<void>;
69
+ }
70
+
71
+ export interface IPdfSupport {
72
+ pdf(options?: { path?: string; format?: 'A4' | 'Letter' }): Promise<Uint8Array>;
73
+ }
74
+
75
+ export interface ITracingSupport {
76
+ startTracing(options?: { categories?: string[] }): Promise<void>;
77
+ stopTracing(): Promise<Uint8Array>;
78
+ }
79
+
80
+ export interface IPersistentContextSupport {
81
+ getPersistentContext(): unknown;
82
+ }
83
+
84
+ export interface IBrowserExtensionsSupport {
85
+ loadExtension(path: string): Promise<void>;
86
+ }
87
+
88
+ export interface IExposeBindingSupport {
89
+ exposeBinding(name: string, fn: (...args: any[]) => any): Promise<void>;
90
+ }
91
+
92
+ export interface IScreenshotSupport {
93
+ screenshot(options?: { type?: 'png' | 'jpeg'; fullPage?: boolean }): Promise<Uint8Array>;
94
+ }
95
+
96
+ export interface IRenderingSupport {
97
+ readonly rendering?: true;
98
+ }
99
+
100
+ export class DriverCapabilityError extends Error {
101
+ constructor(
102
+ public readonly driverName: string,
103
+ public readonly capability: DriverCapabilityKey,
104
+ public readonly reason?: string
105
+ ) {
106
+ super(
107
+ `Driver '${driverName}' does not support capability '${capability}'${
108
+ reason ? `: ${reason}` : ''
109
+ }`
110
+ );
111
+ this.name = 'DriverCapabilityError';
112
+ }
113
+ }
114
+
115
+ export function requireCapability<C extends DriverCapabilityKey>(subject: CapabilitySubject, capability: C): void {
116
+ const support = subject.capabilities[capability];
117
+ if (support.supported) {
118
+ return;
119
+ }
120
+
121
+ throw subject.createCapabilityError?.(capability, support.reason)
122
+ ?? new DriverCapabilityError(subject.name, capability, support.reason);
123
+ }
package/src/driver.ts ADDED
@@ -0,0 +1,146 @@
1
+ import { LaunchOptions, ConnectOptions, IDriverContext, DriverName } from './types';
2
+
3
+ export type NavigationWaitUntil = 'load' | 'domcontentloaded' | 'networkidle' | 'networkidle0' | 'networkidle2';
4
+
5
+ export interface DisposableHandle {
6
+ dispose(): Promise<void> | void;
7
+ }
8
+
9
+ export interface WaitForFunctionOptions {
10
+ timeoutMs?: number;
11
+ polling?: number | 'raf' | 'mutation';
12
+ }
13
+
14
+ export interface IFrame {
15
+ url(): string;
16
+ name(): string;
17
+ isMainFrame(): boolean;
18
+ parentFrame(): IFrame | null;
19
+ content?(): Promise<string>;
20
+ unwrap(): unknown;
21
+ }
22
+
23
+ export interface IRequestContinueOverrides {
24
+ url?: string;
25
+ method?: string;
26
+ postData?: string;
27
+ headers?: Record<string, string>;
28
+ }
29
+
30
+ export interface IRequestResponse {
31
+ status?: number;
32
+ headers?: Record<string, string>;
33
+ contentType?: string;
34
+ body?: string | Uint8Array;
35
+ }
36
+
37
+ export interface IRequest {
38
+ url(): string;
39
+ method(): string;
40
+ headers(): Record<string, string>;
41
+ resourceType(): string | null;
42
+ isNavigationRequest(): boolean;
43
+ frame(): IFrame | null;
44
+ abort(errorCode?: string): Promise<void>;
45
+ continue(overrides?: IRequestContinueOverrides): Promise<void>;
46
+ respond(response: IRequestResponse): Promise<void>;
47
+ unwrap(): unknown;
48
+ }
49
+
50
+ export interface IConsoleMessage {
51
+ type(): string;
52
+ text(): string;
53
+ location?(): { url?: string; lineNumber?: number; columnNumber?: number };
54
+ args?(): unknown[];
55
+ unwrap(): unknown;
56
+ }
57
+
58
+ export interface IPageEventMap {
59
+ close: void;
60
+ console: IConsoleMessage;
61
+ pageerror: Error;
62
+ request: IRequest;
63
+ requestfailed: IRequest;
64
+ requestfinished: IRequest;
65
+ framenavigated: IFrame;
66
+ }
67
+
68
+ export type PageEventHandler<K extends keyof IPageEventMap> = IPageEventMap[K] extends void
69
+ ? () => void | Promise<void>
70
+ : (payload: IPageEventMap[K]) => void | Promise<void>;
71
+
72
+ export interface IDriver {
73
+ readonly name: DriverName;
74
+ readonly version?: string;
75
+
76
+ init(ctx?: IDriverContext): Promise<void>;
77
+ launch(options?: LaunchOptions): Promise<IBrowser>;
78
+ connect(options: ConnectOptions): Promise<IBrowser>;
79
+
80
+ unwrap(): unknown;
81
+ }
82
+
83
+ export interface IBrowser {
84
+ readonly name: DriverName;
85
+
86
+ newPage(options?: {
87
+ //clears the first page
88
+ clearFirstPage?: boolean
89
+ }): Promise<IPage>;
90
+ pages(): Promise<IPage[]>;
91
+ close(): Promise<void>;
92
+ isConnected(): boolean;
93
+ versionString(): Promise<string>;
94
+
95
+ unwrap(): unknown;
96
+ }
97
+
98
+ export interface IPage {
99
+ readonly name: DriverName;
100
+
101
+ goto(url: string, options?: { waitUntil?: NavigationWaitUntil; timeoutMs?: number }): Promise<void>;
102
+ url(): string;
103
+ reload(): Promise<void>;
104
+ mainFrame(): IFrame | null;
105
+
106
+ evaluateOnNewDocument<Arg, Ret>(fn: (arg: Arg) => Ret | Promise<Ret>, arg: Arg): Promise<void>;
107
+
108
+ evaluate<Arg, Ret>(fn: (arg: Arg) => Ret | Promise<Ret>, arg: Arg): Promise<Ret>;
109
+ evaluateScript<Ret = unknown>(script: string): Promise<Ret>;
110
+ addInitScript(script: string): Promise<DisposableHandle>;
111
+
112
+ setViewport(viewport: { width: number; height: number }): Promise<void>;
113
+ setUserAgent(ua: string): Promise<void>;
114
+ setRequestInterception(enabled: boolean): Promise<void>;
115
+
116
+ waitForSelector(selector: string, options?: { timeoutMs?: number }): Promise<IElementHandle | null>;
117
+ waitForFunction(script: string, options?: WaitForFunctionOptions): Promise<void>;
118
+ waitForFunction<Arg>(fn: (arg: Arg) => boolean, arg: Arg, options?: WaitForFunctionOptions): Promise<void>;
119
+ $(selector: string): Promise<IElementHandle | null>;
120
+ $$(selector: string): Promise<IElementHandle[]>;
121
+
122
+ click(selector: string): Promise<void>;
123
+ type(selector: string, text: string, options?: { delayMs?: number }): Promise<void>;
124
+
125
+ screenshot(options?: { type?: 'png' | 'jpeg'; fullPage?: boolean }): Promise<Uint8Array>;
126
+
127
+ exposeFunction(name: string, fn: (...args: any[]) => any): Promise<void>;
128
+ on<K extends keyof IPageEventMap>(event: K, handler: PageEventHandler<K>): DisposableHandle;
129
+ on(event: string, handler: (...args: any[]) => void | Promise<void>): DisposableHandle;
130
+ off<K extends keyof IPageEventMap>(event: K, handler: PageEventHandler<K>): void;
131
+ off(event: string, handler: (...args: any[]) => void | Promise<void>): void;
132
+
133
+ close(): Promise<void>;
134
+ isClosed(): boolean;
135
+
136
+ unwrap(): unknown;
137
+ }
138
+
139
+ export interface IElementHandle {
140
+ click(): Promise<void>;
141
+ type(text: string): Promise<void>;
142
+ getAttribute(name: string): Promise<string | null>;
143
+ textContent(): Promise<string | null>;
144
+ dispose(): Promise<void>;
145
+ unwrap(): unknown;
146
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './driver';
3
+ export * from './capabilities';
package/src/types.ts ADDED
@@ -0,0 +1,36 @@
1
+ export type DriverName = 'puppeteer' | 'playwright' | 'remote' | 'lightpanda' | string;
2
+
3
+ export interface IDriverContext {
4
+ logger?: {
5
+ debug(msg: string, meta?: Record<string, unknown>): void;
6
+ info(msg: string, meta?: Record<string, unknown>): void;
7
+ warn(msg: string, meta?: Record<string, unknown>): void;
8
+ error(msg: string, meta?: Record<string, unknown>): void;
9
+ };
10
+ }
11
+
12
+ export interface LightpandaOptions {
13
+ executablePath?: string;
14
+ portStart?: number;
15
+ host?: string;
16
+ startupTimeoutMs?: number;
17
+ disableTelemetry?: boolean;
18
+ }
19
+
20
+ export interface LaunchOptions {
21
+ headless?: boolean;
22
+ executablePath?: string;
23
+ args?: string[];
24
+ proxy?: { server: string; username?: string; password?: string };
25
+ userDataDir?: string;
26
+ timeoutMs?: number;
27
+ defaultViewport?: { width: number; height: number } | null;
28
+ lightpanda?: LightpandaOptions;
29
+ }
30
+
31
+ export interface ConnectOptions {
32
+ wsEndpoint?: string;
33
+ cdpEndpoint?: string;
34
+ headers?: Record<string, string>;
35
+ timeoutMs?: number;
36
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": [
8
+ "src/**/*"
9
+ ]
10
+ }