effect-playwright 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as NewPageOptions, c as PlaywrightPageService, i as NewContextOptions, l as PlaywrightLocator, n as PlaywrightService, o as PlaywrightBrowser, r as LaunchOptions, s as PlaywrightPage, t as Playwright, u as PlaywrightLocatorService } from "./index-DnbVDccF.mjs";
2
- export { LaunchOptions, NewContextOptions, NewPageOptions, Playwright, PlaywrightBrowser, PlaywrightLocator, PlaywrightLocatorService, PlaywrightPage, PlaywrightPageService, PlaywrightService };
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 };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { i as PlaywrightLocator, n as PlaywrightBrowser, r as PlaywrightPage, t as Playwright } from "./src-BGGNNney.mjs";
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";
2
2
 
3
- export { Playwright, PlaywrightBrowser, PlaywrightLocator, PlaywrightPage };
3
+ export { Playwright, PlaywrightBrowser, PlaywrightBrowserContext, PlaywrightDialog, PlaywrightDownload, PlaywrightError, PlaywrightFileChooser, PlaywrightFrame, PlaywrightLocator, PlaywrightPage, PlaywrightRequest, PlaywrightResponse, PlaywrightWorker };
@@ -2,6 +2,16 @@ import { Context, Data, Effect, Layer, Option, Stream, identity } from "effect";
2
2
  import { chromium, errors } from "playwright-core";
3
3
 
4
4
  //#region src/errors.ts
5
+ /**
6
+ * Error type that is returned when a Playwright error occurs.
7
+ * Reason can either be "Timeout" or "Unknown".
8
+ *
9
+ * Timeout errors occur when a timeout is reached. All other errors are
10
+ * grouped under "Unknown".
11
+ *
12
+ * @category error
13
+ * @since 0.1.0
14
+ */
5
15
  var PlaywrightError = class extends Data.TaggedError("PlaywrightError") {};
