effect-playwright 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,28 @@
1
- import { o as PlaywrightBrowser, x as PlaywrightError } from "../index-BTxElyN5.mjs";
2
- import { Context, Effect, Layer } from "effect";
1
+ import { S as PlaywrightError, d as PlaywrightPageService, o as PlaywrightBrowser, s as PlaywrightBrowserService, y as PlaywrightFrameService } from "../index-ChKUVZYe.mjs";
2
+ import { Context, Effect, Layer, Stream } from "effect";
3
3
  import { BrowserType, LaunchOptions } from "playwright-core";
4
4
  import { Scope as Scope$1 } from "effect/Scope";
5
5
 
6
- //#region src/experimental/environment.d.ts
6
+ //#region src/experimental/browser-utils.d.ts
7
+ declare namespace browser_utils_d_exports {
8
+ export { allFrameNavigatedEventStream, allFrames, allPages };
9
+ }
10
+ /**
11
+ * Returns all pages in the browser from all contexts.
12
+ * @category util
13
+ */
14
+ declare const allPages: (browser: PlaywrightBrowserService) => Effect.Effect<PlaywrightPageService[], never, never>;
15
+ /**
16
+ * Returns all frames in the browser from all pages in all contexts.
17
+ * @category util
18
+ */
19
+ declare const allFrames: (browser: PlaywrightBrowserService) => Effect.Effect<(readonly PlaywrightFrameService[])[], PlaywrightError, never>;
20
+ /**
21
+ * Returns a stream of all framenavigated events for all current and future pages in the browser.
22
+ * In all current contexts (but not future contexts).
23
+ * @category util
24
+ */
25
+ declare const allFrameNavigatedEventStream: (browser: PlaywrightBrowserService) => Stream.Stream<PlaywrightFrameService, never, never>;
7
26
  declare namespace environment_d_exports {
8
27
  export { PlaywrightEnvironment, layer, withBrowser };
9
28
  }
@@ -74,4 +93,4 @@ declare const layer: (browser: BrowserType, launchOptions?: LaunchOptions) => La
74
93
  */
75
94
  declare const withBrowser: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, PlaywrightError | E, PlaywrightEnvironment | Exclude<R, PlaywrightBrowser>>;
76
95
  //#endregion
77
- export { environment_d_exports as PlaywrightEnvironment };
96
+ export { browser_utils_d_exports as BrowserUtils, environment_d_exports as PlaywrightEnvironment };
@@ -1,7 +1,36 @@
1
1
  import { t as __exportAll } from "../chunk-BiucMVzj.mjs";
2
- import { n as PlaywrightBrowser, t as Playwright } from "../src-D0uXY5ik.mjs";
3
- import { Context, Effect, Layer } from "effect";
2
+ import { n as PlaywrightBrowser, t as Playwright } from "../src-BBJfAuBn.mjs";
3
+ import { Array, Context, Effect, Layer, Stream, pipe } from "effect";
4
4
 
5
+ //#region src/experimental/browser-utils.ts
6
+ var browser_utils_exports = /* @__PURE__ */ __exportAll({
7
+ allFrameNavigatedEventStream: () => allFrameNavigatedEventStream,
8
+ allFrames: () => allFrames,
9
+ allPages: () => allPages
10
+ });
11
+ /**
12
+ * Returns all pages in the browser from all contexts.
13
+ * @category util
14
+ */
15
+ const allPages = (browser) => browser.contexts.pipe(Effect.flatMap((contexts) => Effect.all(contexts.map((context) => context.pages))), Effect.map(Array.flatten));
16
+ /**
17
+ * Returns all frames in the browser from all pages in all contexts.
18
+ * @category util
19
+ */
20
+ const allFrames = (browser) => allPages(browser).pipe(Effect.flatMap((pages) => Effect.all(pages.map((page) => page.frames))));
21
+ /**
22
+ * Returns a stream of all framenavigated events for all current and future pages in the browser.
23
+ * In all current contexts (but not future contexts).
24
+ * @category util
25
+ */
26
+ const allFrameNavigatedEventStream = (browser) => Effect.gen(function* () {
27
+ const contexts = yield* browser.contexts;
28
+ const currentPages = (yield* pipe(contexts.map((c) => c.pages), Effect.all, Effect.map(Array.flatten))).map((page) => page.eventStream("framenavigated"));
29
+ const newPages = pipe(contexts.map((c) => c.eventStream("page")), Stream.mergeAll({ concurrency: "unbounded" }), Stream.flatMap((page) => page.eventStream("framenavigated"), { concurrency: "unbounded" }));
30
+ return Stream.mergeAll([newPages, ...currentPages], { concurrency: "unbounded" });
31
+ }).pipe(Stream.unwrap);
32
+
33
+ //#endregion
5
34
  //#region src/experimental/environment.ts
