effect-playwright 0.1.1 → 0.1.2

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.
@@ -1,754 +0,0 @@
1
- import { Context, Effect, Layer, Option, Scope, Stream } from "effect";
2
- import { Browser, BrowserContext, BrowserType, ConnectOverCDPOptions, ConsoleMessage, Dialog, Download, ElementHandle, FileChooser, Frame, JSHandle, Locator, Page, Request as Request$1, Response as Response$1, WebSocket, Worker as Worker$1, chromium } from "playwright-core";
3
- import { Scope as Scope$1 } from "effect/Scope";
4
- import * as effect_Types0 from "effect/Types";
5
- import * as effect_Cause0 from "effect/Cause";
6
-
7
- //#region src/errors.d.ts
8
- type PlaywrightErrorReason = "Timeout" | "Unknown";
9
- declare const PlaywrightError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => effect_Cause0.YieldableError & {
10
- readonly _tag: "PlaywrightError";
11
- } & Readonly<A>;
12
- declare class PlaywrightError extends PlaywrightError_base<{
13
- reason: PlaywrightErrorReason;
14
- cause: unknown;
15
- }> {}
16
- //#endregion
17
- //#region src/playwright-types.d.ts
18
- /**
19
- * Extracted from `playwright-core/types/structs.d.ts` because it is not exported over the package boundary.
20
- * These types are necessary to correctly type `evaluate` functions that unwrap handles.
21
- */
22
- type NoHandles<Arg> = Arg extends JSHandle ? never : Arg extends object ? { [Key in keyof Arg]: NoHandles<Arg[Key]> } : Arg;
23
- type Unboxed<Arg> = Arg extends ElementHandle<infer T> ? T : Arg extends JSHandle<infer T> ? T : Arg extends NoHandles<Arg> ? Arg : Arg extends [infer A0] ? [Unboxed<A0>] : Arg extends [infer A0, infer A1] ? [Unboxed<A0>, Unboxed<A1>] : Arg extends [infer A0, infer A1, infer A2] ? [Unboxed<A0>, Unboxed<A1>, Unboxed<A2>] : Arg extends [infer A0, infer A1, infer A2, infer A3] ? [Unboxed<A0>, Unboxed<A1>, Unboxed<A2>, Unboxed<A3>] : Arg extends Array<infer T> ? Array<Unboxed<T>> : Arg extends object ? { [Key in keyof Arg]: Unboxed<Arg[Key]> } : Arg;
24
- type PageFunction<Arg, R> = string | ((arg: Unboxed<Arg>) => R | Promise<R>);
25
- //#endregion
26
- //#region src/common.d.ts
27
- declare const PlaywrightFrame_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Readonly<A> & {
28
- readonly _tag: "PlaywrightFrame";
29
- };
30
- declare class PlaywrightFrame extends PlaywrightFrame_base<{
31
- use: <A>(f: (frame: Frame) => Promise<A>) => Effect.Effect<A, PlaywrightError>;
32
- }> {
33
- static make(frame: Frame): PlaywrightFrame;
34
- }
35
- declare const PlaywrightRequest_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Readonly<A> & {
36
- readonly _tag: "PlaywrightRequest";
37
- };
38
- declare class PlaywrightRequest extends PlaywrightRequest_base<{
39
- allHeaders: Effect.Effect<Awaited<ReturnType<Request$1["allHeaders"]>>, PlaywrightError>;
40
- failure: () => Option.Option<NonNullable<ReturnType<Request$1["failure"]>>>;
41
- frame: Effect.Effect<PlaywrightFrame>;
42
- headerValue: (name: string) => Effect.Effect<Option.Option<string>, PlaywrightError>;
43
- headers: Effect.Effect<ReturnType<Request$1["headers"]>>;
44
- headersArray: Effect.Effect<Awaited<ReturnType<Request$1["headersArray"]>>, PlaywrightError>;
45
- isNavigationRequest: Effect.Effect<boolean>;
46
- method: Effect.Effect<string>;
47
- postData: () => Option.Option<string>;
48
- postDataBuffer: () => Option.Option<NonNullable<ReturnType<Request$1["postDataBuffer"]>>>;
49
- postDataJSON: Effect.Effect<Option.Option<NonNullable<Awaited<ReturnType<Request$1["postDataJSON"]>>>>, PlaywrightError>;
50
- redirectedFrom: () => Option.Option<PlaywrightRequest>;
51
- redirectedTo: () => Option.Option<PlaywrightRequest>;
52
- resourceType: Effect.Effect<ReturnType<Request$1["resourceType"]>>;
53
- response: Effect.Effect<Option.Option<PlaywrightResponse>, PlaywrightError>;
54
- serviceWorker: () => Option.Option<PlaywrightWorker>;
55
- sizes: Effect.Effect<Awaited<ReturnType<Request$1["sizes"]>>, PlaywrightError>;
56
- timing: Effect.Effect<ReturnType<Request$1["timing"]>>;
57
- url: Effect.Effect<string>;
58
- }> {
59
- static make(request: Request$1): PlaywrightRequest;
60
- }
61
- declare const PlaywrightResponse_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Readonly<A> & {
62
- readonly _tag: "PlaywrightResponse";
63
- };
64
- declare class PlaywrightResponse extends PlaywrightResponse_base<{
65
- allHeaders: Effect.Effect<Awaited<ReturnType<Response$1["allHeaders"]>>, PlaywrightError>;
66
- body: Effect.Effect<Awaited<ReturnType<Response$1["body"]>>, PlaywrightError>;
67
- finished: Effect.Effect<Awaited<ReturnType<Response$1["finished"]>>, PlaywrightError>;
68
- frame: Effect.Effect<PlaywrightFrame>;
69
- fromServiceWorker: Effect.Effect<boolean>;
70
- headers: Effect.Effect<ReturnType<Response$1["headers"]>>;
71
- headersArray: Effect.Effect<Awaited<ReturnType<Response$1["headersArray"]>>, PlaywrightError>;
72
- headerValue: (name: string) => Effect.Effect<Option.Option<string>, PlaywrightError>;
73
- headerValues: (name: string) => Effect.Effect<Awaited<ReturnType<Response$1["headerValues"]>>, PlaywrightError>;
74
- json: Effect.Effect<Awaited<ReturnType<Response$1["json"]>>, PlaywrightError>;
75
- ok: Effect.Effect<boolean>;
76
- request: () => PlaywrightRequest;
77
- securityDetails: Effect.Effect<Option.Option<NonNullable<Awaited<ReturnType<Response$1["securityDetails"]>>>>, PlaywrightError>;
78
- serverAddr: Effect.Effect<Option.Option<NonNullable<Awaited<ReturnType<Response$1["serverAddr"]>>>>, PlaywrightError>;
79
- status: Effect.Effect<number>;
80
- statusText: Effect.Effect<string>;
81
- text: Effect.Effect<Awaited<ReturnType<Response$1["text"]>>, PlaywrightError>;
82
- url: Effect.Effect<string>;
83
- }> {
84
- static make(response: Response$1): PlaywrightResponse;
85
- }
86
- declare const PlaywrightWorker_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Readonly<A> & {
87
- readonly _tag: "PlaywrightWorker";
88
- };
89
- declare class PlaywrightWorker extends PlaywrightWorker_base<{
90
- evaluate: <R, Arg = void>(pageFunction: PageFunction<Arg, R>, arg?: Arg) => Effect.Effect<R, PlaywrightError>;
91
- url: Effect.Effect<string>;
92
- }> {
93
- static make(worker: Worker$1): PlaywrightWorker;
94
- }
95
- declare const PlaywrightDialog_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Readonly<A> & {
96
- readonly _tag: "PlaywrightDialog";
97
- };
98
- declare class PlaywrightDialog extends PlaywrightDialog_base<{
99
- accept: (promptText?: string) => Effect.Effect<void, PlaywrightError>;
100
- defaultValue: Effect.Effect<string>;
101
- dismiss: Effect.Effect<void, PlaywrightError>;
102
- message: Effect.Effect<string>;
103
- page: () => Option.Option<PlaywrightPageService>;
104
- type: Effect.Effect<string>;
105
- }> {
106
- static make(dialog: Dialog): PlaywrightDialog;
107
- }
108
- declare const PlaywrightFileChooser_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Readonly<A> & {
109
- readonly _tag: "PlaywrightFileChooser";
110
- };
111
- declare class PlaywrightFileChooser extends PlaywrightFileChooser_base<{
112
- element: () => ElementHandle;
113
- isMultiple: Effect.Effect<boolean>;
114
- page: () => PlaywrightPageService;
115
- setFiles: (files: Parameters<FileChooser["setFiles"]>[0], options?: Parameters<FileChooser["setFiles"]>[1]) => Effect.Effect<void, PlaywrightError>;
116
- }> {
117
- static make(fileChooser: FileChooser): PlaywrightFileChooser;
118
- }
119
- declare const PlaywrightDownload_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => Readonly<A> & {
120
- readonly _tag: "PlaywrightDownload";
121
- };
122
- declare class PlaywrightDownload extends PlaywrightDownload_base<{
123
- cancel: Effect.Effect<void, PlaywrightError>;
124
- createReadStream: Stream.Stream<Uint8Array, PlaywrightError>;
125
- delete: Effect.Effect<void, PlaywrightError>;
126
- failure: Effect.Effect<Option.Option<string | null>, PlaywrightError>;
127
- page: () => PlaywrightPageService;
128
- path: Effect.Effect<Option.Option<string | null>, PlaywrightError>;
129
- saveAs: (path: string) => Effect.Effect<void, PlaywrightError>;
130
- suggestedFilename: Effect.Effect<string>;
131
- url: Effect.Effect<string>;
132
- use: <R>(f: (download: Download) => Promise<R>) => Effect.Effect<R, PlaywrightError>;
133
- }> {
134
- static make(download: Download): PlaywrightDownload;
135
- }
136
- //#endregion
137
- //#region src/locator.d.ts
138
- /**
139
- * Interface for a Playwright locator.
140
- * @category model
141
- */
142
- interface PlaywrightLocatorService {
143
- /**
144
- * Clicks the element.
145
- *
146
- * @see {@link Locator.click}
147
- * @since 0.1.0
148
- */
149
- readonly click: (options?: Parameters<Locator["click"]>[0]) => Effect.Effect<void, PlaywrightError>;
150
- /**
151
- * Fills the input field.
152
- *
153
- * @see {@link Locator.fill}
154
- * @since 0.1.0
155
- */
156
- readonly fill: (value: string, options?: Parameters<Locator["fill"]>[1]) => Effect.Effect<void, PlaywrightError>;
157
- /**
158
- * Gets an attribute value.
159
- *
160
- * @see {@link Locator.getAttribute}
161
- * @since 0.1.0
162
- */
163
- readonly getAttribute: (name: string, options?: Parameters<Locator["getAttribute"]>[1]) => Effect.Effect<string | null, PlaywrightError>;
164
- /**
165
- * Gets the inner text.
166
- *
167
- * @see {@link Locator.innerText}
168
- * @since 0.1.0
169
- */
170
- readonly innerText: (options?: Parameters<Locator["innerText"]>[0]) => Effect.Effect<string, PlaywrightError>;
171
- /**
172
- * Gets the inner HTML.
173
- *
174
- * @see {@link Locator.innerHTML}
175
- * @since 0.1.0
176
- */
177
- readonly innerHTML: (options?: Parameters<Locator["innerHTML"]>[0]) => Effect.Effect<string, PlaywrightError>;
178
- /**
179
- * Gets the input value.
180
- *
181
- * @see {@link Locator.inputValue}
182
- * @since 0.1.0
183
- */
184
- readonly inputValue: (options?: Parameters<Locator["inputValue"]>[0]) => Effect.Effect<string, PlaywrightError>;
185
- /**
186
- * Gets the text content.
187
- *
188
- * @see {@link Locator.textContent}
189
- * @since 0.1.0
190
- */
191
- readonly textContent: (options?: Parameters<Locator["textContent"]>[0]) => Effect.Effect<string | null, PlaywrightError>;
192
- /**
193
- * Counts the number of matched elements.
194
- *
195
- * @see {@link Locator.count}
196
- * @since 0.1.0
197
- */
198
- readonly count: Effect.Effect<number, PlaywrightError>;
199
- /**
200
- * Returns a locator that points to the first matched element.
201
- * @see {@link Locator.first}
202
- * @since 0.1.0
203
- */
204
- readonly first: () => PlaywrightLocatorService;
205
- /**
206
- * Returns a locator that points to the last matched element.
207
- *
208
- * @see {@link Locator.last}
209
- * @since 0.1.0
210
- */
211
- readonly last: () => PlaywrightLocatorService;
212
- /**
213
- * Returns a locator that points to the nth matched element.
214
- *
215
- * @see {@link Locator.nth}
216
- * @since 0.1.0
217
- */
218
- readonly nth: (index: number) => PlaywrightLocatorService;
219
- /**
220
- * Evaluates a function on the matched element.
221
- *
222
- * @example
223
- * ```ts
224
- * import { PlaywrightBrowser } from "effect-playwright";
225
- * import { PlaywrightEnvironment } from "effect-playwright/experimental";
226
- * import { chromium } from "@playwright/test";
227
- * import { Effect } from "effect";
228
- *
229
- * const program = Effect.gen(function* () {
230
- * const browser = yield* PlaywrightBrowser;
231
- * const page = yield* browser.newPage();
232
- * const locator = yield* page.locator("button");
233
- * const buttonContent = yield* locator.evaluate((button) => button.textContent());
234
- * }).pipe(PlaywrightEnvironment.provideBrowser, Effect.provide(PlaywrightEnvironment.layer(chromium)));
235
- * ```
236
- *
237
- * @see {@link Locator.evaluate}
238
- * @since 0.1.0
239
- */
240
- readonly evaluate: <R, Arg = void, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: (element: E, arg: Unboxed<Arg>) => R | Promise<R>, arg?: Arg, options?: {
241
- timeout?: number;
242
- }) => Effect.Effect<R, PlaywrightError>;
243
- /**
244
- * A generic utility to execute any promise-based method on the underlying Playwright `Locator`.
245
- * Can be used to access any Locator functionality not directly exposed by this service.
246
- *
247
- * @example
248
- * ```typescript
249
- * const isVisible = yield* locator.use((l) => l.isVisible());
250
- * ```
251
- *
252
- * @param f - A function that takes the Playwright `Locator` and returns a `Promise`.
253
- * @returns An effect that wraps the promise and returns its result.
254
- * @see {@link Locator}
255
- * @since 0.1.0
256
- */
257
- readonly use: <T$1>(f: (locator: Locator) => Promise<T$1>) => Effect.Effect<T$1, PlaywrightError>;
258
- }
259
- declare const PlaywrightLocator_base: Context.TagClass<PlaywrightLocator, "effect-playwright/PlaywrightLocator", PlaywrightLocatorService>;
260
- /**
261
- * A service that provides a `PlaywrightLocator` instance.
262
- *
263
- * @since 0.1.0
264
- * @category tag
265
- */
266
- declare class PlaywrightLocator extends PlaywrightLocator_base {
267
- /**
268
- * Creates a `PlaywrightLocator` from a Playwright `Locator` instance. This is mostly for internal use.
269
- * But you could use this if you have used `use` or similar to wrap the locator.
270
- *
271
- * @example
272
- * ```ts
273
- * const playwrightNativeLocator = yield* page.use((p) => p.locator("button"));
274
- * const locator = PlaywrightLocator.make(playwrightNativeLocator);
275
- * ```
276
- *
277
- * @param locator - The Playwright `Locator` instance to wrap.
278
- * @since 0.1.0
279
- * @category constructor
280
- */
281
- static make(locator: Locator): typeof PlaywrightLocator.Service;
282
- }
283
- //#endregion
284
- //#region src/page.d.ts
285
- interface PlaywrightPageService {
286
- /**
287
- * Navigates the page to the given URL.
288
- *
289
- * @example
290
- * ```ts
291
- * yield* page.goto("https://google.com");
292
- * ```
293
- *
294
- * @see {@link Page.goto}
295
- * @since 0.1.0
296
- */
297
- readonly goto: (url: string, options?: Parameters<Page["goto"]>[1]) => Effect.Effect<void, PlaywrightError>;
298
- /**
299
- * Waits for the page to navigate to the given URL.
300
- *
301
- * @example
302
- * ```ts
303
- * yield* page.waitForURL("https://google.com");
304
- * ```
305
- *
306
- * @see {@link Page.waitForURL}
307
- * @since 0.1.0
308
- */
309
- readonly waitForURL: (url: Parameters<Page["waitForURL"]>[0], options?: Parameters<Page["waitForURL"]>[1]) => Effect.Effect<void, PlaywrightError>;
310
- /**
311
- * Evaluates a function in the context of the page.
312
- *
313
- * @example
314
- * ```ts
315
- * const dimensions = yield* page.evaluate(() => ({
316
- * width: document.documentElement.clientWidth,
317
- * height: document.documentElement.clientHeight
318
- * }));
319
- * ```
320
- *
321
- * @see {@link Page.evaluate}
322
- * @since 0.1.0
323
- */
324
- readonly evaluate: <R, Arg = void>(pageFunction: PageFunction<Arg, R>, arg?: Arg) => Effect.Effect<R, PlaywrightError>;
325
- /**
326
- * Returns the page title.
327
- *
328
- * @example
329
- * ```ts
330
- * const title = yield* page.title;
331
- * ```
332
- *
333
- * @see {@link Page.title}
334
- * @since 0.1.0
335
- */
336
- readonly title: Effect.Effect<string, PlaywrightError>;
337
- /**
338
- * A generic utility to execute any promise-based method on the underlying Playwright `Page`.
339
- * Can be used to access any Page functionality not directly exposed by this service.
340
- *
341
- * @example
342
- * ```ts
343
- * const title = yield* page.use((p) => p.title());
344
- * ```
345
- *
346
- * @see {@link Page}
347
- * @since 0.1.0
348
- */
349
- readonly use: <T$1>(f: (page: Page) => Promise<T$1>) => Effect.Effect<T$1, PlaywrightError>;
350
- /**
351
- * Returns a locator for the given selector.
352
- *
353
- * @see {@link Page.locator}
354
- * @since 0.1.0
355
- */
356
- readonly locator: (selector: string, options?: Parameters<Page["locator"]>[1]) => typeof PlaywrightLocator.Service;
357
- /**
358
- * Returns a locator that matches the given role.
359
- *
360
- * @see {@link Page.getByRole}
361
- * @since 0.1.0
362
- */
363
- readonly getByRole: (role: Parameters<Page["getByRole"]>[0], options?: Parameters<Page["getByRole"]>[1]) => typeof PlaywrightLocator.Service;
364
- /**
365
- * Returns a locator that matches the given text.
366
- *
367
- * @see {@link Page.getByText}
368
- * @since 0.1.0
369
- */
370
- readonly getByText: (text: Parameters<Page["getByText"]>[0], options?: Parameters<Page["getByText"]>[1]) => typeof PlaywrightLocator.Service;
371
- /**
372
- * Returns a locator that matches the given label.
373
- *
374
- * @see {@link Page.getByLabel}
375
- * @since 0.1.0
376
- */
377
- readonly getByLabel: (label: Parameters<Page["getByLabel"]>[0], options?: Parameters<Page["getByLabel"]>[1]) => typeof PlaywrightLocator.Service;
378
- /**
379
- * Returns a locator that matches the given test id.
380
- *
381
- * @see {@link Page.getByTestId}
382
- * @since 0.1.0
383
- */
384
- readonly getByTestId: (testId: Parameters<Page["getByTestId"]>[0]) => typeof PlaywrightLocator.Service;
385
- /**
386
- * Reloads the page.
387
- *
388
- * @see {@link Page.reload}
389
- * @since 0.1.0
390
- */
391
- readonly reload: Effect.Effect<void, PlaywrightError>;
392
- /**
393
- * Closes the page.
394
- *
395
- * @see {@link Page.close}
396
- * @since 0.1.0
397
- */
398
- readonly close: Effect.Effect<void, PlaywrightError>;
399
- /**
400
- * Returns the current URL of the page.
401
- *
402
- * @example
403
- * ```ts
404
- * const url = yield* page.url;
405
- * ```
406
- *
407
- * @see {@link Page.url}
408
- * @since 0.1.0
409
- */
410
- readonly url: Effect.Effect<string, PlaywrightError>;
411
- /**
412
- * Creates a stream of the given event from the page.
413
- *
414
- * @example
415
- * ```ts
416
- * const consoleStream = page.eventStream("console");
417
- * ```
418
- *
419
- * @see {@link Page.on}
420
- * @since 0.1.0
421
- */
422
- readonly eventStream: <K extends keyof typeof eventMappings>(event: K) => Stream.Stream<ReturnType<(typeof eventMappings)[K]>>;
423
- /**
424
- * Clicks an element matching the given selector.
425
- *
426
- * @example
427
- * ```ts
428
- * yield* page.click("button#submit");
429
- * ```
430
- * @deprecated Use {@link PlaywrightPageService.locator} to create a locator and then call `click` on it instead.
431
- * @see {@link Page.click}
432
- * @since 0.1.0
433
- * @category deprecated
434
- */
435
- readonly click: (selector: string, options?: Parameters<Page["click"]>[1]) => Effect.Effect<void, PlaywrightError>;
436
- }
437
- declare const PlaywrightPage_base: Context.TagClass<PlaywrightPage, "effect-playwright/PlaywrightPage", PlaywrightPageService>;
438
- /**
439
- * @category tag
440
- */
441
- declare class PlaywrightPage extends PlaywrightPage_base {
442
- /**
443
- * Creates a `PlaywrightPage` from a Playwright `Page` instance.
444
- *
445
- * @param page - The Playwright `Page` instance to wrap.
446
- * @since 0.1.0
447
- */
448
- static make(page: PageWithPatchedEvents): PlaywrightPageService;
449
- }
450
- interface PageEvents {
451
- close: Page;
452
- console: ConsoleMessage;
453
- crash: Page;
454
- dialog: Dialog;
455
- domcontentloaded: Page;
456
- download: Download;
457
- filechooser: FileChooser;
458
- frameattached: Frame;
459
- framedetached: Frame;
460
- framenavigated: Frame;
461
- load: Page;
462
- pageerror: Error;
463
- popup: Page;
464
- request: Request;
465
- requestfailed: Request;
466
- requestfinished: Request;
467
- response: Response;
468
- websocket: WebSocket;
469
- worker: Worker;
470
- }
471
- type PageEvent = keyof PageEvents;
472
- declare const eventMappings: {
473
- readonly close: typeof PlaywrightPage.make;
474
- readonly console: (a: ConsoleMessage) => ConsoleMessage;
475
- readonly crash: typeof PlaywrightPage.make;
476
- readonly dialog: typeof PlaywrightDialog.make;
477
- readonly domcontentloaded: typeof PlaywrightPage.make;
478
- readonly download: typeof PlaywrightDownload.make;
479
- readonly filechooser: typeof PlaywrightFileChooser.make;
480
- readonly frameattached: typeof PlaywrightFrame.make;
481
- readonly framedetached: typeof PlaywrightFrame.make;
482
- readonly framenavigated: typeof PlaywrightFrame.make;
483
- readonly load: typeof PlaywrightPage.make;
484
- readonly pageerror: (a: Error) => Error;
485
- readonly popup: typeof PlaywrightPage.make;
486
- readonly request: typeof PlaywrightRequest.make;
487
- readonly requestfailed: typeof PlaywrightRequest.make;
488
- readonly requestfinished: typeof PlaywrightRequest.make;
489
- readonly response: typeof PlaywrightResponse.make;
490
- readonly websocket: (a: WebSocket) => WebSocket;
491
- readonly worker: typeof PlaywrightWorker.make;
492
- };
493
- /**
494
- * Page interface with generic on/off methods.
495
- * Playwright's Page uses overloads for on/off, making generic event handling impossible.
496
- * This interface provides a unified signature for our event map.
497
- * @internal
498
- */
499
- interface PageWithPatchedEvents extends Page {
500
- on<K extends PageEvent>(event: K, listener: (arg: PageEvents[K]) => void): this;
501
- off<K extends PageEvent>(event: K, listener: (arg: PageEvents[K]) => void): this;
502
- }
503
- //#endregion
504
- //#region src/browser-context.d.ts
505
- declare const PlaywrightBrowserContext_base: Context.TagClass<PlaywrightBrowserContext, "cehs/backend/lib/playwright/PlaywrightBrowserContext", {
506
- readonly pages: Effect.Effect<Array<typeof PlaywrightPage.Service>>;
507
- readonly newPage: Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
508
- readonly close: Effect.Effect<void, PlaywrightError>;
509
- }>;
510
- declare class PlaywrightBrowserContext extends PlaywrightBrowserContext_base {
511
- static make(context: BrowserContext): {
512
- readonly pages: Effect.Effect<Array<typeof PlaywrightPage.Service>>;
513
- readonly newPage: Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
514
- readonly close: Effect.Effect<void, PlaywrightError>;
515
- };
516
- }
517
- //#endregion
518
- //#region src/browser.d.ts
519
- type LaunchOptions$1 = Parameters<typeof chromium.launch>[0];
520
- type NewPageOptions = Parameters<Browser["newPage"]>[0];
521
- type NewContextOptions = Parameters<Browser["newContext"]>[0];
522
- declare const PlaywrightBrowser_base: Context.TagClass<PlaywrightBrowser, "cehs/backend/lib/playwright/PlaywrightBrowser", {
523
- /**
524
- * Opens a new page in the browser.
525
- *
526
- * @example
527
- * ```typescript
528
- * const page = yield* browser.newPage();
529
- * ```
530
- *
531
- * @param options - Optional options for creating the new page.
532
- * @returns An effect that resolves to a `PlaywrightPage` service.
533
- * @see {@link Browser.newPage}
534
- */
535
- readonly newPage: (options?: NewPageOptions) => Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
536
- /**
537
- * A generic utility to execute any promise-based method on the underlying Playwright `Browser`.
538
- * Can be used to access any Browser functionality not directly exposed by this service.
539
- *
540
- * @example
541
- * ```typescript
542
- * const contexts = yield* browser.use((b) => b.contexts());
543
- * ```
544
- *
545
- * @param f - A function that takes the Playwright `Browser` and returns a `Promise`.
546
- * @returns An effect that wraps the promise and returns its result.
547
- * @see {@link Browser}
548
- */
549
- readonly use: <T$1>(f: (browser: Browser) => Promise<T$1>) => Effect.Effect<T$1, PlaywrightError>;
550
- /**
551
- * An Effect that closes the browser and all of its pages.
552
- * @see {@link Browser.close}
553
- */
554
- readonly close: Effect.Effect<void, PlaywrightError>;
555
- /**
556
- * An Effect that returns the list of all open browser contexts.
557
- * @see {@link Browser.contexts}
558
- */
559
- readonly contexts: Effect.Effect<Array<typeof PlaywrightBrowserContext.Service>>;
560
- readonly newContext: (options?: NewContextOptions) => Effect.Effect<typeof PlaywrightBrowserContext.Service, PlaywrightError, Scope$1>;
561
- /**
562
- * An Effect that returns the browser type (chromium, firefox or webkit) that the browser belongs to.
563
- * @see {@link Browser.browserType}
564
- */
565
- readonly browserType: Effect.Effect<BrowserType>;
566
- /**
567
- * An Effect that returns the version of the browser.
568
- * @see {@link Browser.version}
569
- */
570
- readonly version: Effect.Effect<string>;
571
- /**
572
- * An Effect that returns whether the browser is connected.
573
- * @see {@link Browser.isConnected}
574
- */
575
- readonly isConnected: Effect.Effect<boolean>;
576
- }>;
577
- /**
578
- * @category tag
579
- */
580
- declare class PlaywrightBrowser extends PlaywrightBrowser_base {
581
- /**
582
- * @category constructor
583
- */
584
- static make(browser: Browser): {
585
- /**
586
- * Opens a new page in the browser.
587
- *
588
- * @example
589
- * ```typescript
590
- * const page = yield* browser.newPage();
591
- * ```
592
- *
593
- * @param options - Optional options for creating the new page.
594
- * @returns An effect that resolves to a `PlaywrightPage` service.
595
- * @see {@link Browser.newPage}
596
- */
597
- readonly newPage: (options?: NewPageOptions) => Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
598
- /**
599
- * A generic utility to execute any promise-based method on the underlying Playwright `Browser`.
600
- * Can be used to access any Browser functionality not directly exposed by this service.
601
- *
602
- * @example
603
- * ```typescript
604
- * const contexts = yield* browser.use((b) => b.contexts());
605
- * ```
606
- *
607
- * @param f - A function that takes the Playwright `Browser` and returns a `Promise`.
608
- * @returns An effect that wraps the promise and returns its result.
609
- * @see {@link Browser}
610
- */
611
- readonly use: <T$1>(f: (browser: Browser) => Promise<T$1>) => Effect.Effect<T$1, PlaywrightError>;
612
- /**
613
- * An Effect that closes the browser and all of its pages.
614
- * @see {@link Browser.close}
615
- */
616
- readonly close: Effect.Effect<void, PlaywrightError>;
617
- /**
618
- * An Effect that returns the list of all open browser contexts.
619
- * @see {@link Browser.contexts}
620
- */
621
- readonly contexts: Effect.Effect<Array<typeof PlaywrightBrowserContext.Service>>;
622
- readonly newContext: (options?: NewContextOptions) => Effect.Effect<typeof PlaywrightBrowserContext.Service, PlaywrightError, Scope$1>;
623
- /**
624
- * An Effect that returns the browser type (chromium, firefox or webkit) that the browser belongs to.
625
- * @see {@link Browser.browserType}
626
- */
627
- readonly browserType: Effect.Effect<BrowserType>;
628
- /**
629
- * An Effect that returns the version of the browser.
630
- * @see {@link Browser.version}
631
- */
632
- readonly version: Effect.Effect<string>;
633
- /**
634
- * An Effect that returns whether the browser is connected.
635
- * @see {@link Browser.isConnected}
636
- */
637
- readonly isConnected: Effect.Effect<boolean>;
638
- };
639
- }
640
- //#endregion
641
- //#region src/playwright.d.ts
642
- interface PlaywrightService {
643
- /**
644
- * Launches a new browser instance.
645
- *
646
- * It is the caller's responsibility to manage the browser's lifecycle and close
647
- * it when no longer needed. For automatic scope-based management, use
648
- * {@link launchScoped} instead.
649
- *
650
- * ```ts
651
- * import { Effect } from "effect";
652
- * import { Playwright } from "effect-playwright";
653
- * import { chromium } from "playwright-core";
654
- *
655
- * const program = Effect.gen(function* () {
656
- * const browser = yield* Playwright.launch(chromium);
657
- * // ... use browser ...
658
- * yield* browser.close;
659
- * });
660
- *
661
- * await Effect.runPromise(program);
662
- * ```
663
- *
664
- * @param browserType - The browser type to launch (e.g. chromium, firefox, webkit).
665
- * @param options - Optional launch options.
666
- * @since 0.1.0
667
- */
668
- launch: (browserType: BrowserType, options?: LaunchOptions$1) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError>;
669
- /**
670
- * Launches a new browser instance managed by a Scope.
671
- *
672
- * This method automatically closes the browser when the scope is closed.
673
- *
674
- * ```ts
675
- * import { Effect } from "effect";
676
- * import { Playwright } from "effect-playwright";
677
- * import { chromium } from "playwright-core";
678
- *
679
- * const program = Effect.gen(function* () {
680
- * const browser = yield* Playwright.launchScoped(chromium);
681
- * // Browser will be closed automatically when scope closes
682
- * });
683
- *
684
- * await Effect.runPromise(program);
685
- * ```
686
- *
687
- * @param browserType - The browser type to launch (e.g. chromium, firefox, webkit).
688
- * @param options - Optional launch options.
689
- * @since 0.1.0
690
- */
691
- launchScoped: (browserType: BrowserType, options?: LaunchOptions$1) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError, Scope.Scope>;
692
- /**
693
- * Connects to a browser instance via Chrome DevTools Protocol (CDP).
694
- *
695
- * Unlike {@link connectCDPScoped}, this method does **not** close the connection when the
696
- * scope is closed. It is the caller's responsibility to manage the connection's
697
- * lifecycle.
698
- *
699
- * If you want to close the connection using a scope simply add a finalizer:
700
- *
701
- * ```ts
702
- * import { Effect } from "effect";
703
- * import { Playwright } from "effect-playwright";
704
- *
705
- * const program = Effect.gen(function* () {
706
- * const playwright = yield* Playwright;
707
- * const browser = yield* playwright.connectCDP(cdpUrl);
708
- * yield* Effect.addFinalizer(() => browser.close.pipe(Effect.ignore));
709
- * });
710
- *
711
- * await Effect.runPromise(program);
712
- * ```
713
- *
714
- * @param cdpUrl - The CDP URL to connect to.
715
- * @param options - Optional options for connecting to the CDP URL.
716
- * @since 0.1.0
717
- */
718
- connectCDP: (cdpUrl: string, options?: ConnectOverCDPOptions) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError>;
719
- /**
720
- * Connects to a browser instance via Chrome DevTools Protocol (CDP) managed by a Scope.
721
- *
722
- * This method automatically closes the connection when the scope is closed.
723
- *
724
- * Note that closing a CDP connection does **not** close the browser instance itself,
725
- * only the CDP connection.
726
- *
727
- * ```ts
728
- * import { Effect } from "effect";
729
- * import { Playwright } from "effect-playwright";
730
- *
731
- * const program = Effect.gen(function* () {
732
- * const playwright = yield* Playwright;
733
- * const browser = yield* playwright.connectCDPScoped(cdpUrl);
734
- * // Connection will be closed automatically when scope closes
735
- * });
736
- *
737
- * await Effect.runPromise(program);
738
- * ```
739
- *
740
- * @param cdpUrl - The CDP URL to connect to.
741
- * @param options - Optional options for connecting to the CDP URL.
742
- * @since 0.1.1
743
- */
744
- connectCDPScoped: (cdpUrl: string, options?: ConnectOverCDPOptions) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError, Scope.Scope>;
745
- }
746
- declare const Playwright_base: Context.TagClass<Playwright, "effect-playwright/index/Playwright", PlaywrightService>;
747
- declare class Playwright extends Playwright_base {
748
- /**
749
- * @category layer
750
- */
751
- static readonly layer: Layer.Layer<Playwright, never, never>;
752
- }
753
- //#endregion
754
- export { NewPageOptions as a, PlaywrightPageService as c, PlaywrightError as d, NewContextOptions as i, PlaywrightLocator as l, PlaywrightService as n, PlaywrightBrowser as o, LaunchOptions$1 as r, PlaywrightPage as s, Playwright as t, PlaywrightLocatorService as u };