6
16
  function wrapError(error) {
7
17
  if (error instanceof errors.TimeoutError) return new PlaywrightError({
@@ -19,13 +29,128 @@ function wrapError(error) {
19
29
  /** @internal */
20
30
  const useHelper = (api) => (userFunction) => Effect.tryPromise(() => userFunction(api)).pipe(Effect.mapError(wrapError));
21
31
 
32
+ //#endregion
33
+ //#region src/locator.ts
34
+ /**
35
+ * A service that provides a `PlaywrightLocator` instance.
36
+ *
37
+ * @since 0.1.0
38
+ * @category tag
39
+ */
40
+ var PlaywrightLocator = class PlaywrightLocator extends Context.Tag("effect-playwright/PlaywrightLocator")() {
41
+ /**
42
+ * Creates a `PlaywrightLocator` from a Playwright `Locator` instance. This is mostly for internal use.
43
+ * But you could use this if you have used `use` or similar to wrap the locator.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const playwrightNativeLocator = yield* page.use((p) => p.locator("button"));
48
+ * const locator = PlaywrightLocator.make(playwrightNativeLocator);
49
+ * ```
50
+ *
51
+ * @param locator - The Playwright `Locator` instance to wrap.
52
+ * @since 0.1.0
53
+ * @category constructor
54
+ */
55
+ static make(locator) {
56
+ const use = useHelper(locator);
57
+ return PlaywrightLocator.of({
58
+ click: (options) => use((l) => l.click(options)),
59
+ fill: (value, options) => use((l) => l.fill(value, options)),
60
+ getAttribute: (name, options) => use((l) => l.getAttribute(name, options)),
61
+ innerText: (options) => use((l) => l.innerText(options)),
62
+ innerHTML: (options) => use((l) => l.innerHTML(options)),
63
+ inputValue: (options) => use((l) => l.inputValue(options)),
64
+ textContent: (options) => use((l) => l.textContent(options)),
65
+ count: use((l) => l.count()),
66
+ first: () => PlaywrightLocator.make(locator.first()),
67
+ last: () => PlaywrightLocator.make(locator.last()),
68
+ nth: (index) => PlaywrightLocator.make(locator.nth(index)),
69
+ evaluate: (pageFunction, arg, options) => use((l) => l.evaluate(pageFunction, arg, options)),
70
+ use
71
+ });
72
+ }
73
+ };
74
+
75
+ //#endregion
76
+ //#region src/page.ts
77
+ const eventMappings$2 = {
78
+ close: (page) => PlaywrightPage.make(page),
79
+ console: identity,
80
+ crash: (page) => PlaywrightPage.make(page),
81
+ dialog: (dialog) => PlaywrightDialog.make(dialog),
82
+ domcontentloaded: (page) => PlaywrightPage.make(page),
83
+ download: (download) => PlaywrightDownload.make(download),
84
+ filechooser: (fileChooser) => PlaywrightFileChooser.make(fileChooser),
85
+ frameattached: (frame) => PlaywrightFrame.make(frame),
86
+ framedetached: (frame) => PlaywrightFrame.make(frame),
87
+ framenavigated: (frame) => PlaywrightFrame.make(frame),
88
+ load: (page) => PlaywrightPage.make(page),
89
+ pageerror: identity,
90
+ popup: (page) => PlaywrightPage.make(page),
91
+ request: (request) => PlaywrightRequest.make(request),
92
+ requestfailed: (request) => PlaywrightRequest.make(request),
93
+ requestfinished: (request) => PlaywrightRequest.make(request),
94
+ response: (response) => PlaywrightResponse.make(response),
95
+ websocket: identity,
96
+ worker: (worker) => PlaywrightWorker.make(worker)
97
+ };
98
+ /**
99
+ * @category tag
100
+ */
101
+ var PlaywrightPage = class PlaywrightPage extends Context.Tag("effect-playwright/PlaywrightPage")() {
102
+ /**
103
+ * Creates a `PlaywrightPage` from a Playwright `Page` instance.
104
+ *
105
+ * @param page - The Playwright `Page` instance to wrap.
106
+ * @since 0.1.0
107
+ */
108
+ static make(page) {
109
+ const use = useHelper(page);
110
+ return PlaywrightPage.of({
111
+ goto: (url, options) => use((p) => p.goto(url, options)),
112
+ waitForURL: (url, options) => use((p) => p.waitForURL(url, options)),
113
+ title: use((p) => p.title()),
114
+ evaluate: (f, arg) => use((p) => p.evaluate(f, arg)),
115
+ locator: (selector, options) => PlaywrightLocator.make(page.locator(selector, options)),
116
+ getByRole: (role, options) => PlaywrightLocator.make(page.getByRole(role, options)),
117
+ getByText: (text, options) => PlaywrightLocator.make(page.getByText(text, options)),
118
+ getByLabel: (label, options) => PlaywrightLocator.make(page.getByLabel(label, options)),
119
+ getByTestId: (testId) => PlaywrightLocator.make(page.getByTestId(testId)),
120
+ url: Effect.sync(() => page.url()),
121
+ reload: use((p) => p.reload()),
122
+ close: use((p) => p.close()),
123
+ click: (selector, options) => use((p) => p.click(selector, options)),
124
+ eventStream: (event) => Stream.asyncPush((emit) => Effect.acquireRelease(Effect.sync(() => {
125
+ page.on(event, emit.single);
126
+ page.once("close", emit.end);
127
+ }), () => Effect.sync(() => {
128
+ page.off(event, emit.single);
129
+ page.off("close", emit.end);
130
+ }))).pipe(Stream.map((e) => {
131
+ const mapping = eventMappings$2[event];
132
+ return mapping(e);
133
+ })),
134
+ use
135
+ });
136
+ }
137
+ };
138
+
22
139
  //#endregion
23
140
  //#region src/common.ts
141
+ /**
142
+ * @category model
143
+ * @since 0.1.2
144
+ */
24
145
  var PlaywrightFrame = class PlaywrightFrame extends Data.TaggedClass("PlaywrightFrame") {
25
146
  static make(frame) {
26
147
  return new PlaywrightFrame({ use: useHelper(frame) });
27
148
  }
28
149
  };
150
+ /**
151
+ * @category model
152
+ * @since 0.1.2
153
+ */
29
154
  var PlaywrightRequest = class PlaywrightRequest extends Data.TaggedClass("PlaywrightRequest") {
30
155
  static make(request) {
31
156
  const use = useHelper(request);
@@ -52,6 +177,10 @@ var PlaywrightRequest = class PlaywrightRequest extends Data.TaggedClass("Playwr
52
177
  });
53
178
  }
54
179
  };
180
+ /**
181
+ * @category model
182
+ * @since 0.1.2
183
+ */
55
184
  var PlaywrightResponse = class PlaywrightResponse extends Data.TaggedClass("PlaywrightResponse") {
56
185
  static make(response) {
57
186
  const use = useHelper(response);
@@ -77,6 +206,10 @@ var PlaywrightResponse = class PlaywrightResponse extends Data.TaggedClass("Play
77
206
  });
78
207
  }
79
208
  };
209
+ /**
210
+ * @category model
211
+ * @since 0.1.2
212
+ */
80
213
  var PlaywrightWorker = class PlaywrightWorker extends Data.TaggedClass("PlaywrightWorker") {
81
214
  static make(worker) {
82
215
  const use = useHelper(worker);
@@ -86,6 +219,10 @@ var PlaywrightWorker = class PlaywrightWorker extends Data.TaggedClass("Playwrig
86
219
  });
87
220
  }
88
221
  };
222
+ /**
223
+ * @category model
224
+ * @since 0.1.2
225
+ */
89
226
  var PlaywrightDialog = class PlaywrightDialog extends Data.TaggedClass("PlaywrightDialog") {
90
227
  static make(dialog) {
91
228
  const use = useHelper(dialog);
@@ -99,6 +236,10 @@ var PlaywrightDialog = class PlaywrightDialog extends Data.TaggedClass("Playwrig
99
236
  });
100
237
  }
101
238
  };
