effect-playwright 0.1.1 → 0.2.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,1004 @@
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, Response, WebError, WebSocket, Worker, 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
+ /**
9
+ * Playwright does not provide detailed error information but there is
10
+ * a distinction between timeout and other errors.
11
+ *
12
+ * @category error
13
+ * @since 0.1.0
14
+ */
15
+ type PlaywrightErrorReason = "Timeout" | "Unknown";
16
+ 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 & {
17
+ readonly _tag: "PlaywrightError";
18
+ } & Readonly<A>;
19
+ /**
20
+ * Error type that is returned when a Playwright error occurs.
21
+ * Reason can either be "Timeout" or "Unknown".
22
+ *
23
+ * Timeout errors occur when a timeout is reached. All other errors are
24
+ * grouped under "Unknown".
25
+ *
26
+ * @category error
27
+ * @since 0.1.0
28
+ */
29
+ declare class PlaywrightError extends PlaywrightError_base<{
30
+ reason: PlaywrightErrorReason;
31
+ cause: unknown;
32
+ }> {}
33
+ //#endregion
34
+ //#region src/playwright-types.d.ts
35
+ /**
36
+ * Extracted from `playwright-core/types/structs.d.ts` because it is not exported over the package boundary.
37
+ * These types are necessary to correctly type `evaluate` functions that unwrap handles.
38
+ */
39
+ type NoHandles<Arg> = Arg extends JSHandle ? never : Arg extends object ? { [Key in keyof Arg]: NoHandles<Arg[Key]> } : Arg;
40
+ 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;
41
+ type PageFunction<Arg, R> = string | ((arg: Unboxed<Arg>) => R | Promise<R>);
42
+ /**
43
+ * A type helper to patch the `on`, `off`, and `once` methods of a Playwright object
44
+ * to support a specific set of events with correctly typed listeners.
45
+ *
46
+ * This is useful because Playwright's event methods are often overloaded,
47
+ * making them difficult to use in generic contexts or with custom event maps.
48
+ *
49
+ * @internal
50
+ */
51
+ type PatchedEvents<Original, Events> = Original & {
52
+ on<K extends keyof Events>(event: K, listener: (arg: Events[K]) => void): PatchedEvents<Original, Events>;
53
+ off<K extends keyof Events>(event: K, listener: (arg: Events[K]) => void): PatchedEvents<Original, Events>;
54
+ once<K extends keyof Events>(event: K, listener: (arg: Events[K]) => void): PatchedEvents<Original, Events>;
55
+ };
56
+ //#endregion
57
+ //#region src/locator.d.ts
58
+ /**
59
+ * Interface for a Playwright locator.
60
+ * @category model
61
+ */
62
+ interface PlaywrightLocatorService {
63
+ /**
64
+ * Clicks the element.
65
+ *
66
+ * @see {@link Locator.click}
67
+ * @since 0.1.0
68
+ */
69
+ readonly click: (options?: Parameters<Locator["click"]>[0]) => Effect.Effect<void, PlaywrightError>;
70
+ /**
71
+ * Fills the input field.
72
+ *
73
+ * @see {@link Locator.fill}
74
+ * @since 0.1.0
75
+ */
76
+ readonly fill: (value: string, options?: Parameters<Locator["fill"]>[1]) => Effect.Effect<void, PlaywrightError>;
77
+ /**
78
+ * Gets an attribute value.
79
+ *
80
+ * @see {@link Locator.getAttribute}
81
+ * @since 0.1.0
82
+ */
83
+ readonly getAttribute: (name: string, options?: Parameters<Locator["getAttribute"]>[1]) => Effect.Effect<string | null, PlaywrightError>;
84
+ /**
85
+ * Gets the inner text.
86
+ *
87
+ * @see {@link Locator.innerText}
88
+ * @since 0.1.0
89
+ */
90
+ readonly innerText: (options?: Parameters<Locator["innerText"]>[0]) => Effect.Effect<string, PlaywrightError>;
91
+ /**
92
+ * Gets the inner HTML.
93
+ *
94
+ * @see {@link Locator.innerHTML}
95
+ * @since 0.1.0
96
+ */
97
+ readonly innerHTML: (options?: Parameters<Locator["innerHTML"]>[0]) => Effect.Effect<string, PlaywrightError>;
98
+ /**
99
+ * Gets the input value.
100
+ *
101
+ * @see {@link Locator.inputValue}
102
+ * @since 0.1.0
103
+ */
104
+ readonly inputValue: (options?: Parameters<Locator["inputValue"]>[0]) => Effect.Effect<string, PlaywrightError>;
105
+ /**
106
+ * Gets the text content.
107
+ *
108
+ * @see {@link Locator.textContent}
109
+ * @since 0.1.0
110
+ */
111
+ readonly textContent: (options?: Parameters<Locator["textContent"]>[0]) => Effect.Effect<string | null, PlaywrightError>;
112
+ /**
113
+ * Counts the number of matched elements.
114
+ *
115
+ * @see {@link Locator.count}
116
+ * @since 0.1.0
117
+ */
118
+ readonly count: Effect.Effect<number, PlaywrightError>;
119
+ /**
120
+ * Returns a locator that points to the first matched element.
121
+ * @see {@link Locator.first}
122
+ * @since 0.1.0
123
+ */
124
+ readonly first: () => PlaywrightLocatorService;
125
+ /**
126
+ * Returns a locator that points to the last matched element.
127
+ *
128
+ * @see {@link Locator.last}
129
+ * @since 0.1.0
130
+ */
131
+ readonly last: () => PlaywrightLocatorService;
132
+ /**
133
+ * Returns a locator that points to the nth matched element.
134
+ *
135
+ * @see {@link Locator.nth}
136
+ * @since 0.1.0
137
+ */
138
+ readonly nth: (index: number) => PlaywrightLocatorService;
139
+ /**
140
+ * Evaluates a function on the matched element.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * import { PlaywrightBrowser } from "effect-playwright";
145
+ * import { PlaywrightEnvironment } from "effect-playwright/experimental";
146
+ * import { chromium } from "@playwright/test";
147
+ * import { Effect } from "effect";
148
+ *
149
+ * const program = Effect.gen(function* () {
150
+ * const browser = yield* PlaywrightBrowser;
151
+ * const page = yield* browser.newPage();
152
+ * const locator = yield* page.locator("button");
153
+ * const buttonContent = yield* locator.evaluate((button) => button.textContent());
154
+ * }).pipe(PlaywrightEnvironment.provideBrowser, Effect.provide(PlaywrightEnvironment.layer(chromium)));
155
+ * ```
156
+ *
157
+ * @see {@link Locator.evaluate}
158
+ * @since 0.1.0
159
+ */
160
+ readonly evaluate: <R, Arg = void, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: (element: E, arg: Unboxed<Arg>) => R | Promise<R>, arg?: Arg, options?: {
161
+ timeout?: number;
162
+ }) => Effect.Effect<R, PlaywrightError>;
163
+ /**
164
+ * A generic utility to execute any promise-based method on the underlying Playwright `Locator`.
165
+ * Can be used to access any Locator functionality not directly exposed by this service.
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const isVisible = yield* locator.use((l) => l.isVisible());
170
+ * ```
171
+ *
172
+ * @param f - A function that takes the Playwright `Locator` and returns a `Promise`.
173
+ * @returns An effect that wraps the promise and returns its result.
174
+ * @see {@link Locator}
175
+ * @since 0.1.0
176
+ */
177
+ readonly use: <T>(f: (locator: Locator) => Promise<T>) => Effect.Effect<T, PlaywrightError>;
178
+ }
179
+ declare const PlaywrightLocator_base: Context.TagClass<PlaywrightLocator, "effect-playwright/PlaywrightLocator", PlaywrightLocatorService>;
180
+ /**
181
+ * A service that provides a `PlaywrightLocator` instance.
182
+ *
183
+ * @since 0.1.0
184
+ * @category tag
185
+ */
186
+ declare class PlaywrightLocator extends PlaywrightLocator_base {
187
+ /**
188
+ * Creates a `PlaywrightLocator` from a Playwright `Locator` instance. This is mostly for internal use.
189
+ * But you could use this if you have used `use` or similar to wrap the locator.
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * const playwrightNativeLocator = yield* page.use((p) => p.locator("button"));
194
+ * const locator = PlaywrightLocator.make(playwrightNativeLocator);
195
+ * ```
196
+ *
197
+ * @param locator - The Playwright `Locator` instance to wrap.
198
+ * @since 0.1.0
199
+ * @category constructor
200
+ */
201
+ static make(locator: Locator): typeof PlaywrightLocator.Service;
202
+ }
203
+ //#endregion
204
+ //#region src/frame.d.ts
205
+ /**
206
+ * @category model
207
+ * @since 0.1.2
208
+ */
209
+ interface PlaywrightFrameService {
210
+ /**
211
+ * Navigates the frame to the given URL.
212
+ *
213
+ * @see {@link Frame.goto}
214
+ * @since 0.1.3
215
+ */
216
+ readonly goto: (url: string, options?: Parameters<Frame["goto"]>[1]) => Effect.Effect<void, PlaywrightError>;
217
+ /**
218
+ * Waits for the frame to navigate to the given URL.
219
+ *
220
+ * @see {@link Frame.waitForURL}
221
+ * @since 0.1.3
222
+ */
223
+ readonly waitForURL: (url: Parameters<Frame["waitForURL"]>[0], options?: Parameters<Frame["waitForURL"]>[1]) => Effect.Effect<void, PlaywrightError>;
224
+ /**
225
+ * Waits for the frame to reach the given load state.
226
+ *
227
+ * @see {@link Frame.waitForLoadState}
228
+ * @since 0.2.0
229
+ */
230
+ readonly waitForLoadState: (state?: Parameters<Frame["waitForLoadState"]>[0], options?: Parameters<Frame["waitForLoadState"]>[1]) => Effect.Effect<void, PlaywrightError>;
231
+ /**
232
+ * Evaluates a function in the context of the frame.
233
+ *
234
+ * @see {@link Frame.evaluate}
235
+ * @since 0.1.3
236
+ */
237
+ readonly evaluate: <R, Arg = void>(pageFunction: PageFunction<Arg, R>, arg?: Arg) => Effect.Effect<R, PlaywrightError>;
238
+ /**
239
+ * Returns the frame title.
240
+ *
241
+ * @see {@link Frame.title}
242
+ * @since 0.1.3
243
+ */
244
+ readonly title: Effect.Effect<string, PlaywrightError>;
245
+ /**
246
+ * A generic utility to execute any promise-based method on the underlying Playwright `Frame`.
247
+ * Can be used to access any Frame functionality not directly exposed by this service.
248
+ *
249
+ * @see {@link Frame}
250
+ * @since 0.1.2
251
+ */
252
+ readonly use: <T>(f: (frame: Frame) => Promise<T>) => Effect.Effect<T, PlaywrightError>;
253
+ /**
254
+ * Returns a locator for the given selector.
255
+ *
256
+ * @see {@link Frame.locator}
257
+ * @since 0.1.3
258
+ */
259
+ readonly locator: (selector: string, options?: Parameters<Frame["locator"]>[1]) => typeof PlaywrightLocator.Service;
260
+ /**
261
+ * Returns a locator that matches the given role.
262
+ *
263
+ * @see {@link Frame.getByRole}
264
+ * @since 0.1.3
265
+ */
266
+ readonly getByRole: (role: Parameters<Frame["getByRole"]>[0], options?: Parameters<Frame["getByRole"]>[1]) => typeof PlaywrightLocator.Service;
267
+ /**
268
+ * Returns a locator that matches the given text.
269
+ *
270
+ * @see {@link Frame.getByText}
271
+ * @since 0.1.3
272
+ */
273
+ readonly getByText: (text: Parameters<Frame["getByText"]>[0], options?: Parameters<Frame["getByText"]>[1]) => typeof PlaywrightLocator.Service;
274
+ /**
275
+ * Returns a locator that matches the given label.
276
+ *
277
+ * @see {@link Frame.getByLabel}
278
+ * @since 0.1.3
279
+ */
280
+ readonly getByLabel: (label: Parameters<Frame["getByLabel"]>[0], options?: Parameters<Frame["getByLabel"]>[1]) => typeof PlaywrightLocator.Service;
281
+ /**
282
+ * Returns a locator that matches the given test id.
283
+ *
284
+ * @see {@link Frame.getByTestId}
285
+ * @since 0.1.3
286
+ */
287
+ readonly getByTestId: (testId: Parameters<Frame["getByTestId"]>[0]) => typeof PlaywrightLocator.Service;
288
+ /**
289
+ * Returns the current URL of the frame.
290
+ *
291
+ * @see {@link Frame.url}
292
+ * @since 0.1.3
293
+ */
294
+ readonly url: Effect.Effect<string, PlaywrightError>;
295
+ /**
296
+ * Returns the full HTML contents of the frame, including the doctype.
297
+ *
298
+ * @see {@link Frame.content}
299
+ * @since 0.1.3
300
+ */
301
+ readonly content: Effect.Effect<string, PlaywrightError>;
302
+ /**
303
+ * Returns the frame name.
304
+ *
305
+ * @see {@link Frame.name}
306
+ * @since 0.1.3
307
+ */
308
+ readonly name: Effect.Effect<string>;
309
+ /**
310
+ * Clicks an element matching the given selector.
311
+ *
312
+ * @deprecated Use {@link PlaywrightFrameService.locator} to create a locator and then call `click` on it instead.
313
+ * @see {@link Frame.click}
314
+ * @since 0.1.3
315
+ * @category deprecated
316
+ */
317
+ readonly click: (selector: string, options?: Parameters<Frame["click"]>[1]) => Effect.Effect<void, PlaywrightError>;
318
+ }
319
+ declare const PlaywrightFrame_base: Context.TagClass<PlaywrightFrame, "effect-playwright/PlaywrightFrame", PlaywrightFrameService>;
320
+ /**
321
+ * @category tag
322
+ * @since 0.1.2
323
+ */
324
+ declare class PlaywrightFrame extends PlaywrightFrame_base {
325
+ /**
326
+ * Creates a `PlaywrightFrame` from a Playwright `Frame` instance.
327
+ *
328
+ * @param frame - The Playwright `Frame` instance to wrap.
329
+ * @since 0.1.2
330
+ */
331
+ static make(frame: Frame): PlaywrightFrameService;
332
+ }
333
+ //#endregion
334
+ //#region src/common.d.ts
335
+ 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> & {
336
+ readonly _tag: "PlaywrightRequest";
337
+ };
338
+ /**
339
+ * @category model
340
+ * @since 0.1.2
341
+ */
342
+ declare class PlaywrightRequest extends PlaywrightRequest_base<{
343
+ allHeaders: Effect.Effect<Awaited<ReturnType<Request["allHeaders"]>>, PlaywrightError>;
344
+ failure: () => Option.Option<NonNullable<ReturnType<Request["failure"]>>>;
345
+ frame: Effect.Effect<PlaywrightFrameService>;
346
+ headerValue: (name: string) => Effect.Effect<Option.Option<string>, PlaywrightError>;
347
+ headers: Effect.Effect<ReturnType<Request["headers"]>>;
348
+ headersArray: Effect.Effect<Awaited<ReturnType<Request["headersArray"]>>, PlaywrightError>;
349
+ isNavigationRequest: Effect.Effect<boolean>;
350
+ method: Effect.Effect<string>;
351
+ postData: () => Option.Option<string>;
352
+ postDataBuffer: () => Option.Option<NonNullable<ReturnType<Request["postDataBuffer"]>>>;
353
+ postDataJSON: Effect.Effect<Option.Option<NonNullable<Awaited<ReturnType<Request["postDataJSON"]>>>>, PlaywrightError>;
354
+ redirectedFrom: () => Option.Option<PlaywrightRequest>;
355
+ redirectedTo: () => Option.Option<PlaywrightRequest>;
356
+ resourceType: Effect.Effect<ReturnType<Request["resourceType"]>>;
357
+ response: Effect.Effect<Option.Option<PlaywrightResponse>, PlaywrightError>;
358
+ serviceWorker: () => Option.Option<PlaywrightWorker>;
359
+ sizes: Effect.Effect<Awaited<ReturnType<Request["sizes"]>>, PlaywrightError>;
360
+ timing: Effect.Effect<ReturnType<Request["timing"]>>;
361
+ url: Effect.Effect<string>;
362
+ }> {
363
+ static make(request: Request): PlaywrightRequest;
364
+ }
365
+ 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> & {
366
+ readonly _tag: "PlaywrightResponse";
367
+ };
368
+ /**
369
+ * @category model
370
+ * @since 0.1.2
371
+ */
372
+ declare class PlaywrightResponse extends PlaywrightResponse_base<{
373
+ allHeaders: Effect.Effect<Awaited<ReturnType<Response["allHeaders"]>>, PlaywrightError>;
374
+ body: Effect.Effect<Awaited<ReturnType<Response["body"]>>, PlaywrightError>;
375
+ finished: Effect.Effect<Awaited<ReturnType<Response["finished"]>>, PlaywrightError>;
376
+ frame: Effect.Effect<PlaywrightFrameService>;
377
+ fromServiceWorker: Effect.Effect<boolean>;
378
+ headers: Effect.Effect<ReturnType<Response["headers"]>>;
379
+ headersArray: Effect.Effect<Awaited<ReturnType<Response["headersArray"]>>, PlaywrightError>;
380
+ headerValue: (name: string) => Effect.Effect<Option.Option<string>, PlaywrightError>;
381
+ headerValues: (name: string) => Effect.Effect<Awaited<ReturnType<Response["headerValues"]>>, PlaywrightError>;
382
+ json: Effect.Effect<Awaited<ReturnType<Response["json"]>>, PlaywrightError>;
383
+ ok: Effect.Effect<boolean>;
384
+ request: () => PlaywrightRequest;
385
+ securityDetails: Effect.Effect<Option.Option<NonNullable<Awaited<ReturnType<Response["securityDetails"]>>>>, PlaywrightError>;
386
+ serverAddr: Effect.Effect<Option.Option<NonNullable<Awaited<ReturnType<Response["serverAddr"]>>>>, PlaywrightError>;
387
+ status: Effect.Effect<number>;
388
+ statusText: Effect.Effect<string>;
389
+ text: Effect.Effect<Awaited<ReturnType<Response["text"]>>, PlaywrightError>;
390
+ url: Effect.Effect<string>;
391
+ }> {
392
+ static make(response: Response): PlaywrightResponse;
393
+ }
394
+ 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> & {
395
+ readonly _tag: "PlaywrightWorker";
396
+ };
397
+ /**
398
+ * @category model
399
+ * @since 0.1.2
400
+ */
401
+ declare class PlaywrightWorker extends PlaywrightWorker_base<{
402
+ evaluate: <R, Arg = void>(pageFunction: PageFunction<Arg, R>, arg?: Arg) => Effect.Effect<R, PlaywrightError>;
403
+ url: Effect.Effect<string>;
404
+ }> {
405
+ static make(worker: Worker): PlaywrightWorker;
406
+ }
407
+ 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> & {
408
+ readonly _tag: "PlaywrightDialog";
409
+ };
410
+ /**
411
+ * @category model
412
+ * @since 0.1.2
413
+ */
414
+ declare class PlaywrightDialog extends PlaywrightDialog_base<{
415
+ accept: (promptText?: string) => Effect.Effect<void, PlaywrightError>;
416
+ defaultValue: Effect.Effect<string>;
417
+ dismiss: Effect.Effect<void, PlaywrightError>;
418
+ message: Effect.Effect<string>;
419
+ page: () => Option.Option<PlaywrightPageService>;
420
+ type: Effect.Effect<string>;
421
+ }> {
422
+ static make(dialog: Dialog): PlaywrightDialog;
423
+ }
424
+ 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> & {
425
+ readonly _tag: "PlaywrightFileChooser";
426
+ };
427
+ /**
428
+ * @category model
429
+ * @since 0.1.2
430
+ */
431
+ declare class PlaywrightFileChooser extends PlaywrightFileChooser_base<{
432
+ element: () => ElementHandle;
433
+ isMultiple: Effect.Effect<boolean>;
434
+ page: () => PlaywrightPageService;
435
+ setFiles: (files: Parameters<FileChooser["setFiles"]>[0], options?: Parameters<FileChooser["setFiles"]>[1]) => Effect.Effect<void, PlaywrightError>;
436
+ }> {
437
+ static make(fileChooser: FileChooser): PlaywrightFileChooser;
438
+ }
439
+ 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> & {
440
+ readonly _tag: "PlaywrightDownload";
441
+ };
442
+ /**
443
+ * @category model
444
+ * @since 0.1.2
445
+ */
446
+ declare class PlaywrightDownload extends PlaywrightDownload_base<{
447
+ cancel: Effect.Effect<void, PlaywrightError>;
448
+ /**
449
+ * Creates a stream of the download data.
450
+ * @category custom
451
+ * @since 0.2.0
452
+ */
453
+ stream: Stream.Stream<Uint8Array, PlaywrightError>;
454
+ delete: Effect.Effect<void, PlaywrightError>;
455
+ failure: Effect.Effect<Option.Option<string | null>, PlaywrightError>;
456
+ page: () => PlaywrightPageService;
457
+ path: Effect.Effect<Option.Option<string | null>, PlaywrightError>;
458
+ saveAs: (path: string) => Effect.Effect<void, PlaywrightError>;
459
+ suggestedFilename: Effect.Effect<string>;
460
+ url: Effect.Effect<string>;
461
+ use: <R>(f: (download: Download) => Promise<R>) => Effect.Effect<R, PlaywrightError>;
462
+ }> {
463
+ static make(download: Download): PlaywrightDownload;
464
+ }
465
+ //#endregion
466
+ //#region src/page.d.ts
467
+ interface PageEvents {
468
+ close: Page;
469
+ console: ConsoleMessage;
470
+ crash: Page;
471
+ dialog: Dialog;
472
+ domcontentloaded: Page;
473
+ download: Download;
474
+ filechooser: FileChooser;
475
+ frameattached: Frame;
476
+ framedetached: Frame;
477
+ framenavigated: Frame;
478
+ load: Page;
479
+ pageerror: Error;
480
+ popup: Page;
481
+ request: Request;
482
+ requestfailed: Request;
483
+ requestfinished: Request;
484
+ response: Response;
485
+ websocket: WebSocket;
486
+ worker: Worker;
487
+ }
488
+ declare const eventMappings$2: {
489
+ readonly close: (page: Page) => PlaywrightPageService;
490
+ readonly console: (a: ConsoleMessage) => ConsoleMessage;
491
+ readonly crash: (page: Page) => PlaywrightPageService;
492
+ readonly dialog: (dialog: Dialog) => PlaywrightDialog;
493
+ readonly domcontentloaded: (page: Page) => PlaywrightPageService;
494
+ readonly download: (download: Download) => PlaywrightDownload;
495
+ readonly filechooser: (fileChooser: FileChooser) => PlaywrightFileChooser;
496
+ readonly frameattached: (frame: Frame) => PlaywrightFrameService;
497
+ readonly framedetached: (frame: Frame) => PlaywrightFrameService;
498
+ readonly framenavigated: (frame: Frame) => PlaywrightFrameService;
499
+ readonly load: (page: Page) => PlaywrightPageService;
500
+ readonly pageerror: (a: Error) => Error;
501
+ readonly popup: (page: Page) => PlaywrightPageService;
502
+ readonly request: (request: Request) => PlaywrightRequest;
503
+ readonly requestfailed: (request: Request) => PlaywrightRequest;
504
+ readonly requestfinished: (request: Request) => PlaywrightRequest;
505
+ readonly response: (response: Response) => PlaywrightResponse;
506
+ readonly websocket: (a: WebSocket) => WebSocket;
507
+ readonly worker: (worker: Worker) => PlaywrightWorker;
508
+ };
509
+ type PageWithPatchedEvents = PatchedEvents<Page, PageEvents>;
510
+ /**
511
+ * @category model
512
+ * @since 0.1.0
513
+ */
514
+ interface PlaywrightPageService {
515
+ /**
516
+ * Navigates the page to the given URL.
517
+ *
518
+ * @example
519
+ * ```ts
520
+ * yield* page.goto("https://google.com");
521
+ * ```
522
+ *
523
+ * @see {@link Page.goto}
524
+ * @since 0.1.0
525
+ */
526
+ readonly goto: (url: string, options?: Parameters<Page["goto"]>[1]) => Effect.Effect<void, PlaywrightError>;
527
+ /**
528
+ * Waits for the page to navigate to the given URL.
529
+ *
530
+ * @example
531
+ * ```ts
532
+ * yield* page.waitForURL("https://google.com");
533
+ * ```
534
+ *
535
+ * @see {@link Page.waitForURL}
536
+ * @since 0.1.0
537
+ */
538
+ readonly waitForURL: (url: Parameters<Page["waitForURL"]>[0], options?: Parameters<Page["waitForURL"]>[1]) => Effect.Effect<void, PlaywrightError>;
539
+ /**
540
+ * Waits for the page to reach the given load state.
541
+ *
542
+ * NOTE: Most of the time, this method is not needed because Playwright auto-waits before every action.
543
+ *
544
+ * @example
545
+ * ```ts
546
+ * yield* page.waitForLoadState("domcontentloaded");
547
+ * ```
548
+ *
549
+ * @see {@link Page.waitForLoadState}
550
+ * @since 0.2.0
551
+ */
552
+ readonly waitForLoadState: (state?: Parameters<Page["waitForLoadState"]>[0], options?: Parameters<Page["waitForLoadState"]>[1]) => Effect.Effect<void, PlaywrightError>;
553
+ /**
554
+ * Evaluates a function in the context of the page.
555
+ *
556
+ * @example
557
+ * ```ts
558
+ * const dimensions = yield* page.evaluate(() => ({
559
+ * width: document.documentElement.clientWidth,
560
+ * height: document.documentElement.clientHeight
561
+ * }));
562
+ * ```
563
+ *
564
+ * @see {@link Page.evaluate}
565
+ * @since 0.1.0
566
+ */
567
+ readonly evaluate: <R, Arg = void>(pageFunction: PageFunction<Arg, R>, arg?: Arg) => Effect.Effect<R, PlaywrightError>;
568
+ /**
569
+ * Returns the page title.
570
+ *
571
+ * @example
572
+ * ```ts
573
+ * const title = yield* page.title;
574
+ * ```
575
+ *
576
+ * @see {@link Page.title}
577
+ * @since 0.1.0
578
+ */
579
+ readonly title: Effect.Effect<string, PlaywrightError>;
580
+ /**
581
+ * A generic utility to execute any promise-based method on the underlying Playwright `Page`.
582
+ * Can be used to access any Page functionality not directly exposed by this service.
583
+ *
584
+ * @example
585
+ * ```ts
586
+ * const title = yield* page.use((p) => p.title());
587
+ * ```
588
+ *
589
+ * @see {@link Page}
590
+ * @since 0.1.0
591
+ */
592
+ readonly use: <T>(f: (page: Page) => Promise<T>) => Effect.Effect<T, PlaywrightError>;
593
+ /**
594
+ * Returns a locator for the given selector.
595
+ *
596
+ * @see {@link Page.locator}
597
+ * @since 0.1.0
598
+ */
599
+ readonly locator: (selector: string, options?: Parameters<Page["locator"]>[1]) => typeof PlaywrightLocator.Service;
600
+ /**
601
+ * Returns a locator that matches the given role.
602
+ *
603
+ * @see {@link Page.getByRole}
604
+ * @since 0.1.0
605
+ */
606
+ readonly getByRole: (role: Parameters<Page["getByRole"]>[0], options?: Parameters<Page["getByRole"]>[1]) => typeof PlaywrightLocator.Service;
607
+ /**
608
+ * Returns a locator that matches the given text.
609
+ *
610
+ * @see {@link Page.getByText}
611
+ * @since 0.1.0
612
+ */
613
+ readonly getByText: (text: Parameters<Page["getByText"]>[0], options?: Parameters<Page["getByText"]>[1]) => typeof PlaywrightLocator.Service;
614
+ /**
615
+ * Returns a locator that matches the given label.
616
+ *
617
+ * @see {@link Page.getByLabel}
618
+ * @since 0.1.0
619
+ */
620
+ readonly getByLabel: (label: Parameters<Page["getByLabel"]>[0], options?: Parameters<Page["getByLabel"]>[1]) => typeof PlaywrightLocator.Service;
621
+ /**
622
+ * Returns a locator that matches the given test id.
623
+ *
624
+ * @see {@link Page.getByTestId}
625
+ * @since 0.1.0
626
+ */
627
+ readonly getByTestId: (testId: Parameters<Page["getByTestId"]>[0]) => typeof PlaywrightLocator.Service;
628
+ /**
629
+ * Reloads the page.
630
+ *
631
+ * @see {@link Page.reload}
632
+ * @since 0.1.0
633
+ */
634
+ readonly reload: Effect.Effect<void, PlaywrightError>;
635
+ /**
636
+ * Closes the page.
637
+ *
638
+ * @see {@link Page.close}
639
+ * @since 0.1.0
640
+ */
641
+ readonly close: Effect.Effect<void, PlaywrightError>;
642
+ /**
643
+ * Returns the current URL of the page.
644
+ *
645
+ * @example
646
+ * ```ts
647
+ * const url = yield* page.url;
648
+ * ```
649
+ *
650
+ * @see {@link Page.url}
651
+ * @since 0.1.0
652
+ */
653
+ readonly url: Effect.Effect<string, PlaywrightError>;
654
+ /**
655
+ * Returns all frames attached to the page.
656
+ *
657
+ * @see {@link Page.frames}
658
+ * @since 0.2.0
659
+ */
660
+ readonly frames: Effect.Effect<ReadonlyArray<typeof PlaywrightFrame.Service>, PlaywrightError>;
661
+ /**
662
+ * Creates a stream of the given event from the page.
663
+ *
664
+ * @example
665
+ * ```ts
666
+ * const consoleStream = page.eventStream("console");
667
+ * ```
668
+ *
669
+ * @category custom
670
+ * @see {@link Page.on}
671
+ * @since 0.1.0
672
+ */
673
+ readonly eventStream: <K extends keyof PageEvents>(event: K) => Stream.Stream<ReturnType<(typeof eventMappings$2)[K]>>;
674
+ /**
675
+ * Clicks an element matching the given selector.
676
+ *
677
+ * @example
678
+ * ```ts
679
+ * yield* page.click("button#submit");
680
+ * ```
681
+ * @deprecated Use {@link PlaywrightPageService.locator} to create a locator and then call `click` on it instead.
682
+ * @see {@link Page.click}
683
+ * @since 0.1.0
684
+ * @category deprecated
685
+ */
686
+ readonly click: (selector: string, options?: Parameters<Page["click"]>[1]) => Effect.Effect<void, PlaywrightError>;
687
+ }
688
+ declare const PlaywrightPage_base: Context.TagClass<PlaywrightPage, "effect-playwright/PlaywrightPage", PlaywrightPageService>;
689
+ /**
690
+ * @category tag
691
+ */
692
+ declare class PlaywrightPage extends PlaywrightPage_base {
693
+ /**
694
+ * Creates a `PlaywrightPage` from a Playwright `Page` instance.
695
+ *
696
+ * @param page - The Playwright `Page` instance to wrap.
697
+ * @since 0.1.0
698
+ */
699
+ static make(page: PageWithPatchedEvents): PlaywrightPageService;
700
+ }
701
+ //#endregion
702
+ //#region src/browser-context.d.ts
703
+ interface BrowserContextEvents {
704
+ backgroundpage: Page;
705
+ close: BrowserContext;
706
+ console: ConsoleMessage;
707
+ dialog: Dialog;
708
+ page: Page;
709
+ request: Request;
710
+ requestfailed: Request;
711
+ requestfinished: Request;
712
+ response: Response;
713
+ serviceworker: Worker;
714
+ weberror: WebError;
715
+ }
716
+ declare const eventMappings$1: {
717
+ readonly backgroundpage: (page: Page) => PlaywrightPageService;
718
+ readonly close: (context: BrowserContext) => PlaywrightBrowserContextService;
719
+ readonly console: (a: ConsoleMessage) => ConsoleMessage;
720
+ readonly dialog: (dialog: Dialog) => PlaywrightDialog;
721
+ readonly page: (page: Page) => PlaywrightPageService;
722
+ readonly request: (request: Request) => PlaywrightRequest;
723
+ readonly requestfailed: (request: Request) => PlaywrightRequest;
724
+ readonly requestfinished: (request: Request) => PlaywrightRequest;
725
+ readonly response: (response: Response) => PlaywrightResponse;
726
+ readonly serviceworker: (worker: Worker) => PlaywrightWorker;
727
+ readonly weberror: (a: WebError) => WebError;
728
+ };
729
+ type BrowserContextWithPatchedEvents = PatchedEvents<BrowserContext, BrowserContextEvents>;
730
+ /**
731
+ * @category model
732
+ * @since 0.1.0
733
+ */
734
+ interface PlaywrightBrowserContextService {
735
+ /**
736
+ * Returns the list of all open pages in the browser context.
737
+ *
738
+ * @see {@link BrowserContext.pages}
739
+ * @since 0.1.0
740
+ */
741
+ readonly pages: Effect.Effect<Array<typeof PlaywrightPage.Service>>;
742
+ /**
743
+ * Opens a new page in the browser context.
744
+ *
745
+ * @example
746
+ * ```ts
747
+ * const page = yield* context.newPage;
748
+ * ```
749
+ *
750
+ * @see {@link BrowserContext.newPage}
751
+ * @since 0.1.0
752
+ */
753
+ readonly newPage: Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
754
+ /**
755
+ * Closes the browser context.
756
+ *
757
+ * @see {@link BrowserContext.close}
758
+ * @since 0.1.0
759
+ */
760
+ readonly close: Effect.Effect<void, PlaywrightError>;
761
+ /**
762
+ * Creates a stream of the given event from the browser context.
763
+ *
764
+ * @example
765
+ * ```ts
766
+ * const pageStream = context.eventStream("page");
767
+ * ```
768
+ *
769
+ * @category custom
770
+ * @see {@link BrowserContext.on}
771
+ * @since 0.1.2
772
+ */
773
+ readonly eventStream: <K extends keyof typeof eventMappings$1>(event: K) => Stream.Stream<ReturnType<(typeof eventMappings$1)[K]>>;
774
+ }
775
+ declare const PlaywrightBrowserContext_base: Context.TagClass<PlaywrightBrowserContext, "effect-playwright/PlaywrightBrowserContext", PlaywrightBrowserContextService>;
776
+ /**
777
+ * @category tag
778
+ */
779
+ declare class PlaywrightBrowserContext extends PlaywrightBrowserContext_base {
780
+ /**
781
+ * Creates a `PlaywrightBrowserContext` from a Playwright `BrowserContext` instance.
782
+ *
783
+ * @param context - The Playwright `BrowserContext` instance to wrap.
784
+ * @since 0.1.0
785
+ */
786
+ static make(context: BrowserContextWithPatchedEvents): PlaywrightBrowserContextService;
787
+ }
788
+ //#endregion
789
+ //#region src/browser.d.ts
790
+ type LaunchOptions$1 = Parameters<typeof chromium.launch>[0];
791
+ type NewPageOptions = Parameters<Browser["newPage"]>[0];
792
+ type NewContextOptions = Parameters<Browser["newContext"]>[0];
793
+ interface BrowserEvents {
794
+ disconnected: Browser;
795
+ }
796
+ declare const eventMappings: {
797
+ readonly disconnected: (browser: Browser) => PlaywrightBrowserService;
798
+ };
799
+ type BrowserWithPatchedEvents = PatchedEvents<Browser, BrowserEvents>;
800
+ /**
801
+ * @category model
802
+ * @since 0.1.0
803
+ */
804
+ interface PlaywrightBrowserService {
805
+ /**
806
+ * Opens a new page in the browser.
807
+ *
808
+ * @example
809
+ * ```typescript
810
+ * const page = yield* browser.newPage();
811
+ * ```
812
+ *
813
+ * @param options - Optional options for creating the new page.
814
+ * @returns An effect that resolves to a `PlaywrightPage` service.
815
+ * @see {@link Browser.newPage}
816
+ */
817
+ readonly newPage: (options?: NewPageOptions) => Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
818
+ /**
819
+ * A generic utility to execute any promise-based method on the underlying Playwright `Browser`.
820
+ * Can be used to access any Browser functionality not directly exposed by this service.
821
+ *
822
+ * @example
823
+ * ```typescript
824
+ * const contexts = yield* browser.use((b) => b.contexts());
825
+ * ```
826
+ *
827
+ * @param f - A function that takes the Playwright `Browser` and returns a `Promise`.
828
+ * @returns An effect that wraps the promise and returns its result.
829
+ * @see {@link Browser}
830
+ */
831
+ readonly use: <T>(f: (browser: Browser) => Promise<T>) => Effect.Effect<T, PlaywrightError>;
832
+ /**
833
+ * An Effect that closes the browser and all of its pages.
834
+ * @see {@link Browser.close}
835
+ */
836
+ readonly close: Effect.Effect<void, PlaywrightError>;
837
+ /**
838
+ * An Effect that returns the list of all open browser contexts.
839
+ * @see {@link Browser.contexts}
840
+ */
841
+ readonly contexts: Effect.Effect<Array<typeof PlaywrightBrowserContext.Service>>;
842
+ readonly newContext: (options?: NewContextOptions) => Effect.Effect<typeof PlaywrightBrowserContext.Service, PlaywrightError, Scope$1>;
843
+ /**
844
+ * An Effect that returns the browser type (chromium, firefox or webkit) that the browser belongs to.
845
+ * @see {@link Browser.browserType}
846
+ */
847
+ readonly browserType: Effect.Effect<BrowserType>;
848
+ /**
849
+ * An Effect that returns the version of the browser.
850
+ * @see {@link Browser.version}
851
+ */
852
+ readonly version: Effect.Effect<string>;
853
+ /**
854
+ * An Effect that returns whether the browser is connected.
855
+ * @see {@link Browser.isConnected}
856
+ */
857
+ readonly isConnected: Effect.Effect<boolean>;
858
+ /**
859
+ * Creates a stream of the given event from the browser.
860
+ *
861
+ * @example
862
+ * ```ts
863
+ * const disconnectedStream = browser.eventStream("disconnected");
864
+ * ```
865
+ *
866
+ * @category custom
867
+ * @see {@link Browser.on}
868
+ * @since 0.1.2
869
+ */
870
+ readonly eventStream: <K extends keyof typeof eventMappings>(event: K) => Stream.Stream<ReturnType<(typeof eventMappings)[K]>>;
871
+ }
872
+ declare const PlaywrightBrowser_base: Context.TagClass<PlaywrightBrowser, "effect-playwright/PlaywrightBrowser", PlaywrightBrowserService>;
873
+ /**
874
+ * @category tag
875
+ */
876
+ declare class PlaywrightBrowser extends PlaywrightBrowser_base {
877
+ /**
878
+ * @category constructor
879
+ */
880
+ static make(browser: BrowserWithPatchedEvents): PlaywrightBrowserService;
881
+ }
882
+ //#endregion
883
+ //#region src/playwright.d.ts
884
+ /**
885
+ * @category model
886
+ * @since 0.1.0
887
+ */
888
+ interface PlaywrightService {
889
+ /**
890
+ * Launches a new browser instance.
891
+ *
892
+ * It is the caller's responsibility to manage the browser's lifecycle and close
893
+ * it when no longer needed. For automatic scope-based management, use
894
+ * {@link launchScoped} instead.
895
+ *
896
+ * ```ts
897
+ * import { Effect } from "effect";
898
+ * import { Playwright } from "effect-playwright";
899
+ * import { chromium } from "playwright-core";
900
+ *
901
+ * const program = Effect.gen(function* () {
902
+ * const browser = yield* Playwright.launch(chromium);
903
+ * // ... use browser ...
904
+ * yield* browser.close;
905
+ * });
906
+ *
907
+ * await Effect.runPromise(program);
908
+ * ```
909
+ *
910
+ * @param browserType - The browser type to launch (e.g. chromium, firefox, webkit).
911
+ * @param options - Optional launch options.
912
+ * @since 0.1.0
913
+ */
914
+ launch: (browserType: BrowserType, options?: LaunchOptions$1) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError>;
915
+ /**
916
+ * Launches a new browser instance managed by a Scope.
917
+ *
918
+ * This method automatically closes the browser when the scope is closed.
919
+ *
920
+ * ```ts
921
+ * import { Effect } from "effect";
922
+ * import { Playwright } from "effect-playwright";
923
+ * import { chromium } from "playwright-core";
924
+ *
925
+ * const program = Effect.gen(function* () {
926
+ * const browser = yield* Playwright.launchScoped(chromium);
927
+ * // Browser will be closed automatically when scope closes
928
+ * });
929
+ *
930
+ * await Effect.runPromise(program);
931
+ * ```
932
+ *
933
+ * @param browserType - The browser type to launch (e.g. chromium, firefox, webkit).
934
+ * @param options - Optional launch options.
935
+ * @since 0.1.0
936
+ */
937
+ launchScoped: (browserType: BrowserType, options?: LaunchOptions$1) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError, Scope.Scope>;
938
+ /**
939
+ * Connects to a browser instance via Chrome DevTools Protocol (CDP).
940
+ *
941
+ * Unlike {@link connectCDPScoped}, this method does **not** close the connection when the
942
+ * scope is closed. It is the caller's responsibility to manage the connection's
943
+ * lifecycle.
944
+ *
945
+ * If you want to close the connection using a scope simply add a finalizer:
946
+ *
947
+ * ```ts
948
+ * import { Effect } from "effect";
949
+ * import { Playwright } from "effect-playwright";
950
+ *
951
+ * const program = Effect.gen(function* () {
952
+ * const playwright = yield* Playwright;
953
+ * const browser = yield* playwright.connectCDP(cdpUrl);
954
+ * yield* Effect.addFinalizer(() => browser.close.pipe(Effect.ignore));
955
+ * });
956
+ *
957
+ * await Effect.runPromise(program);
958
+ * ```
959
+ *
960
+ * @param cdpUrl - The CDP URL to connect to.
961
+ * @param options - Optional options for connecting to the CDP URL.
962
+ * @since 0.1.0
963
+ */
964
+ connectCDP: (cdpUrl: string, options?: ConnectOverCDPOptions) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError>;
965
+ /**
966
+ * Connects to a browser instance via Chrome DevTools Protocol (CDP) managed by a Scope.
967
+ *
968
+ * This method automatically closes the connection when the scope is closed.
969
+ *
970
+ * Note that closing a CDP connection does **not** close the browser instance itself,
971
+ * only the CDP connection.
972
+ *
973
+ * ```ts
974
+ * import { Effect } from "effect";
975
+ * import { Playwright } from "effect-playwright";
976
+ *
977
+ * const program = Effect.gen(function* () {
978
+ * const playwright = yield* Playwright;
979
+ * const browser = yield* playwright.connectCDPScoped(cdpUrl);
980
+ * // Connection will be closed automatically when scope closes
981
+ * });
982
+ *
983
+ * await Effect.runPromise(program);
984
+ * ```
985
+ *
986
+ * @param cdpUrl - The CDP URL to connect to.
987
+ * @param options - Optional options for connecting to the CDP URL.
988
+ * @since 0.1.1
989
+ */
990
+ connectCDPScoped: (cdpUrl: string, options?: ConnectOverCDPOptions) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError, Scope.Scope>;
991
+ }
992
+ declare const Playwright_base: Context.TagClass<Playwright, "effect-playwright/index/Playwright", PlaywrightService>;
993
+ /**
994
+ * @category tag
995
+ * @since 0.1.0
996
+ */
997
+ declare class Playwright extends Playwright_base {
998
+ /**
999
+ * @category layer
1000
+ */
1001
+ static readonly layer: Layer.Layer<Playwright, never, never>;
1002
+ }
1003
+ //#endregion
1004
+ export { PlaywrightErrorReason as S, PlaywrightWorker as _, NewPageOptions as a, PlaywrightLocatorService as b, PlaywrightBrowserContext as c, PlaywrightPageService as d, PlaywrightDialog as f, PlaywrightResponse as g, PlaywrightRequest as h, NewContextOptions as i, PlaywrightBrowserContextService as l, PlaywrightFileChooser as m, PlaywrightService as n, PlaywrightBrowser as o, PlaywrightDownload as p, LaunchOptions$1 as r, PlaywrightBrowserService as s, Playwright as t, PlaywrightPage as u, PlaywrightFrameService as v, PlaywrightError as x, PlaywrightLocator as y };