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.
- package/README.md +86 -0
- package/dist/experimental/index.d.mts +10 -7
- package/dist/experimental/index.mjs +10 -7
- package/dist/index-BTxElyN5.d.mts +857 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/src-D0uXY5ik.mjs +389 -0
- package/package.json +9 -5
- package/dist/index-aR0Fa_4Y.d.mts +0 -584
- package/dist/src-DveiwW4g.mjs +0 -167
|
@@ -1,584 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Layer, Scope, Stream } from "effect";
|
|
2
|
-
import { Browser, BrowserContext, BrowserType, ConnectOverCDPOptions, ConsoleMessage, Dialog, Download, ElementHandle, FileChooser, Frame, JSHandle, Locator, Page, Request, Response, 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
|
-
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/locator.d.ts
|
|
27
|
-
/**
|
|
28
|
-
* Interface for a Playwright locator.
|
|
29
|
-
* @category model
|
|
30
|
-
*/
|
|
31
|
-
interface PlaywrightLocatorService {
|
|
32
|
-
/**
|
|
33
|
-
* Clicks the element.
|
|
34
|
-
*
|
|
35
|
-
* @see {@link Locator.click}
|
|
36
|
-
* @since 0.1.0
|
|
37
|
-
*/
|
|
38
|
-
readonly click: (options?: Parameters<Locator["click"]>[0]) => Effect.Effect<void, PlaywrightError>;
|
|
39
|
-
/**
|
|
40
|
-
* Fills the input field.
|
|
41
|
-
*
|
|
42
|
-
* @see {@link Locator.fill}
|
|
43
|
-
* @since 0.1.0
|
|
44
|
-
*/
|
|
45
|
-
readonly fill: (value: string, options?: Parameters<Locator["fill"]>[1]) => Effect.Effect<void, PlaywrightError>;
|
|
46
|
-
/**
|
|
47
|
-
* Gets an attribute value.
|
|
48
|
-
*
|
|
49
|
-
* @see {@link Locator.getAttribute}
|
|
50
|
-
* @since 0.1.0
|
|
51
|
-
*/
|
|
52
|
-
readonly getAttribute: (name: string, options?: Parameters<Locator["getAttribute"]>[1]) => Effect.Effect<string | null, PlaywrightError>;
|
|
53
|
-
/**
|
|
54
|
-
* Gets the inner text.
|
|
55
|
-
*
|
|
56
|
-
* @see {@link Locator.innerText}
|
|
57
|
-
* @since 0.1.0
|
|
58
|
-
*/
|
|
59
|
-
readonly innerText: (options?: Parameters<Locator["innerText"]>[0]) => Effect.Effect<string, PlaywrightError>;
|
|
60
|
-
/**
|
|
61
|
-
* Gets the inner HTML.
|
|
62
|
-
*
|
|
63
|
-
* @see {@link Locator.innerHTML}
|
|
64
|
-
* @since 0.1.0
|
|
65
|
-
*/
|
|
66
|
-
readonly innerHTML: (options?: Parameters<Locator["innerHTML"]>[0]) => Effect.Effect<string, PlaywrightError>;
|
|
67
|
-
/**
|
|
68
|
-
* Gets the input value.
|
|
69
|
-
*
|
|
70
|
-
* @see {@link Locator.inputValue}
|
|
71
|
-
* @since 0.1.0
|
|
72
|
-
*/
|
|
73
|
-
readonly inputValue: (options?: Parameters<Locator["inputValue"]>[0]) => Effect.Effect<string, PlaywrightError>;
|
|
74
|
-
/**
|
|
75
|
-
* Gets the text content.
|
|
76
|
-
*
|
|
77
|
-
* @see {@link Locator.textContent}
|
|
78
|
-
* @since 0.1.0
|
|
79
|
-
*/
|
|
80
|
-
readonly textContent: (options?: Parameters<Locator["textContent"]>[0]) => Effect.Effect<string | null, PlaywrightError>;
|
|
81
|
-
/**
|
|
82
|
-
* Counts the number of matched elements.
|
|
83
|
-
*
|
|
84
|
-
* @see {@link Locator.count}
|
|
85
|
-
* @since 0.1.0
|
|
86
|
-
*/
|
|
87
|
-
readonly count: Effect.Effect<number, PlaywrightError>;
|
|
88
|
-
/**
|
|
89
|
-
* Returns a locator that points to the first matched element.
|
|
90
|
-
* @see {@link Locator.first}
|
|
91
|
-
* @since 0.1.0
|
|
92
|
-
*/
|
|
93
|
-
readonly first: () => PlaywrightLocatorService;
|
|
94
|
-
/**
|
|
95
|
-
* Returns a locator that points to the last matched element.
|
|
96
|
-
*
|
|
97
|
-
* @see {@link Locator.last}
|
|
98
|
-
* @since 0.1.0
|
|
99
|
-
*/
|
|
100
|
-
readonly last: () => PlaywrightLocatorService;
|
|
101
|
-
/**
|
|
102
|
-
* Returns a locator that points to the nth matched element.
|
|
103
|
-
*
|
|
104
|
-
* @see {@link Locator.nth}
|
|
105
|
-
* @since 0.1.0
|
|
106
|
-
*/
|
|
107
|
-
readonly nth: (index: number) => PlaywrightLocatorService;
|
|
108
|
-
/**
|
|
109
|
-
* Evaluates a function on the matched element.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* import { PlaywrightBrowser } from "effect-playwright";
|
|
114
|
-
* import { PlaywrightEnvironment } from "effect-playwright/experimental";
|
|
115
|
-
* import { chromium } from "@playwright/test";
|
|
116
|
-
* import { Effect } from "effect";
|
|
117
|
-
*
|
|
118
|
-
* const program = Effect.gen(function* () {
|
|
119
|
-
* const browser = yield* PlaywrightBrowser;
|
|
120
|
-
* const page = yield* browser.newPage();
|
|
121
|
-
* const locator = yield* page.locator("button");
|
|
122
|
-
* const buttonContent = yield* locator.evaluate((button) => button.textContent());
|
|
123
|
-
* }).pipe(PlaywrightEnvironment.provideBrowser, Effect.provide(PlaywrightEnvironment.layer(chromium)));
|
|
124
|
-
* ```
|
|
125
|
-
*
|
|
126
|
-
* @see {@link Locator.evaluate}
|
|
127
|
-
* @since 0.1.0
|
|
128
|
-
*/
|
|
129
|
-
readonly evaluate: <R, Arg = void, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(pageFunction: (element: E, arg: Unboxed<Arg>) => R | Promise<R>, arg?: Arg, options?: {
|
|
130
|
-
timeout?: number;
|
|
131
|
-
}) => Effect.Effect<R, PlaywrightError>;
|
|
132
|
-
/**
|
|
133
|
-
* A generic utility to execute any promise-based method on the underlying Playwright `Locator`.
|
|
134
|
-
* Can be used to access any Locator functionality not directly exposed by this service.
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```typescript
|
|
138
|
-
* const isVisible = yield* locator.use((l) => l.isVisible());
|
|
139
|
-
* ```
|
|
140
|
-
*
|
|
141
|
-
* @param f - A function that takes the Playwright `Locator` and returns a `Promise`.
|
|
142
|
-
* @returns An effect that wraps the promise and returns its result.
|
|
143
|
-
* @see {@link Locator}
|
|
144
|
-
* @since 0.1.0
|
|
145
|
-
*/
|
|
146
|
-
readonly use: <T$1>(f: (locator: Locator) => Promise<T$1>) => Effect.Effect<T$1, PlaywrightError>;
|
|
147
|
-
}
|
|
148
|
-
declare const PlaywrightLocator_base: Context.TagClass<PlaywrightLocator, "effect-playwright/PlaywrightLocator", PlaywrightLocatorService>;
|
|
149
|
-
/**
|
|
150
|
-
* A service that provides a `PlaywrightLocator` instance.
|
|
151
|
-
*
|
|
152
|
-
* @since 0.1.0
|
|
153
|
-
* @category tag
|
|
154
|
-
*/
|
|
155
|
-
declare class PlaywrightLocator extends PlaywrightLocator_base {
|
|
156
|
-
/**
|
|
157
|
-
* Creates a `PlaywrightLocator` from a Playwright `Locator` instance. This is mostly for internal use.
|
|
158
|
-
* But you could use this if you have used `use` or similar to wrap the locator.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```ts
|
|
162
|
-
* const playwrightNativeLocator = yield* page.use((p) => p.locator("button"));
|
|
163
|
-
* const locator = PlaywrightLocator.make(playwrightNativeLocator);
|
|
164
|
-
* ```
|
|
165
|
-
*
|
|
166
|
-
* @param locator - The Playwright `Locator` instance to wrap.
|
|
167
|
-
* @since 0.1.0
|
|
168
|
-
* @category constructor
|
|
169
|
-
*/
|
|
170
|
-
static make(locator: Locator): typeof PlaywrightLocator.Service;
|
|
171
|
-
}
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region src/page.d.ts
|
|
174
|
-
interface PlaywrightPageEvents {
|
|
175
|
-
close: Page;
|
|
176
|
-
console: ConsoleMessage;
|
|
177
|
-
crash: Page;
|
|
178
|
-
dialog: Dialog;
|
|
179
|
-
domcontentloaded: Page;
|
|
180
|
-
download: Download;
|
|
181
|
-
filechooser: FileChooser;
|
|
182
|
-
frameattached: Frame;
|
|
183
|
-
framedetached: Frame;
|
|
184
|
-
framenavigated: Frame;
|
|
185
|
-
load: Page;
|
|
186
|
-
pageerror: Error;
|
|
187
|
-
popup: Page;
|
|
188
|
-
request: Request;
|
|
189
|
-
requestfailed: Request;
|
|
190
|
-
requestfinished: Request;
|
|
191
|
-
response: Response;
|
|
192
|
-
websocket: WebSocket;
|
|
193
|
-
worker: Worker;
|
|
194
|
-
}
|
|
195
|
-
interface PlaywrightPageService {
|
|
196
|
-
/**
|
|
197
|
-
* Navigates the page to the given URL.
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* ```ts
|
|
201
|
-
* yield* page.goto("https://google.com");
|
|
202
|
-
* ```
|
|
203
|
-
*
|
|
204
|
-
* @see {@link Page.goto}
|
|
205
|
-
* @since 0.1.0
|
|
206
|
-
*/
|
|
207
|
-
readonly goto: (url: string, options?: Parameters<Page["goto"]>[1]) => Effect.Effect<void, PlaywrightError>;
|
|
208
|
-
/**
|
|
209
|
-
* Waits for the page to navigate to the given URL.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* yield* page.waitForURL("https://google.com");
|
|
214
|
-
* ```
|
|
215
|
-
*
|
|
216
|
-
* @see {@link Page.waitForURL}
|
|
217
|
-
* @since 0.1.0
|
|
218
|
-
*/
|
|
219
|
-
readonly waitForURL: (url: Parameters<Page["waitForURL"]>[0], options?: Parameters<Page["waitForURL"]>[1]) => Effect.Effect<void, PlaywrightError>;
|
|
220
|
-
/**
|
|
221
|
-
* Evaluates a function in the context of the page.
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* ```ts
|
|
225
|
-
* const dimensions = yield* page.evaluate(() => ({
|
|
226
|
-
* width: document.documentElement.clientWidth,
|
|
227
|
-
* height: document.documentElement.clientHeight
|
|
228
|
-
* }));
|
|
229
|
-
* ```
|
|
230
|
-
*
|
|
231
|
-
* @see {@link Page.evaluate}
|
|
232
|
-
* @since 0.1.0
|
|
233
|
-
*/
|
|
234
|
-
readonly evaluate: <R, Arg = void>(pageFunction: PageFunction<Arg, R>, arg?: Arg) => Effect.Effect<R, PlaywrightError>;
|
|
235
|
-
/**
|
|
236
|
-
* Returns the page title.
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* ```ts
|
|
240
|
-
* const title = yield* page.title;
|
|
241
|
-
* ```
|
|
242
|
-
*
|
|
243
|
-
* @see {@link Page.title}
|
|
244
|
-
* @since 0.1.0
|
|
245
|
-
*/
|
|
246
|
-
readonly title: Effect.Effect<string, PlaywrightError>;
|
|
247
|
-
/**
|
|
248
|
-
* A generic utility to execute any promise-based method on the underlying Playwright `Page`.
|
|
249
|
-
* Can be used to access any Page functionality not directly exposed by this service.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```ts
|
|
253
|
-
* const title = yield* page.use((p) => p.title());
|
|
254
|
-
* ```
|
|
255
|
-
*
|
|
256
|
-
* @see {@link Page}
|
|
257
|
-
* @since 0.1.0
|
|
258
|
-
*/
|
|
259
|
-
readonly use: <T$1>(f: (page: Page) => Promise<T$1>) => Effect.Effect<T$1, PlaywrightError>;
|
|
260
|
-
/**
|
|
261
|
-
* Returns a locator for the given selector.
|
|
262
|
-
*
|
|
263
|
-
* @see {@link Page.locator}
|
|
264
|
-
* @since 0.1.0
|
|
265
|
-
*/
|
|
266
|
-
readonly locator: (selector: string, options?: Parameters<Page["locator"]>[1]) => typeof PlaywrightLocator.Service;
|
|
267
|
-
/**
|
|
268
|
-
* Returns a locator that matches the given role.
|
|
269
|
-
*
|
|
270
|
-
* @see {@link Page.getByRole}
|
|
271
|
-
* @since 0.1.0
|
|
272
|
-
*/
|
|
273
|
-
readonly getByRole: (role: Parameters<Page["getByRole"]>[0], options?: Parameters<Page["getByRole"]>[1]) => typeof PlaywrightLocator.Service;
|
|
274
|
-
/**
|
|
275
|
-
* Returns a locator that matches the given text.
|
|
276
|
-
*
|
|
277
|
-
* @see {@link Page.getByText}
|
|
278
|
-
* @since 0.1.0
|
|
279
|
-
*/
|
|
280
|
-
readonly getByText: (text: Parameters<Page["getByText"]>[0], options?: Parameters<Page["getByText"]>[1]) => typeof PlaywrightLocator.Service;
|
|
281
|
-
/**
|
|
282
|
-
* Returns a locator that matches the given label.
|
|
283
|
-
*
|
|
284
|
-
* @see {@link Page.getByLabel}
|
|
285
|
-
* @since 0.1.0
|
|
286
|
-
*/
|
|
287
|
-
readonly getByLabel: (label: Parameters<Page["getByLabel"]>[0], options?: Parameters<Page["getByLabel"]>[1]) => typeof PlaywrightLocator.Service;
|
|
288
|
-
/**
|
|
289
|
-
* Returns a locator that matches the given test id.
|
|
290
|
-
*
|
|
291
|
-
* @see {@link Page.getByTestId}
|
|
292
|
-
* @since 0.1.0
|
|
293
|
-
*/
|
|
294
|
-
readonly getByTestId: (testId: Parameters<Page["getByTestId"]>[0]) => typeof PlaywrightLocator.Service;
|
|
295
|
-
/**
|
|
296
|
-
* Reloads the page.
|
|
297
|
-
*
|
|
298
|
-
* @see {@link Page.reload}
|
|
299
|
-
* @since 0.1.0
|
|
300
|
-
*/
|
|
301
|
-
readonly reload: Effect.Effect<void, PlaywrightError>;
|
|
302
|
-
/**
|
|
303
|
-
* Closes the page.
|
|
304
|
-
*
|
|
305
|
-
* @see {@link Page.close}
|
|
306
|
-
* @since 0.1.0
|
|
307
|
-
*/
|
|
308
|
-
readonly close: Effect.Effect<void, PlaywrightError>;
|
|
309
|
-
/**
|
|
310
|
-
* Returns the current URL of the page.
|
|
311
|
-
*
|
|
312
|
-
* @example
|
|
313
|
-
* ```ts
|
|
314
|
-
* const url = yield* page.url;
|
|
315
|
-
* ```
|
|
316
|
-
*
|
|
317
|
-
* @see {@link Page.url}
|
|
318
|
-
* @since 0.1.0
|
|
319
|
-
*/
|
|
320
|
-
readonly url: Effect.Effect<string, PlaywrightError>;
|
|
321
|
-
/**
|
|
322
|
-
* Creates a stream of the given event from the page.
|
|
323
|
-
*
|
|
324
|
-
* @example
|
|
325
|
-
* ```ts
|
|
326
|
-
* const consoleStream = page.eventStream("console");
|
|
327
|
-
* ```
|
|
328
|
-
*
|
|
329
|
-
* @see {@link Page.on}
|
|
330
|
-
* @since 0.1.0
|
|
331
|
-
*/
|
|
332
|
-
readonly eventStream: <K extends keyof PlaywrightPageEvents>(event: K) => Stream.Stream<PlaywrightPageEvents[K]>;
|
|
333
|
-
/**
|
|
334
|
-
* Clicks an element matching the given selector.
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* ```ts
|
|
338
|
-
* yield* page.click("button#submit");
|
|
339
|
-
* ```
|
|
340
|
-
* @deprecated Use {@link PlaywrightPageService.locator} to create a locator and then call `click` on it instead.
|
|
341
|
-
* @see {@link Page.click}
|
|
342
|
-
* @since 0.1.0
|
|
343
|
-
* @category deprecated
|
|
344
|
-
*/
|
|
345
|
-
readonly click: (selector: string, options?: Parameters<Page["click"]>[1]) => Effect.Effect<void, PlaywrightError>;
|
|
346
|
-
}
|
|
347
|
-
declare const PlaywrightPage_base: Context.TagClass<PlaywrightPage, "effect-playwright/PlaywrightPage", PlaywrightPageService>;
|
|
348
|
-
/**
|
|
349
|
-
* @category tag
|
|
350
|
-
*/
|
|
351
|
-
declare class PlaywrightPage extends PlaywrightPage_base {
|
|
352
|
-
/**
|
|
353
|
-
* Creates a `PlaywrightPage` from a Playwright `Page` instance.
|
|
354
|
-
*
|
|
355
|
-
* @param page - The Playwright `Page` instance to wrap.
|
|
356
|
-
* @since 0.1.0
|
|
357
|
-
*/
|
|
358
|
-
static make(page: Page): PlaywrightPageService;
|
|
359
|
-
}
|
|
360
|
-
//#endregion
|
|
361
|
-
//#region src/browser-context.d.ts
|
|
362
|
-
declare const PlaywrightBrowserContext_base: Context.TagClass<PlaywrightBrowserContext, "cehs/backend/lib/playwright/PlaywrightBrowserContext", {
|
|
363
|
-
readonly pages: Effect.Effect<Array<typeof PlaywrightPage.Service>>;
|
|
364
|
-
readonly newPage: Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
|
|
365
|
-
readonly close: Effect.Effect<void, PlaywrightError>;
|
|
366
|
-
}>;
|
|
367
|
-
declare class PlaywrightBrowserContext extends PlaywrightBrowserContext_base {
|
|
368
|
-
static make(context: BrowserContext): {
|
|
369
|
-
readonly pages: Effect.Effect<Array<typeof PlaywrightPage.Service>>;
|
|
370
|
-
readonly newPage: Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
|
|
371
|
-
readonly close: Effect.Effect<void, PlaywrightError>;
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
//#endregion
|
|
375
|
-
//#region src/browser.d.ts
|
|
376
|
-
type LaunchOptions$1 = Parameters<typeof chromium.launch>[0];
|
|
377
|
-
type NewPageOptions = Parameters<Browser["newPage"]>[0];
|
|
378
|
-
type NewContextOptions = Parameters<Browser["newContext"]>[0];
|
|
379
|
-
declare const PlaywrightBrowser_base: Context.TagClass<PlaywrightBrowser, "cehs/backend/lib/playwright/PlaywrightBrowser", {
|
|
380
|
-
/**
|
|
381
|
-
* Opens a new page in the browser.
|
|
382
|
-
*
|
|
383
|
-
* @example
|
|
384
|
-
* ```typescript
|
|
385
|
-
* const page = yield* browser.newPage();
|
|
386
|
-
* ```
|
|
387
|
-
*
|
|
388
|
-
* @param options - Optional options for creating the new page.
|
|
389
|
-
* @returns An effect that resolves to a `PlaywrightPage` service.
|
|
390
|
-
* @see {@link Browser.newPage}
|
|
391
|
-
*/
|
|
392
|
-
readonly newPage: (options?: NewPageOptions) => Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
|
|
393
|
-
/**
|
|
394
|
-
* A generic utility to execute any promise-based method on the underlying Playwright `Browser`.
|
|
395
|
-
* Can be used to access any Browser functionality not directly exposed by this service.
|
|
396
|
-
*
|
|
397
|
-
* @example
|
|
398
|
-
* ```typescript
|
|
399
|
-
* const contexts = yield* browser.use((b) => b.contexts());
|
|
400
|
-
* ```
|
|
401
|
-
*
|
|
402
|
-
* @param f - A function that takes the Playwright `Browser` and returns a `Promise`.
|
|
403
|
-
* @returns An effect that wraps the promise and returns its result.
|
|
404
|
-
* @see {@link Browser}
|
|
405
|
-
*/
|
|
406
|
-
readonly use: <T$1>(f: (browser: Browser) => Promise<T$1>) => Effect.Effect<T$1, PlaywrightError>;
|
|
407
|
-
/**
|
|
408
|
-
* An Effect that closes the browser and all of its pages.
|
|
409
|
-
* @see {@link Browser.close}
|
|
410
|
-
*/
|
|
411
|
-
readonly close: Effect.Effect<void, PlaywrightError>;
|
|
412
|
-
/**
|
|
413
|
-
* An Effect that returns the list of all open browser contexts.
|
|
414
|
-
* @see {@link Browser.contexts}
|
|
415
|
-
*/
|
|
416
|
-
readonly contexts: Effect.Effect<Array<typeof PlaywrightBrowserContext.Service>>;
|
|
417
|
-
readonly newContext: (options?: NewContextOptions) => Effect.Effect<typeof PlaywrightBrowserContext.Service, PlaywrightError, Scope$1>;
|
|
418
|
-
/**
|
|
419
|
-
* An Effect that returns the browser type (chromium, firefox or webkit) that the browser belongs to.
|
|
420
|
-
* @see {@link Browser.browserType}
|
|
421
|
-
*/
|
|
422
|
-
readonly browserType: Effect.Effect<BrowserType>;
|
|
423
|
-
/**
|
|
424
|
-
* An Effect that returns the version of the browser.
|
|
425
|
-
* @see {@link Browser.version}
|
|
426
|
-
*/
|
|
427
|
-
readonly version: Effect.Effect<string>;
|
|
428
|
-
/**
|
|
429
|
-
* An Effect that returns whether the browser is connected.
|
|
430
|
-
* @see {@link Browser.isConnected}
|
|
431
|
-
*/
|
|
432
|
-
readonly isConnected: Effect.Effect<boolean>;
|
|
433
|
-
}>;
|
|
434
|
-
/**
|
|
435
|
-
* @category tag
|
|
436
|
-
*/
|
|
437
|
-
declare class PlaywrightBrowser extends PlaywrightBrowser_base {
|
|
438
|
-
/**
|
|
439
|
-
* @category constructor
|
|
440
|
-
*/
|
|
441
|
-
static make(browser: Browser): {
|
|
442
|
-
/**
|
|
443
|
-
* Opens a new page in the browser.
|
|
444
|
-
*
|
|
445
|
-
* @example
|
|
446
|
-
* ```typescript
|
|
447
|
-
* const page = yield* browser.newPage();
|
|
448
|
-
* ```
|
|
449
|
-
*
|
|
450
|
-
* @param options - Optional options for creating the new page.
|
|
451
|
-
* @returns An effect that resolves to a `PlaywrightPage` service.
|
|
452
|
-
* @see {@link Browser.newPage}
|
|
453
|
-
*/
|
|
454
|
-
readonly newPage: (options?: NewPageOptions) => Effect.Effect<typeof PlaywrightPage.Service, PlaywrightError>;
|
|
455
|
-
/**
|
|
456
|
-
* A generic utility to execute any promise-based method on the underlying Playwright `Browser`.
|
|
457
|
-
* Can be used to access any Browser functionality not directly exposed by this service.
|
|
458
|
-
*
|
|
459
|
-
* @example
|
|
460
|
-
* ```typescript
|
|
461
|
-
* const contexts = yield* browser.use((b) => b.contexts());
|
|
462
|
-
* ```
|
|
463
|
-
*
|
|
464
|
-
* @param f - A function that takes the Playwright `Browser` and returns a `Promise`.
|
|
465
|
-
* @returns An effect that wraps the promise and returns its result.
|
|
466
|
-
* @see {@link Browser}
|
|
467
|
-
*/
|
|
468
|
-
readonly use: <T$1>(f: (browser: Browser) => Promise<T$1>) => Effect.Effect<T$1, PlaywrightError>;
|
|
469
|
-
/**
|
|
470
|
-
* An Effect that closes the browser and all of its pages.
|
|
471
|
-
* @see {@link Browser.close}
|
|
472
|
-
*/
|
|
473
|
-
readonly close: Effect.Effect<void, PlaywrightError>;
|
|
474
|
-
/**
|
|
475
|
-
* An Effect that returns the list of all open browser contexts.
|
|
476
|
-
* @see {@link Browser.contexts}
|
|
477
|
-
*/
|
|
478
|
-
readonly contexts: Effect.Effect<Array<typeof PlaywrightBrowserContext.Service>>;
|
|
479
|
-
readonly newContext: (options?: NewContextOptions) => Effect.Effect<typeof PlaywrightBrowserContext.Service, PlaywrightError, Scope$1>;
|
|
480
|
-
/**
|
|
481
|
-
* An Effect that returns the browser type (chromium, firefox or webkit) that the browser belongs to.
|
|
482
|
-
* @see {@link Browser.browserType}
|
|
483
|
-
*/
|
|
484
|
-
readonly browserType: Effect.Effect<BrowserType>;
|
|
485
|
-
/**
|
|
486
|
-
* An Effect that returns the version of the browser.
|
|
487
|
-
* @see {@link Browser.version}
|
|
488
|
-
*/
|
|
489
|
-
readonly version: Effect.Effect<string>;
|
|
490
|
-
/**
|
|
491
|
-
* An Effect that returns whether the browser is connected.
|
|
492
|
-
* @see {@link Browser.isConnected}
|
|
493
|
-
*/
|
|
494
|
-
readonly isConnected: Effect.Effect<boolean>;
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
//#endregion
|
|
498
|
-
//#region src/playwright.d.ts
|
|
499
|
-
interface PlaywrightService {
|
|
500
|
-
/**
|
|
501
|
-
* Launches a new browser instance.
|
|
502
|
-
*
|
|
503
|
-
* It is the caller's responsibility to manage the browser's lifecycle and close
|
|
504
|
-
* it when no longer needed. For automatic scope-based management, use
|
|
505
|
-
* {@link launchScoped} instead.
|
|
506
|
-
*
|
|
507
|
-
* ```ts
|
|
508
|
-
* import { Effect } from "effect";
|
|
509
|
-
* import { Playwright } from "effect-playwright";
|
|
510
|
-
* import { chromium } from "playwright-core";
|
|
511
|
-
*
|
|
512
|
-
* const program = Effect.gen(function* () {
|
|
513
|
-
* const browser = yield* Playwright.launch(chromium);
|
|
514
|
-
* // ... use browser ...
|
|
515
|
-
* yield* browser.close;
|
|
516
|
-
* });
|
|
517
|
-
*
|
|
518
|
-
* await Effect.runPromise(program);
|
|
519
|
-
* ```
|
|
520
|
-
*
|
|
521
|
-
* @param browserType - The browser type to launch (e.g. chromium, firefox, webkit).
|
|
522
|
-
* @param options - Optional launch options.
|
|
523
|
-
* @since 0.1.0
|
|
524
|
-
*/
|
|
525
|
-
launch: (browserType: BrowserType, options?: LaunchOptions$1) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError>;
|
|
526
|
-
/**
|
|
527
|
-
* Launches a new browser instance managed by a Scope.
|
|
528
|
-
*
|
|
529
|
-
* This method automatically closes the browser when the scope is closed.
|
|
530
|
-
*
|
|
531
|
-
* ```ts
|
|
532
|
-
* import { Effect } from "effect";
|
|
533
|
-
* import { Playwright } from "effect-playwright";
|
|
534
|
-
* import { chromium } from "playwright-core";
|
|
535
|
-
*
|
|
536
|
-
* const program = Effect.gen(function* () {
|
|
537
|
-
* const browser = yield* Playwright.launchScoped(chromium);
|
|
538
|
-
* // Browser will be closed automatically when scope closes
|
|
539
|
-
* });
|
|
540
|
-
*
|
|
541
|
-
* await Effect.runPromise(program);
|
|
542
|
-
* ```
|
|
543
|
-
*
|
|
544
|
-
* @param browserType - The browser type to launch (e.g. chromium, firefox, webkit).
|
|
545
|
-
* @param options - Optional launch options.
|
|
546
|
-
* @since 0.1.0
|
|
547
|
-
*/
|
|
548
|
-
launchScoped: (browserType: BrowserType, options?: LaunchOptions$1) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError, Scope.Scope>;
|
|
549
|
-
/**
|
|
550
|
-
* Connects to a browser instance via Chrome DevTools Protocol (CDP).
|
|
551
|
-
*
|
|
552
|
-
* Unlike {@link launchScoped}, this method does **not** close the browser when the
|
|
553
|
-
* scope is closed. It is the caller's responsibility to manage the browser's
|
|
554
|
-
* lifecycle.
|
|
555
|
-
*
|
|
556
|
-
* If you want to close the browser using a scope simply add a finalizer:
|
|
557
|
-
*
|
|
558
|
-
* ```ts
|
|
559
|
-
* import { Effect } from "effect";
|
|
560
|
-
* import { Playwright } from "effect-playwright";
|
|
561
|
-
*
|
|
562
|
-
* const program = Effect.gen(function* () {
|
|
563
|
-
* const browser = yield* Playwright.connectCDP(cdpUrl);
|
|
564
|
-
* yield* Effect.addFinalizer(() => browser.close.pipe(Effect.ignore));
|
|
565
|
-
* });
|
|
566
|
-
*
|
|
567
|
-
* await Effect.runPromise(program);
|
|
568
|
-
* ```
|
|
569
|
-
*
|
|
570
|
-
* @param cdpUrl - The CDP URL to connect to.
|
|
571
|
-
* @param options - Optional options for connecting to the CDP URL.
|
|
572
|
-
* @since 0.1.0
|
|
573
|
-
*/
|
|
574
|
-
connectCDP: (cdpUrl: string, options?: ConnectOverCDPOptions) => Effect.Effect<typeof PlaywrightBrowser.Service, PlaywrightError>;
|
|
575
|
-
}
|
|
576
|
-
declare const Playwright_base: Context.TagClass<Playwright, "effect-playwright/index/Playwright", PlaywrightService>;
|
|
577
|
-
declare class Playwright extends Playwright_base {
|
|
578
|
-
/**
|
|
579
|
-
* @category layer
|
|
580
|
-
*/
|
|
581
|
-
static readonly layer: Layer.Layer<Playwright, never, never>;
|
|
582
|
-
}
|
|
583
|
-
//#endregion
|
|
584
|
-
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 };
|