239
+ /**
240
+ * @category model
241
+ * @since 0.1.2
242
+ */
102
243
  var PlaywrightFileChooser = class PlaywrightFileChooser extends Data.TaggedClass("PlaywrightFileChooser") {
103
244
  static make(fileChooser) {
104
245
  const use = useHelper(fileChooser);
@@ -110,6 +251,10 @@ var PlaywrightFileChooser = class PlaywrightFileChooser extends Data.TaggedClass
110
251
  });
111
252
  }
112
253
  };
254
+ /**
255
+ * @category model
256
+ * @since 0.1.2
257
+ */
113
258
  var PlaywrightDownload = class PlaywrightDownload extends Data.TaggedClass("PlaywrightDownload") {
114
259
  static make(download) {
115
260
  const use = useHelper(download);
@@ -129,137 +274,57 @@ var PlaywrightDownload = class PlaywrightDownload extends Data.TaggedClass("Play
129
274
  };
130
275
 
131
276
  //#endregion
132
- //#region src/locator.ts
133
- /**
134
- * A service that provides a `PlaywrightLocator` instance.
135
- *
136
- * @since 0.1.0
137
- * @category tag
138
- */
139
- var PlaywrightLocator = class PlaywrightLocator extends Context.Tag("effect-playwright/PlaywrightLocator")() {
140
- /**
141
- * Creates a `PlaywrightLocator` from a Playwright `Locator` instance. This is mostly for internal use.
142
- * But you could use this if you have used `use` or similar to wrap the locator.
143
- *
144
- * @example
145
- * ```ts
146
- * const playwrightNativeLocator = yield* page.use((p) => p.locator("button"));
147
- * const locator = PlaywrightLocator.make(playwrightNativeLocator);
148
- * ```
149
- *
150
- * @param locator - The Playwright `Locator` instance to wrap.
151
- * @since 0.1.0
152
- * @category constructor
153
- */
154
- static make(locator) {
155
- const use = useHelper(locator);
156
- return PlaywrightLocator.of({
157
- click: (options) => use((l) => l.click(options)),
158
- fill: (value, options) => use((l) => l.fill(value, options)),
159
- getAttribute: (name, options) => use((l) => l.getAttribute(name, options)),
160
- innerText: (options) => use((l) => l.innerText(options)),
161
- innerHTML: (options) => use((l) => l.innerHTML(options)),
162
- inputValue: (options) => use((l) => l.inputValue(options)),
163
- textContent: (options) => use((l) => l.textContent(options)),
164
- count: use((l) => l.count()),
165
- first: () => PlaywrightLocator.make(locator.first()),
166
- last: () => PlaywrightLocator.make(locator.last()),
167
- nth: (index) => PlaywrightLocator.make(locator.nth(index)),
168
- evaluate: (pageFunction, arg, options) => use((l) => l.evaluate(pageFunction, arg, options)),
169
- use
170
- });
171
- }
277
+ //#region src/browser-context.ts
278
+ const eventMappings$1 = {
279
+ backgroundpage: (page) => PlaywrightPage.make(page),
280
+ close: (context) => PlaywrightBrowserContext.make(context),
281
+ console: identity,
282
+ dialog: (dialog) => PlaywrightDialog.make(dialog),
283
+ page: (page) => PlaywrightPage.make(page),
284
+ request: (request) => PlaywrightRequest.make(request),
285
+ requestfailed: (request) => PlaywrightRequest.make(request),
286
+ requestfinished: (request) => PlaywrightRequest.make(request),
287
+ response: (response) => PlaywrightResponse.make(response),
288
+ serviceworker: (worker) => PlaywrightWorker.make(worker),
289
+ weberror: identity
172
290
  };
173
-
174
- //#endregion
175
- //#region src/page.ts
176
291
  /**
177
292
  * @category tag
178
293
  */
179
- var PlaywrightPage = class PlaywrightPage extends Context.Tag("effect-playwright/PlaywrightPage")() {
294
+ var PlaywrightBrowserContext = class PlaywrightBrowserContext extends Context.Tag("effect-playwright/PlaywrightBrowserContext")() {
180
295
  /**
181
- * Creates a `PlaywrightPage` from a Playwright `Page` instance.
296
+ * Creates a `PlaywrightBrowserContext` from a Playwright `BrowserContext` instance.
182
297
  *
183
- * @param page - The Playwright `Page` instance to wrap.
298
+ * @param context - The Playwright `BrowserContext` instance to wrap.
184
299
  * @since 0.1.0
185
300
  */
186
- static make(page) {
187
- const use = useHelper(page);
188
- return PlaywrightPage.of({
189
- goto: (url, options) => use((p) => p.goto(url, options)),
190
- waitForURL: (url, options) => use((p) => p.waitForURL(url, options)),
191
- title: use((p) => p.title()),
192
- evaluate: (f, arg) => use((p) => p.evaluate(f, arg)),
193
- locator: (selector, options) => PlaywrightLocator.make(page.locator(selector, options)),
194
- getByRole: (role, options) => PlaywrightLocator.make(page.getByRole(role, options)),
195
- getByText: (text, options) => PlaywrightLocator.make(page.getByText(text, options)),
196
- getByLabel: (label, options) => PlaywrightLocator.make(page.getByLabel(label, options)),
197
- getByTestId: (testId) => PlaywrightLocator.make(page.getByTestId(testId)),
198
- url: Effect.sync(() => page.url()),
199
- reload: use((p) => p.reload()),
200
- close: use((p) => p.close()),
201
- click: (selector, options) => use((p) => p.click(selector, options)),
202
- eventStream: (event) => Stream.asyncPush((emit) => Effect.acquireRelease(Effect.sync(() => {
203
- const callback = emit.single;
204
- const closeCallback = emit.end;
205
- page.on(event, callback);
206
- page.once("close", closeCallback);
207
- return {
208
- callback,
209
- closeCallback
210
- };
211
- }), ({ callback, closeCallback }) => Effect.sync(() => {
212
- page.off(event, callback);
213
- page.off("close", closeCallback);
214
- }))).pipe(Stream.map((e) => {
215
- const mapper = eventMappings[event];
216
- return mapper(e);
217
- })),
218
- use
219
- });
220
- }
221
- };
222
- const eventMappings = {
223
- close: PlaywrightPage.make,
224
- console: identity,
225
- crash: PlaywrightPage.make,
226
- dialog: PlaywrightDialog.make,
227
- domcontentloaded: PlaywrightPage.make,
228
- download: PlaywrightDownload.make,
229
- filechooser: PlaywrightFileChooser.make,
230
- frameattached: PlaywrightFrame.make,
231
- framedetached: PlaywrightFrame.make,
232
- framenavigated: PlaywrightFrame.make,
233
- load: PlaywrightPage.make,
234
- pageerror: identity,
235
- popup: PlaywrightPage.make,
236
- request: PlaywrightRequest.make,
237
- requestfailed: PlaywrightRequest.make,
238
- requestfinished: PlaywrightRequest.make,
239
- response: PlaywrightResponse.make,
240
- websocket: identity,
241
- worker: PlaywrightWorker.make
242
- };
243
-
244
- //#endregion
245
- //#region src/browser-context.ts
246
- var PlaywrightBrowserContext = class PlaywrightBrowserContext extends Context.Tag("cehs/backend/lib/playwright/PlaywrightBrowserContext")() {
247
301
  static make(context) {
248
302
  const use = useHelper(context);
249
303
  return PlaywrightBrowserContext.of({
250
304
  pages: Effect.sync(() => context.pages().map(PlaywrightPage.make)),
251
305
  newPage: use((c) => c.newPage().then(PlaywrightPage.make)),
252
- close: use((c) => c.close())
306
+ close: use((c) => c.close()),
307
+ eventStream: (event) => Stream.asyncPush((emit) => Effect.acquireRelease(Effect.sync(() => {
308
+ context.on(event, emit.single);
309
+ context.once("close", emit.end);
310
+ }), () => Effect.sync(() => {
311
+ context.off(event, emit.single);
312
+ context.off("close", emit.end);
313
+ }))).pipe(Stream.map((e) => {
314
+ const mapping = eventMappings$1[event];
315
+ return mapping(e);
316
+ }))
253
317
  });
254
318
  }
255
319
  };
256
320
 
257
321
  //#endregion
258
322
  //#region src/browser.ts
323
+ const eventMappings = { disconnected: (browser) => PlaywrightBrowser.make(browser) };
259
324
  /**
260
325
  * @category tag
261
326
  */
262
- var PlaywrightBrowser = class PlaywrightBrowser extends Context.Tag("cehs/backend/lib/playwright/PlaywrightBrowser")() {
327
+ var PlaywrightBrowser = class PlaywrightBrowser extends Context.Tag("effect-playwright/PlaywrightBrowser")() {
263
328
  /**
264
329
  * @category constructor
265
330
  */
@@ -273,6 +338,16 @@ var PlaywrightBrowser = class PlaywrightBrowser extends Context.Tag("cehs/backen
273
338
  browserType: Effect.sync(() => browser.browserType()),
274
339
  version: Effect.sync(() => browser.version()),
275
340
  isConnected: Effect.sync(() => browser.isConnected()),
341
+ eventStream: (event) => Stream.asyncPush((emit) => Effect.acquireRelease(Effect.sync(() => {
342
+ browser.on(event, emit.single);
343
+ browser.once("disconnected", emit.end);
344
+ }), () => Effect.sync(() => {
345
+ browser.off(event, emit.single);
346
+ browser.off("disconnected", emit.end);
347
+ }))).pipe(Stream.map((e) => {
348
+ const mapping = eventMappings[event];
349
+ return mapping(e);
350
+ })),
276
351
  use
277
352
  });
278
353
  }
@@ -294,6 +369,10 @@ const connectCDP = Effect.fn(function* (cdpUrl, options) {
294
369
  });
295
370
  return PlaywrightBrowser.make(browser);
296
371
  });
372
+ /**
373
+ * @category tag
374
+ * @since 0.1.0
375
+ */
297
376
  var Playwright = class Playwright extends Context.Tag("effect-playwright/index/Playwright")() {
298
377
  /**
299
378
  * @category layer
@@ -307,4 +386,4 @@ var Playwright = class Playwright extends Context.Tag("effect-playwright/index/P
307
386
  };
308
387
 
309
388
  //#endregion
310
- export { PlaywrightLocator as i, PlaywrightBrowser as n, PlaywrightPage as r, Playwright as t };
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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "effect-playwright",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "An Effect-based Playwright library.",
6
6
  "author": "Jobflow GmbH",
7
7
  "license": "ISC",
@@ -37,15 +37,16 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@biomejs/biome": "2.3.11",
40
- "@effect/language-service": "^0.65.0",
40
+ "@effect/language-service": "^0.69.2",
41
41
  "@effect/platform": "^0.94.1",
42
42
  "@effect/platform-node": "^0.104.0",
43
43
  "@effect/vitest": "^0.27.0",
44
- "@types/node": "^25.0.8",
44
+ "@types/node": "^25.0.9",
45
45
  "effect": "^3.19.14",
46
46
  "playwright": "^1.57.0",
47
- "tsdown": "0.20.0-beta.1",
47
+ "tsdown": "0.20.0-beta.3",
48
48
  "tsx": "^4.21.0",
49
+ "typedoc": "^0.28.16",
49
50
  "typescript": "^5.9.3",
50
51
  "vitest": "^4.0.17"
51
52
  },
@@ -53,6 +54,8 @@
53
54
  "scripts": {
54
55
  "build": "tsdown",
55
56
  "test": "vitest run",
56
- "type-check": "tsc --noEmit"
57
+ "type-check": "tsc --noEmit",
58
+ "generate-docs": "typedoc",
59
+ "format-fix": "biome format --fix"
57
60
  }
58
61
  }