6
35
  var environment_exports = /* @__PURE__ */ __exportAll({
7
36
  PlaywrightEnvironment: () => PlaywrightEnvironment,
@@ -77,4 +106,4 @@ const layer = (browser, launchOptions) => {
77
106
  const withBrowser = Effect.provide(PlaywrightEnvironment.pipe(Effect.map((e) => e.browser), Effect.flatten, Layer.scoped(PlaywrightBrowser)));
78
107
 
79
108
  //#endregion
80
- export { environment_exports as PlaywrightEnvironment };
109
+ export { browser_utils_exports as BrowserUtils, environment_exports as PlaywrightEnvironment };
@@ -1,7 +1,7 @@
1
1
  import { Context, Effect, Layer, Option, Scope, Stream } from "effect";
2
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
3
  import { Scope as Scope$1 } from "effect/Scope";
4
- import * as effect_Types6 from "effect/Types";
4
+ import * as effect_Types0 from "effect/Types";
5
5
  import * as effect_Cause0 from "effect/Cause";
6
6
 
7
7
  //#region src/errors.d.ts
@@ -13,7 +13,7 @@ import * as effect_Cause0 from "effect/Cause";
13
13
  * @since 0.1.0
14
14
  */
15
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 & {
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
17
  readonly _tag: "PlaywrightError";
18
18
  } & Readonly<A>;
19
19
  /**
@@ -54,145 +54,6 @@ type PatchedEvents<Original, Events> = Original & {
54
54
  once<K extends keyof Events>(event: K, listener: (arg: Events[K]) => void): PatchedEvents<Original, Events>;
55
55
  };
56
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
57
  //#region src/locator.d.ts
197
58
  /**
198
59
  * Interface for a Playwright locator.
@@ -340,6 +201,268 @@ declare class PlaywrightLocator extends PlaywrightLocator_base {
340
201
  static make(locator: Locator): typeof PlaywrightLocator.Service;
341
202
  }
342
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
343
466
  //#region src/page.d.ts
344
467
  interface PageEvents {
345
468
  close: Page;
@@ -370,9 +493,9 @@ declare const eventMappings$2: {
370
493
  readonly domcontentloaded: (page: Page) => PlaywrightPageService;
371
494
  readonly download: (download: Download) => PlaywrightDownload;
372
495
  readonly filechooser: (fileChooser: FileChooser) => PlaywrightFileChooser;
373
- readonly frameattached: (frame: Frame) => PlaywrightFrame;
374
- readonly framedetached: (frame: Frame) => PlaywrightFrame;
375
- readonly framenavigated: (frame: Frame) => PlaywrightFrame;
496
+ readonly frameattached: (frame: Frame) => PlaywrightFrameService;
497
+ readonly framedetached: (frame: Frame) => PlaywrightFrameService;
498
+ readonly framenavigated: (frame: Frame) => PlaywrightFrameService;
376
499
  readonly load: (page: Page) => PlaywrightPageService;
377
500
  readonly pageerror: (a: Error) => Error;
378
501
  readonly popup: (page: Page) => PlaywrightPageService;
@@ -413,6 +536,20 @@ interface PlaywrightPageService {
413
536
  * @since 0.1.0
414
537
  */
415
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>;
416
553
  /**
417
554
  * Evaluates a function in the context of the page.
418
555
  *
@@ -514,6 +651,13 @@ interface PlaywrightPageService {
514
651
  * @since 0.1.0
515
652
  */
516
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>;
517
661
  /**
518
662
  * Creates a stream of the given event from the page.
519
663
  *
@@ -522,6 +666,7 @@ interface PlaywrightPageService {
522
666
  * const consoleStream = page.eventStream("console");
523
667
  * ```
524
668
  *
669
+ * @category custom
525
670
  * @see {@link Page.on}
526
671
  * @since 0.1.0
527
672
  */
@@ -621,6 +766,7 @@ interface PlaywrightBrowserContextService {
621
766
  * const pageStream = context.eventStream("page");
622
767
  * ```
623
768
  *
769
+ * @category custom
624
770
  * @see {@link BrowserContext.on}
625
771
  * @since 0.1.2
626
772
  */
@@ -717,6 +863,7 @@ interface PlaywrightBrowserService {
717
863
  * const disconnectedStream = browser.eventStream("disconnected");
718
864
  * ```
719
865
  *
866
+ * @category custom
720
867
  * @see {@link Browser.on}
721
868
  * @since 0.1.2
722
869
  */
@@ -854,4 +1001,4 @@ declare class Playwright extends Playwright_base {
854
1001
  static readonly layer: Layer.Layer<Playwright, never, never>;
855
1002
  }
856
1003
  //#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 };
1004
+ export { PlaywrightErrorReason as C, PlaywrightError as S, PlaywrightWorker as _, NewPageOptions as a, PlaywrightLocator 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, PlaywrightFrame as v, PlaywrightLocatorService as x, PlaywrightFrameService as y };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { S as PlaywrightErrorReason, _ as PlaywrightFrame, a as NewPageOptions, b as PlaywrightWorker, c as PlaywrightBrowserContext, d as PlaywrightPageService, f as PlaywrightLocator, g as PlaywrightFileChooser, h as PlaywrightDownload, i as NewContextOptions, l as PlaywrightBrowserContextService, m as PlaywrightDialog, n as PlaywrightService, o as PlaywrightBrowser, p as PlaywrightLocatorService, r as LaunchOptions, s as PlaywrightBrowserService, t as Playwright, u as PlaywrightPage, v as PlaywrightRequest, x as PlaywrightError, y as PlaywrightResponse } from "./index-BTxElyN5.mjs";
2
- export { LaunchOptions, NewContextOptions, NewPageOptions, Playwright, PlaywrightBrowser, PlaywrightBrowserContext, PlaywrightBrowserContextService, PlaywrightBrowserService, PlaywrightDialog, PlaywrightDownload, PlaywrightError, PlaywrightErrorReason, PlaywrightFileChooser, PlaywrightFrame, PlaywrightLocator, PlaywrightLocatorService, PlaywrightPage, PlaywrightPageService, PlaywrightRequest, PlaywrightResponse, PlaywrightService, PlaywrightWorker };
1
+ import { C as PlaywrightErrorReason, S as PlaywrightError, _ as PlaywrightWorker, a as NewPageOptions, b as PlaywrightLocator, c as PlaywrightBrowserContext, d as PlaywrightPageService, f as PlaywrightDialog, g as PlaywrightResponse, h as PlaywrightRequest, i as NewContextOptions, l as PlaywrightBrowserContextService, m as PlaywrightFileChooser, n as PlaywrightService, o as PlaywrightBrowser, p as PlaywrightDownload, r as LaunchOptions, s as PlaywrightBrowserService, t as Playwright, u as PlaywrightPage, v as PlaywrightFrame, x as PlaywrightLocatorService, y as PlaywrightFrameService } from "./index-ChKUVZYe.mjs";
2
+ export { LaunchOptions, NewContextOptions, NewPageOptions, Playwright, PlaywrightBrowser, PlaywrightBrowserContext, PlaywrightBrowserContextService, PlaywrightBrowserService, PlaywrightDialog, PlaywrightDownload, PlaywrightError, PlaywrightErrorReason, PlaywrightFileChooser, PlaywrightFrame, PlaywrightFrameService, PlaywrightLocator, PlaywrightLocatorService, PlaywrightPage, PlaywrightPageService, PlaywrightRequest, PlaywrightResponse, PlaywrightService, PlaywrightWorker };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as PlaywrightDownload, c as PlaywrightRequest, d as PlaywrightPage, f as PlaywrightLocator, i as PlaywrightDialog, l as PlaywrightResponse, n as PlaywrightBrowser, o as PlaywrightFileChooser, p as PlaywrightError, r as PlaywrightBrowserContext, s as PlaywrightFrame, t as Playwright, u as PlaywrightWorker } from "./src-D0uXY5ik.mjs";
1
+ import { a as PlaywrightDownload, c as PlaywrightResponse, d as PlaywrightFrame, f as PlaywrightLocator, i as PlaywrightDialog, l as PlaywrightWorker, n as PlaywrightBrowser, o as PlaywrightFileChooser, p as PlaywrightError, r as PlaywrightBrowserContext, s as PlaywrightRequest, t as Playwright, u as PlaywrightPage } from "./src-BBJfAuBn.mjs";
2
2
 
3
3
  export { Playwright, PlaywrightBrowser, PlaywrightBrowserContext, PlaywrightDialog, PlaywrightDownload, PlaywrightError, PlaywrightFileChooser, PlaywrightFrame, PlaywrightLocator, PlaywrightPage, PlaywrightRequest, PlaywrightResponse, PlaywrightWorker };
@@ -1,4 +1,5 @@
1
1
  import { Context, Data, Effect, Layer, Option, Stream, identity } from "effect";
2
+ import { Readable } from "node:stream";
2
3
  import { chromium, errors } from "playwright-core";
3
4
 
4
5
  //#region src/errors.ts
@@ -72,6 +73,41 @@ var PlaywrightLocator = class PlaywrightLocator extends Context.Tag("effect-play
72
73
  }
73
74
  };
74
75
 
76
+ //#endregion
77
+ //#region src/frame.ts
78
+ /**
79
+ * @category tag
80
+ * @since 0.1.2
81
+ */
82
+ var PlaywrightFrame = class PlaywrightFrame extends Context.Tag("effect-playwright/PlaywrightFrame")() {
83
+ /**
84
+ * Creates a `PlaywrightFrame` from a Playwright `Frame` instance.
85
+ *
86
+ * @param frame - The Playwright `Frame` instance to wrap.
87
+ * @since 0.1.2
88
+ */
89
+ static make(frame) {
90
+ const use = useHelper(frame);
91
+ return PlaywrightFrame.of({
92
+ goto: (url, options) => use((f) => f.goto(url, options)),
93
+ waitForURL: (url, options) => use((f) => f.waitForURL(url, options)),
94
+ waitForLoadState: (state, options) => use((f) => f.waitForLoadState(state, options)),
95
+ evaluate: (f, arg) => use((frame$1) => frame$1.evaluate(f, arg)),
96
+ title: use((f) => f.title()),
97
+ use,
98
+ locator: (selector, options) => PlaywrightLocator.make(frame.locator(selector, options)),
99
+ getByRole: (role, options) => PlaywrightLocator.make(frame.getByRole(role, options)),
100
+ getByText: (text, options) => PlaywrightLocator.make(frame.getByText(text, options)),
101
+ getByLabel: (label, options) => PlaywrightLocator.make(frame.getByLabel(label, options)),
102
+ getByTestId: (testId) => PlaywrightLocator.make(frame.getByTestId(testId)),
103
+ url: Effect.sync(() => frame.url()),
104
+ content: use((f) => f.content()),
105
+ name: Effect.sync(() => frame.name()),
106
+ click: (selector, options) => use((f) => f.click(selector, options))
107
+ });
108
+ }
109
+ };
110
+
75
111
  //#endregion
76
112
  //#region src/page.ts
77
113
  const eventMappings$2 = {
@@ -110,6 +146,7 @@ var PlaywrightPage = class PlaywrightPage extends Context.Tag("effect-playwright
110
146
  return PlaywrightPage.of({
111
147
  goto: (url, options) => use((p) => p.goto(url, options)),
112
148
  waitForURL: (url, options) => use((p) => p.waitForURL(url, options)),
149
+ waitForLoadState: (state, options) => use((p) => p.waitForLoadState(state, options)),
113
150
  title: use((p) => p.title()),
114
151
  evaluate: (f, arg) => use((p) => p.evaluate(f, arg)),
115
152
  locator: (selector, options) => PlaywrightLocator.make(page.locator(selector, options)),
@@ -118,6 +155,7 @@ var PlaywrightPage = class PlaywrightPage extends Context.Tag("effect-playwright
118
155
  getByLabel: (label, options) => PlaywrightLocator.make(page.getByLabel(label, options)),
119
156
  getByTestId: (testId) => PlaywrightLocator.make(page.getByTestId(testId)),
120
157
  url: Effect.sync(() => page.url()),
158
+ frames: use((p) => Promise.resolve(p.frames().map(PlaywrightFrame.make))),
121
159
  reload: use((p) => p.reload()),
122
160
  close: use((p) => p.close()),
123
161
  click: (selector, options) => use((p) => p.click(selector, options)),
@@ -142,15 +180,6 @@ var PlaywrightPage = class PlaywrightPage extends Context.Tag("effect-playwright
142
180
  * @category model
143
181
  * @since 0.1.2
144
182
  */
145
- var PlaywrightFrame = class PlaywrightFrame extends Data.TaggedClass("PlaywrightFrame") {
146
- static make(frame) {
147
- return new PlaywrightFrame({ use: useHelper(frame) });
148
- }
149
- };
150
- /**
151
- * @category model
152
- * @since 0.1.2
153
- */
154
183
  var PlaywrightRequest = class PlaywrightRequest extends Data.TaggedClass("PlaywrightRequest") {
155
184
  static make(request) {
156
185
  const use = useHelper(request);
@@ -260,7 +289,7 @@ var PlaywrightDownload = class PlaywrightDownload extends Data.TaggedClass("Play
260
289
  const use = useHelper(download);
261
290
  return new PlaywrightDownload({
262
291
  cancel: use(() => download.cancel()),
263
- createReadStream: Stream.empty,
292
+ stream: use(() => download.createReadStream().then((s) => Readable.toWeb(s))).pipe(Effect.map((s) => Stream.fromReadableStream(() => s, wrapError)), Stream.unwrap),
264
293
  delete: use(() => download.delete()),
265
294
  failure: use(() => download.failure()).pipe(Effect.map(Option.fromNullable)),
266
295
  page: () => PlaywrightPage.make(download.page()),
@@ -386,4 +415,4 @@ var Playwright = class Playwright extends Context.Tag("effect-playwright/index/P
386
415
  };
387
416
 
388
417
  //#endregion
389
- export { PlaywrightDownload as a, PlaywrightRequest as c, PlaywrightPage as d, PlaywrightLocator as f, PlaywrightDialog as i, PlaywrightResponse as l, PlaywrightBrowser as n, PlaywrightFileChooser as o, PlaywrightError as p, PlaywrightBrowserContext as r, PlaywrightFrame as s, Playwright as t, PlaywrightWorker as u };
418
+ export { PlaywrightDownload as a, PlaywrightResponse as c, PlaywrightFrame as d, PlaywrightLocator as f, PlaywrightDialog as i, PlaywrightWorker as l, PlaywrightBrowser as n, PlaywrightFileChooser as o, PlaywrightError as p, PlaywrightBrowserContext as r, PlaywrightRequest as s, Playwright as t, PlaywrightPage as u };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "effect-playwright",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.2.1",
5
5
  "description": "An Effect-based Playwright library.",
6
6
  "author": "Jobflow GmbH",
7
7
  "license": "ISC",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@biomejs/biome": "2.3.11",
40
- "@effect/language-service": "^0.69.2",
40
+ "@effect/language-service": "0.71.1",
41
41
  "@effect/platform": "^0.94.1",
42
42
  "@effect/platform-node": "^0.104.0",
43
43
  "@effect/vitest": "^0.27.0",