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/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![NPM Version](https://img.shields.io/npm/v/effect-playwright)](https://www.npmjs.com/package/effect-playwright)
4
4
  [![GitHub License](https://img.shields.io/github/license/Jobflow-io/effect-playwright)](https://github.com/Jobflow-io/effect-playwright/blob/main/LICENSE)
5
5
  [![Effect: yes](https://img.shields.io/badge/effect-yes-blue)](https://effect.website/)
6
+ [![Documentation](https://img.shields.io/badge/view_documentation-purple)](https://jobflow-io.github.io/effect-playwright/modules/index.html)
6
7
 
7
8
  A Playwright wrapper for the Effect ecosystem. This library provides a set of services and layers to interact with Playwright in a type-safe way using Effect.
8
9
 
@@ -125,6 +126,41 @@ const program = Effect.gen(function* () {
125
126
  }).pipe(PlaywrightEnvironment.withBrowser);
126
127
  ```
127
128
 
129
+ ## Event Handling
130
+
131
+ You can listen to Playwright events using the `eventStream` method. This returns an Effect `Stream` that emits events as they occur.
132
+
133
+ > [!NOTE]
134
+ > `eventStream` emits "Effectified" wrappers (e.g., `PlaywrightRequest`, `PlaywrightResponse`, `PlaywrightPage`) for most events. This allows you to continue using the Effect ecosystem seamlessly within your event handlers.
135
+
136
+ The stream is automatically managed and will close when the underlying resource (like the Page or Browser) is closed.
137
+
138
+ ### Example: Monitoring Network Requests
139
+
140
+ Since event streams run indefinitely until the resource closes, you often need to **fork** the resulting effect so it runs in the background without blocking your main program flow.
141
+
142
+ ```ts
143
+ const program = Effect.gen(function* () {
144
+ const browser = yield* PlaywrightBrowser;
145
+ const page = yield* browser.newPage();
146
+
147
+ // Create a stream of request events
148
+ yield* page.eventStream("request").pipe(
149
+ Stream.runForEach((request) =>
150
+ Effect.gen(function* () {
151
+ const url = yield* request.url;
152
+ yield* Effect.log(`Request: ${url}`);
153
+ }),
154
+ ),
155
+
156
+ // Fork to run it in the background
157
+ Effect.fork,
158
+ );
159
+
160
+ yield* page.goto("https://example.com");
161
+ }).pipe(PlaywrightEnvironment.withBrowser);
162
+ ```
163
+
128
164
  ## Accessing Native Playwright
129
165
 
130
166
  If you need to access functionality from the underlying Playwright objects that isn't directly exposed, you can use the `use` method available on most services/objects (browsers, pages, locators).
@@ -1,4 +1,4 @@
1
- import { d as PlaywrightError, o as PlaywrightBrowser } from "../index-DnbVDccF.mjs";
1
+ import { o as PlaywrightBrowser, x as PlaywrightError } from "../index-BTxElyN5.mjs";
2
2
  import { Context, Effect, Layer } from "effect";
3
3
  import { BrowserType, LaunchOptions } from "playwright-core";
4
4
  import { Scope as Scope$1 } from "effect/Scope";
@@ -13,9 +13,9 @@ declare const PlaywrightEnvironment_base: Context.TagClass<PlaywrightEnvironment
13
13
  /**
14
14
  * Most of the time you want to use the same kind of browser and configuration every time you use Playwright.
15
15
  * `PlaywrightEnvironment` is a service that allows you to configure how browsers are launched once. You can then
16
- * use {@link PlaywrightEnvironment.browser} to start browsers scoped to the current lifetime. They will be closed when the scope is closed.
16
+ * use `PlaywrightEnvironment.browser` to start browsers scoped to the current lifetime. They will be closed when the scope is closed.
17
17
  *
18
- * You can use {@link PlaywrightEnvironment.withBrowser} to provide the `PlaywrightBrowser` service to the wrapped effect. This
18
+ * You can use {@link withBrowser} to provide the `PlaywrightBrowser` service to the wrapped effect. This
19
19
  * also allows you to re-use the same browser as many times as you want.
20
20
  *
21
21
  * @since 0.1.0
@@ -70,6 +70,7 @@ declare const layer: (browser: BrowserType, launchOptions?: LaunchOptions) => La
70
70
  * ```
71
71
  *
72
72
  * @since 0.1.0
73
+ * @category util
73
74
  */
74
75
  declare const withBrowser: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, PlaywrightError | E, PlaywrightEnvironment | Exclude<R, PlaywrightBrowser>>;
75
76
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "../chunk-BiucMVzj.mjs";
2
- import { n as PlaywrightBrowser, t as Playwright } from "../src-BGGNNney.mjs";
2
+ import { n as PlaywrightBrowser, t as Playwright } from "../src-D0uXY5ik.mjs";
3
3
  import { Context, Effect, Layer } from "effect";
4
4
 
5
5
  //#region src/experimental/environment.ts
@@ -11,9 +11,9 @@ var environment_exports = /* @__PURE__ */ __exportAll({
11
11
  /**
12
12
  * Most of the time you want to use the same kind of browser and configuration every time you use Playwright.
13
13
  * `PlaywrightEnvironment` is a service that allows you to configure how browsers are launched once. You can then
14
- * use {@link PlaywrightEnvironment.browser} to start browsers scoped to the current lifetime. They will be closed when the scope is closed.
14
+ * use `PlaywrightEnvironment.browser` to start browsers scoped to the current lifetime. They will be closed when the scope is closed.
15
15
  *
16
- * You can use {@link PlaywrightEnvironment.withBrowser} to provide the `PlaywrightBrowser` service to the wrapped effect. This
16
+ * You can use {@link withBrowser} to provide the `PlaywrightBrowser` service to the wrapped effect. This
17
17
  * also allows you to re-use the same browser as many times as you want.
18
18
  *
19
19
  * @since 0.1.0
@@ -72,6 +72,7 @@ const layer = (browser, launchOptions) => {
72
72
  * ```
73
73
  *
74
74
  * @since 0.1.0
75
+ * @category util
75
76
  */
76
77
  const withBrowser = Effect.provide(PlaywrightEnvironment.pipe(Effect.map((e) => e.browser), Effect.flatten, Layer.scoped(PlaywrightBrowser)));
77
78