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