effect-browser 0.3.0-beta.6 → 0.3.0-beta.8

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.
Files changed (53) hide show
  1. package/README.md +124 -21
  2. package/dist/{Browser-B5AV7zPS.mjs → Browser-CNwK0r0q.mjs} +2 -2
  3. package/dist/{Browser-B5AV7zPS.mjs.map → Browser-CNwK0r0q.mjs.map} +1 -1
  4. package/dist/Browser.d.mts +2 -2
  5. package/dist/Browser.mjs +1 -1
  6. package/dist/{BrowserEvent-DzdNdvoh.d.mts → BrowserEvent-BRu2juEz.d.mts} +3 -1
  7. package/dist/BrowserEvent.d.mts +1 -1
  8. package/dist/BrowserEvent.mjs +2 -0
  9. package/dist/BrowserEvent.mjs.map +1 -1
  10. package/dist/Cdp.mjs +1 -1
  11. package/dist/{Change-DVP2IJWm.d.mts → Change-iMlcuzVD.d.mts} +2 -2
  12. package/dist/Change.d.mts +1 -1
  13. package/dist/Chromium.mjs +1 -1
  14. package/dist/Expect.d.mts +1 -1
  15. package/dist/Expect.mjs +1 -1
  16. package/dist/Moment.d.mts +1 -1
  17. package/dist/{Page-DYTdVhYa.d.mts → Page-C30aG2RQ.d.mts} +6 -4
  18. package/dist/Page-D4281dIi.mjs.map +1 -1
  19. package/dist/Page.d.mts +1 -1
  20. package/dist/Plan-BvCS9qAf.d.mts +209 -0
  21. package/dist/{Plan-5MdsRzE5.mjs → Plan-CyQNv49C.mjs} +232 -38
  22. package/dist/Plan-CyQNv49C.mjs.map +1 -0
  23. package/dist/Plan.d.mts +2 -2
  24. package/dist/Plan.mjs +2 -2
  25. package/dist/Policy.d.mts +1 -1
  26. package/dist/Presentation.d.mts +1 -1
  27. package/dist/Presentation.mjs +1 -1
  28. package/dist/Stage.d.mts +1 -1
  29. package/dist/Stage.mjs +1 -1
  30. package/dist/{Supervisor-Im6-wbg5.d.mts → Supervisor-CYWFK3vM.d.mts} +106 -56
  31. package/dist/Supervisor-TNKNOVzu.mjs +599 -0
  32. package/dist/Supervisor-TNKNOVzu.mjs.map +1 -0
  33. package/dist/Supervisor.d.mts +2 -2
  34. package/dist/Supervisor.mjs +2 -2
  35. package/dist/index.d.mts +5 -5
  36. package/dist/index.mjs +3 -3
  37. package/dist/{page-BkRcLCWZ.mjs → page-DHeYWEs-.mjs} +27 -14
  38. package/dist/page-DHeYWEs-.mjs.map +1 -0
  39. package/package.json +1 -1
  40. package/src/BrowserEvent.ts +2 -0
  41. package/src/Page.ts +3 -1
  42. package/src/Plan.ts +365 -56
  43. package/src/Supervisor.ts +384 -138
  44. package/src/internal/input/perform.ts +2 -0
  45. package/src/internal/page/bridge.ts +3 -3
  46. package/src/internal/reading/ready.inpage.ts +17 -7
  47. package/src/internal/reading/ready.ts +9 -3
  48. package/src/internal/supervisor/lifecycle.ts +291 -140
  49. package/dist/Plan-5MdsRzE5.mjs.map +0 -1
  50. package/dist/Plan-CNNOU1Tx.d.mts +0 -112
  51. package/dist/Supervisor-BtEG93gR.mjs +0 -420
  52. package/dist/Supervisor-BtEG93gR.mjs.map +0 -1
  53. package/dist/page-BkRcLCWZ.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Supervisor-TNKNOVzu.mjs","names":["Lifecycle.GenerationState","Lifecycle.resolve","Lifecycle.lookup","Lifecycle.Settled","Lifecycle.Unconfirmed","Lifecycle.start","Lifecycle.transition"],"sources":["../src/internal/supervisor/lifecycle.ts","../src/Supervisor.ts"],"sourcesContent":["/**\n * A supervisor's life as one state and one transition function, and the generation states it\n * publishes. The transition has no effects: `Supervisor.make` applies each input under one lock,\n * publishes the events in order and runs the commands, so the rules here are tested alone.\n */\nimport { Schema } from \"effect\";\n\nimport { DisconnectCause } from \"../../BrowserEvent.ts\";\n\n/** The provider confirmed that the generation's browser ended. */\nexport class Settled extends Schema.TaggedClass<Settled>()(\"Settled\", {}) {}\n\n/** The provider could not confirm the end by its deadline, so the browser may still run, and bill. */\nexport class Unconfirmed extends Schema.TaggedClass<Unconfirmed>()(\"Unconfirmed\", {\n detail: Schema.String,\n}) {}\n\nexport const Released = Schema.Union([Settled, Unconfirmed]);\n\nexport type Released = typeof Released.Type;\n\n/** Opening, but not after a loss: the first generation, a rotation, or the one after `Down`. */\nexport class Opening extends Schema.TaggedClass<Opening>()(\"Opening\", {}) {}\n\n/** Opening after the generation before it was lost. */\nexport class Reopening extends Schema.TaggedClass<Reopening>()(\"Reopening\", {}) {}\n\n/** Open: `browser` gives this generation until the next one opens. */\nexport class Open extends Schema.TaggedClass<Open>()(\"Open\", {}) {}\n\n/** No longer serving; holds end at this host-monotonic deadline or when their owners let go. */\nexport class Draining extends Schema.TaggedClass<Draining>()(\"Draining\", {\n reason: Schema.Literals([\"rotated\", \"lost\", \"retired\"]),\n revokeAt: Schema.Finite,\n}) {}\n\n/** Lost: its connection dropped, or its provider ended its session, as `cause` says. */\nexport class Lost extends Schema.TaggedClass<Lost>()(\"Lost\", {\n cause: DisconnectCause,\n}) {}\n\n/**\n * It never opened: its last try failed with `cause`, which the provider deems definite, or after\n * which the reopen schedule gave up.\n */\nexport class Down extends Schema.TaggedClass<Down>()(\"Down\", {\n detail: Schema.String,\n cause: Schema.Defect(),\n}) {}\n\n/** It ended. `released` says how its release went; one retired while opening has none. */\nexport class Closed extends Schema.TaggedClass<Closed>()(\"Closed\", {\n released: Schema.optional(Released),\n}) {}\n\n/**\n * It was serving as the supervisor's scope closed, and was left running, not released: its scope\n * closed, and its provider runs it on, and bills, until something adopts and releases it.\n */\nexport class Kept extends Schema.TaggedClass<Kept>()(\"Kept\", {}) {}\n\nexport const GenerationState = Schema.Union([\n Opening,\n Reopening,\n Open,\n Draining,\n Lost,\n Down,\n Closed,\n Kept,\n]);\n\nexport type GenerationState = typeof GenerationState.Type;\n\n/** A generation that opened: its number, and what the runtime keeps to serve and end it. */\nexport interface Live<A> {\n readonly number: number;\n readonly value: A;\n}\n\nexport interface Held<A, H> extends Live<A> {\n readonly holds: ReadonlySet<H>;\n}\n\n/** Release ownership remains here until the provider and generation scope have finished. */\nexport interface Drain<A, H> {\n readonly _tag: \"Draining\" | \"Releasing\" | \"Leaving\";\n readonly live: Held<A, H>;\n readonly ending: Draining;\n}\n\n/** One serving generation, one shared acquisition, and prior generations still owned. */\nexport type State<A, H = unknown> = (\n | { readonly _tag: \"Opening\"; readonly number: number; readonly serving: Held<A, H> | undefined }\n | { readonly _tag: \"Open\"; readonly serving: Held<A, H> }\n | {\n readonly _tag: \"Down\";\n readonly number: number;\n readonly detail: string;\n readonly cause: unknown;\n readonly serving: Held<A, H> | undefined;\n }\n | { readonly _tag: \"Retired\" }\n) & { readonly draining: ReadonlyMap<number, Drain<A, H>> };\n\nexport type Input<A, H = unknown> =\n | { readonly _tag: \"Opened\"; readonly live: Live<A> }\n | {\n readonly _tag: \"Failed\";\n readonly number: number;\n readonly detail: string;\n readonly cause: unknown;\n }\n | { readonly _tag: \"Abandoned\"; readonly number: number }\n | { readonly _tag: \"Lost\"; readonly number: number; readonly cause: DisconnectCause }\n | { readonly _tag: \"Rotate\"; readonly due?: number | undefined }\n | { readonly _tag: \"Retire\" }\n | { readonly _tag: \"Keep\" }\n | {\n readonly _tag: \"Hold\";\n readonly number?: number | undefined;\n readonly hold: H;\n }\n | { readonly _tag: \"Let\"; readonly number: number; readonly hold: H }\n | { readonly _tag: \"Revoke\"; readonly number: number }\n | {\n readonly _tag: \"Released\";\n readonly number: number;\n readonly released?: Released | undefined;\n };\n\nexport type Command<A> =\n | { readonly _tag: \"Open\"; readonly number: number; readonly after: number | undefined }\n | { readonly _tag: \"Watch\"; readonly live: Live<A> }\n /** Signal ending and arrange revocation. Repeated only when loss/retirement accelerates it. */\n | { readonly _tag: \"Drain\"; readonly live: Live<A>; readonly ending: Draining }\n /** Revoke/close holds, await their Let inputs, release the provider, then close its scope. */\n | { readonly _tag: \"Release\"; readonly live: Live<A>; readonly ending: Draining }\n | { readonly _tag: \"Leave\"; readonly live: Live<A>; readonly ending: Draining };\n\nexport interface Step<A, H = unknown> {\n readonly state: State<A, H>;\n readonly events: ReadonlyArray<readonly [number, GenerationState]>;\n readonly commands: ReadonlyArray<Command<A>>;\n readonly reply?: number | undefined;\n readonly borrowed?: Live<A> | undefined;\n}\n\nexport const start = <A, H = unknown>(): Step<A, H> => ({\n state: { _tag: \"Opening\", number: 1, serving: undefined, draining: new Map() },\n events: [[1, new Opening()]],\n commands: [{ _tag: \"Open\", number: 1, after: undefined }],\n});\n\nconst servingOf = <A, H>(state: State<A, H>) =>\n state._tag === \"Retired\" ? undefined : state.serving;\n\n/** The holds still owned for a generation, including one whose release has begun. */\nexport const lookup = <A, H>(state: State<A, H>, number: number): Held<A, H> | undefined =>\n servingOf(state)?.number === number ? servingOf(state) : state.draining.get(number)?.live;\n\n/** A transition's local result builder; input state and its collections remain immutable. */\ninterface Change<A, H> {\n readonly now: number;\n readonly handover: number;\n readonly exclusive: boolean;\n state: State<A, H>;\n events: Array<readonly [number, GenerationState]>;\n commands: Array<Command<A>>;\n reply?: number;\n borrowed?: Live<A>;\n}\n\n/** The sole writer of a drain's ending and phase; each release command is emitted once. */\nconst draining = <A, H>(change: Change<A, H>, drain: Drain<A, H>) => {\n const before = change.state.draining.get(drain.live.number);\n const { live, ending, _tag } = drain;\n\n change.state = {\n ...change.state,\n draining: new Map(change.state.draining).set(live.number, drain),\n };\n if (before?.ending !== ending) {\n change.events.push([live.number, ending]);\n change.commands.push({ _tag: \"Drain\", live, ending });\n }\n if (_tag !== \"Draining\" && before?._tag !== _tag)\n change.commands.push({ _tag: _tag === \"Leaving\" ? \"Leave\" : \"Release\", live, ending });\n};\n\nconst end = <A, H>(\n change: Change<A, H>,\n live: Held<A, H>,\n reason: Draining[\"reason\"],\n keep = false,\n) => {\n const ending = new Draining({\n reason,\n revokeAt: change.now + (reason === \"rotated\" ? change.handover : 0),\n });\n\n draining(change, {\n live,\n ending,\n _tag: keep\n ? \"Leaving\"\n : live.holds.size === 0 || ending.revokeAt <= change.now\n ? \"Releasing\"\n : \"Draining\",\n });\n};\n\nconst revoke = <A, H>(change: Change<A, H>, number: number, reason?: \"lost\" | \"retired\") => {\n const drain = change.state.draining.get(number);\n\n if (drain?._tag !== \"Draining\" || (reason === undefined && change.now < drain.ending.revokeAt))\n return;\n draining(change, {\n ...drain,\n _tag: \"Releasing\",\n ending: reason === undefined ? drain.ending : new Draining({ reason, revokeAt: change.now }),\n });\n};\n\nconst holds = <A, H>(\n change: Change<A, H>,\n input: Extract<Input<A, H>, { readonly _tag: \"Hold\" | \"Let\" }>,\n) => {\n const number = input.number ?? servingOf(change.state)?.number;\n const live = number === undefined ? undefined : lookup(change.state, number);\n\n if (live === undefined) return;\n const drain = change.state.draining.get(live.number);\n\n if (\n input._tag === \"Hold\" &&\n drain !== undefined &&\n (drain._tag !== \"Draining\" || change.now >= drain.ending.revokeAt)\n )\n return;\n if (live.holds.has(input.hold) === (input._tag === \"Hold\")) return;\n const holds = new Set(live.holds);\n\n if (input._tag === \"Hold\") {\n holds.add(input.hold);\n change.borrowed = live;\n } else holds.delete(input.hold);\n const held = { ...live, holds };\n\n if (drain !== undefined)\n draining(change, {\n ...drain,\n live: held,\n _tag: drain._tag === \"Draining\" && holds.size === 0 ? \"Releasing\" : drain._tag,\n });\n else if (change.state._tag !== \"Retired\") change.state = { ...change.state, serving: held };\n};\n\nconst next = <A, H>(change: Change<A, H>, number: number, reopen: boolean) => {\n const { exclusive } = change;\n const current = servingOf(change.state);\n\n const after = exclusive\n ? (current?.number ?? change.state.draining.keys().next().value)\n : undefined;\n\n if (current !== undefined && (reopen || exclusive))\n end(change, current, reopen ? \"lost\" : \"rotated\");\n change.state = {\n _tag: \"Opening\",\n number,\n serving: reopen || exclusive ? undefined : current,\n draining: change.state.draining,\n };\n change.events.push([number, reopen ? new Reopening() : new Opening()]);\n change.commands.push({ _tag: \"Open\", number, after });\n};\n\nconst lost = <A, H>(\n change: Change<A, H>,\n input: Extract<Input<A, H>, { readonly _tag: \"Lost\" }>,\n) => {\n const { state } = change;\n const drain = state.draining.get(input.number);\n const current = servingOf(state);\n\n if (drain?._tag === \"Draining\") {\n change.events.push([input.number, new Lost({ cause: input.cause })]);\n revoke(change, input.number, \"lost\");\n } else if (state._tag !== \"Retired\" && current?.number === input.number) {\n change.events.push([input.number, new Lost({ cause: input.cause })]);\n if (state._tag !== \"Opening\")\n next(change, (state._tag === \"Open\" ? current.number : state.number) + 1, true);\n else {\n change.state = { ...state, serving: undefined };\n end(change, current, \"lost\");\n }\n }\n};\n\n/** Pure admission and lifecycle changes. A rejected hold preserves state identity. */\nexport const transition = <A, H = unknown>(\n state: State<A, H>,\n input: Input<A, H>,\n exclusive: boolean,\n now = 0,\n handover = 30_000,\n): Step<A, H> => {\n const change: Change<A, H> = {\n state,\n events: [],\n commands: [],\n exclusive,\n handover,\n now,\n };\n\n switch (input._tag) {\n case \"Hold\":\n case \"Let\":\n holds(change, input);\n break;\n case \"Revoke\":\n revoke(change, input.number);\n break;\n case \"Opened\": {\n const live = { ...input.live, holds: new Set<H>() };\n\n if (lookup(state, live.number) !== undefined) break;\n if (state._tag !== \"Opening\" || state.number !== live.number) end(change, live, \"retired\");\n else {\n change.events.push([live.number, new Open()]);\n change.commands.push({ _tag: \"Watch\", live });\n if (state.serving !== undefined) end(change, state.serving, \"rotated\");\n change.state = { _tag: \"Open\", serving: live, draining: change.state.draining };\n }\n break;\n }\n case \"Failed\": {\n const { number, detail, cause } = input;\n\n if (state._tag === \"Opening\" && state.number === number)\n change.state = { ...state, _tag: \"Down\", detail, cause };\n change.events.push([number, new Down({ detail, cause })]);\n break;\n }\n case \"Abandoned\":\n change.events.push([input.number, new Closed({})]);\n break;\n case \"Released\": {\n const drain = state.draining.get(input.number);\n\n if (drain === undefined || drain._tag === \"Draining\" || drain.live.holds.size > 0) break;\n const draining = new Map(state.draining);\n\n draining.delete(input.number);\n change.state = { ...state, draining };\n change.events.push([\n input.number,\n input.released === undefined ? new Kept() : new Closed({ released: input.released }),\n ]);\n break;\n }\n case \"Lost\":\n lost(change, input);\n break;\n case \"Rotate\": {\n if (\n state._tag === \"Retired\" ||\n (input.due !== undefined && (state._tag !== \"Open\" || state.serving.number !== input.due))\n )\n break;\n change.reply =\n state._tag === \"Opening\"\n ? state.number\n : (state._tag === \"Open\" ? state.serving.number : state.number) + 1;\n if (state._tag !== \"Opening\") next(change, change.reply, false);\n break;\n }\n case \"Keep\":\n case \"Retire\":\n if (state._tag === \"Retired\") break;\n for (const number of state.draining.keys()) revoke(change, number, \"retired\");\n if (state.serving !== undefined) end(change, state.serving, \"retired\", input._tag === \"Keep\");\n change.state = { _tag: \"Retired\", draining: change.state.draining };\n }\n\n return change;\n};\n\nexport type Resolution<A> =\n | { readonly _tag: \"Serve\"; readonly live: Live<A> }\n | {\n readonly _tag: \"Unavailable\";\n readonly reason: \"down\" | \"retired\";\n readonly detail: string;\n readonly cause?: unknown;\n };\n\n/** An unheld browser resolution; use obtains its hold atomically through Hold instead. */\nexport const resolve = <A, H>(\n state: State<A, H>,\n target: number | undefined,\n): Resolution<A> | undefined => {\n if (state._tag === \"Retired\")\n return { _tag: \"Unavailable\", reason: \"retired\", detail: \"the supervisor was retired\" };\n if (\n state.serving !== undefined &&\n (target === undefined || (state._tag === \"Open\" && state.serving.number >= target))\n )\n return { _tag: \"Serve\", live: state.serving };\n if (state._tag === \"Down\" && (target === undefined || state.number >= target))\n return { _tag: \"Unavailable\", reason: \"down\", detail: state.detail, cause: state.cause };\n\n return undefined;\n};\n","/**\n * A browser kept open across losses and session ends, as a series of generations, each a new\n * browser from the same provider. Pages don't carry over from one generation to the next.\n *\n * `make` opens the first generation at once with the provider's `open`, in a scope of its own, so\n * a caller that stops waiting never interrupts a half-open browser. `browser` gives the current\n * generation; callers wait, bounded, and share one open. A loss is published at once and the next\n * generation opens on the `reopen` schedule, which also retries a failed open, unless the provider\n * deems its failure `definite`: that goes `Down` at once, with its cause. `rotate` opens the\n * next generation now, and so does the time `rotateBefore` ahead of a generation's `expiresAt`. A\n * rotation makes the next generation before it breaks the current one, unless generations are\n * `exclusive`, as sessions saving to one stored context must be: then the current one is released\n * first. `retire` stops reopening at once and releases what is open; the scope's close retires\n * too, unless the supervisor `keep`s: then it leaves the serving generation running, `Kept`. `states`\n * publishes each generation's changes, with the provider's release outcome last.\n *\n * Providers supply the specifics: `Browserbase.supervise` opens hosted sessions this way.\n *\n * @since 0.3.0\n */\nimport {\n Cause,\n Clock,\n DateTime,\n Deferred,\n Duration,\n Effect,\n Exit,\n FiberHandle,\n FiberMap,\n Option,\n Predicate,\n PubSub,\n Schedule,\n Schema,\n Scope,\n Semaphore,\n Stream,\n SubscriptionRef,\n type Take,\n} from \"effect\";\n\nimport type * as Browser from \"./Browser.ts\";\nimport * as Lifecycle from \"./internal/supervisor/lifecycle.ts\";\n\nexport {\n Closed,\n Down,\n Draining,\n GenerationState,\n Kept,\n Lost,\n Open,\n Opening,\n Released,\n Reopening,\n Settled,\n Unconfirmed,\n} from \"./internal/supervisor/lifecycle.ts\";\n\n/** One change in a generation's life. `at` is wall-clock epoch milliseconds from the Effect `Clock`. */\nexport class Generation extends Schema.Class<Generation>(\"effect-browser/Generation\")({\n number: Schema.Int.check(Schema.isGreaterThan(0)),\n at: Schema.Finite,\n hostTime: Schema.Finite,\n state: Lifecycle.GenerationState,\n}) {}\n\n/**\n * No browser to give: none opened within `waitTimeout` (`opening`), the latest generation failed\n * to open (`down`, with what it failed with as `cause`), or the supervisor was retired.\n */\nexport class Unavailable extends Schema.TaggedError<Unavailable>()(\"Unavailable\", {\n reason: Schema.Literals([\"opening\", \"down\", \"retired\"]),\n detail: Schema.String,\n cause: Schema.optional(Schema.Defect()),\n}) {\n override get message() {\n return `no browser: ${this.detail}`;\n }\n}\n\n/** One generation, as a provider opened it in the scope the supervisor gave it. */\nexport interface Opened<A = void> {\n readonly value: A;\n readonly browser: Browser.Service;\n /**\n * End the generation, and say whether the provider confirmed its end. The supervisor asks it\n * before it closes the generation's scope; without it, closing the scope ends the generation,\n * which counts as `Settled`.\n */\n readonly release?: Effect.Effect<Lifecycle.Released> | undefined;\n}\n\nexport interface Options<E, R, A = void> {\n /** Opens one generation in the scope it is given. */\n readonly open: Effect.Effect<Opened<A>, E, R>;\n /** When to try a failed open again. Defaults to exponential from 1 second, for 5 minutes. */\n readonly reopen?: Schedule.Schedule<unknown, E> | undefined;\n /**\n * Failures no new try mends, such as a refused key: an open that fails so is `Down` at once.\n * Defaults to none.\n */\n readonly definite?: ((error: E) => boolean) | undefined;\n /**\n * Rotate this long ahead of a generation's `expiresAt`, but no sooner than halfway through its\n * life. Without it, a generation's end is a loss.\n */\n readonly rotateBefore?: Duration.Input | undefined;\n /** Generations must not overlap: a rotation releases the current one before it opens the next. */\n readonly exclusive?: boolean | undefined;\n /** Finite, nonnegative time outgoing holds may finish; defaults to 30 seconds. */\n readonly handover?: Duration.Input | undefined;\n /**\n * Closing the scope leaves the serving generation running, `Kept`: it closes the generation's\n * scope but never asks `release`. For providers whose scope only disconnects, such as\n * `Browserbase.supervise` with `keep`. `retire` still releases it.\n */\n readonly keep?: boolean | undefined;\n /** How long `browser` and `rotate` wait for a generation to open. Defaults to 2 minutes. */\n readonly waitTimeout?: Duration.Input | undefined;\n}\n\n/** Work whose generation was revoked; input receipts still determine whether input reached a site. */\nexport class Superseded extends Schema.TaggedError<Superseded>()(\"Superseded\", {\n generation: Schema.Int,\n reason: Schema.Literals([\"rotated\", \"lost\", \"retired\"]),\n revokeAt: Schema.Finite,\n}) {}\n\nexport interface Lease<A> {\n readonly generation: number;\n readonly browser: Browser.Service;\n readonly value: A;\n /** First notice that serving ended; loss or retirement may revoke before its deadline. */\n readonly ending: Effect.Effect<Superseded>;\n /** An independent scope; its resources close before provider release. Fails once revoked. */\n readonly retain: Effect.Effect<Scope.Closeable, Superseded>;\n}\n\nexport interface UseOptions {\n /** Finite, nonnegative wait for a serving generation. Zero makes an immediate attempt. */\n readonly wait?: Duration.Input | undefined;\n}\n\nexport interface Supervisor<A = void> {\n /** Scoped work on the current generation. Revocation interrupts it and waits for its cleanup. */\n readonly use: <B, E, R>(\n work: (lease: Lease<A>) => Effect.Effect<B, E, R>,\n options?: UseOptions,\n ) => Effect.Effect<B, E | Unavailable | Superseded, Exclude<R, Scope.Scope>>;\n /** The current generation's browser, waiting up to `waitTimeout` while none is open. */\n readonly browser: Effect.Effect<Browser.Service, Unavailable>;\n /** Each generation's changes, in order. A new reader first gets the latest 64; ends on retiring. */\n readonly states: Stream.Stream<Generation>;\n /** Open the next generation now, or join the one opening, and wait for it. */\n readonly rotate: Effect.Effect<Browser.Service, Unavailable>;\n /** Stop opening at once, release every generation, and wait until each release has finished. */\n readonly retire: Effect.Effect<void>;\n}\n\ntype Hold =\n | { readonly _tag: \"Use\" }\n | { readonly _tag: \"Retained\"; readonly scope: Scope.Closeable };\n\ninterface Held<A> {\n readonly opened: Opened<A>;\n readonly ending: Deferred.Deferred<Superseded>;\n readonly revoked: Deferred.Deferred<Superseded>;\n readonly scope: Scope.Closeable;\n}\n\ntype State<A> = Lifecycle.State<Held<A>, Hold>;\ntype Apply<A> = (\n input: Lifecycle.Input<Held<A>, Hold>,\n) => Effect.Effect<Lifecycle.Step<Held<A>, Hold>>;\n\nconst retired = () => new Unavailable({ reason: \"retired\", detail: \"the supervisor was retired\" });\n\nconst describe = (cause: Cause.Cause<unknown>) => {\n const error = Cause.squash(cause);\n\n return Predicate.isError(error) ? error.message : String(error);\n};\n\nconst unavailable = (\n resolution: Extract<Lifecycle.Resolution<unknown>, { readonly _tag: \"Unavailable\" }>,\n) =>\n new Unavailable({\n reason: resolution.reason,\n detail: resolution.detail,\n cause: resolution.cause,\n });\n\nconst timedOut = () =>\n new Unavailable({ reason: \"opening\", detail: \"no generation opened within the wait\" });\n\nconst bounded = (input: Duration.Input, name: string) =>\n Effect.suspend(() => {\n const duration = Duration.fromInput(input);\n\n return Option.isSome(duration) &&\n Duration.isFinite(duration.value) &&\n !Duration.isNegative(duration.value)\n ? Effect.succeed(duration.value)\n : Effect.die(new RangeError(`${name} must be a finite nonnegative duration`));\n });\n\n/** Resolve immediately before starting a bounded wait, including when its duration is zero. */\nconst waitFor = <A, H>(\n state: SubscriptionRef.SubscriptionRef<Lifecycle.State<A, H>>,\n wait: Duration.Duration,\n clock: Clock.Clock,\n target?: number,\n) => {\n const result = (resolution: Lifecycle.Resolution<A>) =>\n resolution._tag === \"Serve\"\n ? Effect.succeed(resolution.live)\n : Effect.fail(unavailable(resolution));\n\n return Effect.suspend(() => {\n const current = Lifecycle.resolve(state.value, target);\n\n return current === undefined\n ? SubscriptionRef.changes(state).pipe(\n Stream.map((state) => Lifecycle.resolve(state, target)),\n Stream.filter(Predicate.isNotUndefined),\n Stream.runHead,\n Effect.flatMap(Option.match({ onNone: () => Effect.fail(retired()), onSome: result })),\n Effect.timeoutOrElse({ duration: wait, orElse: () => Effect.fail(timedOut()) }),\n )\n : result(current);\n }).pipe(Effect.provideService(Clock.Clock, clock));\n};\n\n/** Sleep until `before` ahead of `expiresAt`, but no sooner than halfway there from now. */\nconst untilRotation = (expiresAt: DateTime.Utc, before: Duration.Duration) =>\n Clock.currentTimeMillis.pipe(\n Effect.flatMap((now) => {\n const left = DateTime.toEpochMillis(expiresAt) - now;\n\n return Effect.sleep(Duration.millis(Math.max(left - Duration.toMillis(before), left / 2, 0)));\n }),\n );\n\n/** Native timers may wake a fraction early; a revocation must reach its monotonic deadline. */\nconst until = (at: number, now: () => number): Effect.Effect<void> =>\n Effect.suspend(() =>\n now() >= at\n ? Effect.void\n : Effect.sleep(Duration.millis(Math.ceil(at - now()))).pipe(Effect.andThen(until(at, now))),\n );\n\n/** Borrowed work and transferred scopes hold a generation until cleanup lets it go. */\nconst leasing = <A>(\n state: SubscriptionRef.SubscriptionRef<State<A>>,\n apply: Apply<A>,\n waitTimeout: Duration.Duration,\n now: () => number,\n clock: Clock.Clock,\n) => {\n const borrow = (hold: Hold, wait: Duration.Duration) =>\n Effect.gen(function* () {\n const until = now() + Duration.toMillis(wait);\n\n for (;;) {\n const step = yield* apply({ _tag: \"Hold\", hold });\n\n if (step.borrowed !== undefined) return step.borrowed;\n yield* waitFor(state, Duration.millis(Math.max(0, until - now())), clock).pipe(\n Effect.interruptible,\n );\n if (now() >= until) return yield* timedOut();\n }\n });\n\n const leaseOf = (live: Lifecycle.Live<Held<A>>): Lease<A> => ({\n generation: live.number,\n browser: live.value.opened.browser,\n value: live.value.opened.value,\n ending: Deferred.await(live.value.ending),\n retain: Effect.uninterruptible(\n Effect.gen(function* () {\n const scope = yield* Scope.make();\n const hold: Hold = { _tag: \"Retained\", scope };\n const step = yield* apply({ _tag: \"Hold\", number: live.number, hold });\n\n if (step.borrowed === undefined) {\n yield* Scope.close(scope, Exit.void);\n\n return yield* yield* Deferred.await(live.value.ending);\n }\n yield* Scope.addFinalizer(\n scope,\n apply({ _tag: \"Let\", number: live.number, hold }).pipe(Effect.asVoid),\n );\n\n return scope;\n }),\n ),\n });\n\n const use: Supervisor<A>[\"use\"] = (work, options = {}) =>\n Effect.scoped(\n Effect.gen(function* () {\n const hold: Hold = { _tag: \"Use\" };\n const wait = yield* bounded(options.wait ?? waitTimeout, \"wait\");\n\n const live = yield* Effect.acquireRelease(borrow(hold, wait), (live) =>\n apply({ _tag: \"Let\", number: live.number, hold }).pipe(Effect.asVoid),\n );\n\n return yield* Effect.raceFirst(\n work(leaseOf(live)),\n Deferred.await(live.value.revoked).pipe(Effect.flatMap(Effect.fail)),\n );\n }),\n );\n\n return use;\n};\n\ntype Provider = Omit<Opened, \"value\">;\ntype MakeOptions<E, R, A> = Omit<Options<E, R, A>, \"open\"> & {\n readonly open: Effect.Effect<Opened<A> | Provider, E, R>;\n};\n\nconst acquireGeneration = <A, E, R>(\n open: Effect.Effect<Opened<A> | Provider, E, R>,\n own: Scope.Scope,\n) =>\n Effect.uninterruptibleMask((restore) =>\n Effect.flatMap(Scope.fork(own), (scope) =>\n restore(open.pipe(Scope.provide(scope))).pipe(\n Effect.onError((cause) => Scope.close(scope, Exit.failCause(cause))),\n Effect.map((opened): Held<A | void> => ({\n opened: { ...opened, value: \"value\" in opened ? opened.value : undefined },\n scope,\n ending: Deferred.makeUnsafe<Superseded>(),\n revoked: Deferred.makeUnsafe<Superseded>(),\n })),\n ),\n ),\n );\n\nconst changedUntil = <A>(\n state: SubscriptionRef.SubscriptionRef<State<A>>,\n predicate: (current: State<A>) => boolean,\n) => SubscriptionRef.changes(state).pipe(Stream.filter(predicate), Stream.runHead, Effect.asVoid);\n\nconst watchGeneration = <A>(\n live: Lifecycle.Live<Held<A>>,\n rotateBefore: Duration.Duration | undefined,\n apply: Apply<A>,\n) => {\n const { browser } = live.value.opened;\n\n const loss = browser.disconnected.pipe(\n Effect.flatMap((cause) => apply({ _tag: \"Lost\", number: live.number, cause })),\n );\n\n const rotation =\n browser.expiresAt === undefined || rotateBefore === undefined\n ? Effect.void\n : untilRotation(browser.expiresAt, rotateBefore).pipe(\n Effect.andThen(apply({ _tag: \"Rotate\", due: live.number })),\n );\n\n return Effect.all([loss, rotation], { concurrency: 2, discard: true });\n};\n\n// Revocation stops use work; retained resources and use finalizers let go before the provider.\nconst releaseGeneration = <A>(\n command: Extract<Lifecycle.Command<Held<A>>, { readonly _tag: \"Release\" | \"Leave\" }>,\n state: SubscriptionRef.SubscriptionRef<State<A>>,\n apply: Apply<A>,\n) =>\n Effect.gen(function* () {\n const { live, ending } = command;\n\n yield* Deferred.succeed(\n live.value.revoked,\n new Superseded({\n generation: live.number,\n reason: ending.reason,\n revokeAt: ending.revokeAt,\n }),\n );\n const holds = Lifecycle.lookup(state.value, live.number)?.holds ?? [];\n\n const cleaned = yield* Effect.forEach(\n holds,\n (hold) =>\n Effect.exit(hold._tag === \"Retained\" ? Scope.close(hold.scope, Exit.void) : Effect.void),\n { concurrency: 8 },\n );\n\n yield* changedUntil(\n state,\n (current) => (Lifecycle.lookup(current, live.number)?.holds.size ?? 0) === 0,\n );\n\n const released =\n command._tag === \"Leave\"\n ? undefined\n : yield* (live.value.opened.release ?? Effect.succeed(new Lifecycle.Settled())).pipe(\n Effect.catchCause((cause) =>\n Effect.succeed(\n new Lifecycle.Unconfirmed({ detail: `the release failed: ${describe(cause)}` }),\n ),\n ),\n );\n\n const closed = yield* Effect.exit(Scope.close(live.value.scope, Exit.void));\n\n yield* apply({ _tag: \"Released\", number: live.number, released });\n yield* Exit.asVoidAll([...cleaned, closed]);\n });\n\nconst makeScoped = Effect.fn(\"Supervisor.make\")(function* <E, R, A>(\n options: MakeOptions<E, R, A>,\n): Effect.fn.Return<Supervisor<A | void>, never, Scope.Scope | Exclude<R, Scope.Scope>> {\n const clock = yield* Clock.Clock;\n const now = () => Number(clock.monotonicTimeNanosUnsafe()) / 1e6;\n const context = yield* Effect.context<Exclude<R, Scope.Scope>>();\n const own = yield* Scope.fork(yield* Effect.scope);\n const exclusive = options.exclusive ?? false;\n const definite = options.definite ?? (() => false);\n\n const reopen: Schedule.Schedule<unknown, E> =\n options.reopen ??\n Schedule.exponential(\"1 second\").pipe(Schedule.upTo({ duration: Duration.minutes(5) }));\n\n const rotateBefore =\n options.rotateBefore === undefined ? undefined : Duration.fromInputUnsafe(options.rotateBefore);\n\n const waitTimeout = yield* bounded(options.waitTimeout ?? Duration.minutes(2), \"waitTimeout\");\n\n const handover = Duration.toMillis(\n yield* bounded(options.handover ?? Duration.seconds(30), \"handover\"),\n );\n\n const started = Lifecycle.start<Held<A | void>, Hold>();\n const state = yield* SubscriptionRef.make(started.state);\n const applying = yield* Semaphore.make(1);\n const events = yield* PubSub.unbounded<Take.Take<Generation>>({ replay: 64 });\n const opening = yield* FiberHandle.make<unknown, never>();\n const releases = yield* FiberMap.make<number, unknown, never>();\n const runOpen = yield* FiberHandle.runtime(opening)();\n const runRelease = yield* FiberMap.runtime(releases)();\n\n const apply = (\n input: Lifecycle.Input<Held<A | void>, Hold>,\n ): Effect.Effect<Lifecycle.Step<Held<A | void>, Hold>> =>\n applying\n .withPermit(\n Effect.gen(function* () {\n const current = state.value;\n const step = Lifecycle.transition(current, input, exclusive, now(), handover);\n\n if (step.state !== current) yield* SubscriptionRef.set(state, step.state);\n yield* perform(step);\n\n return step;\n }),\n )\n .pipe(Effect.uninterruptible, Effect.provideService(Clock.Clock, clock));\n\n const perform = (step: Lifecycle.Step<Held<A | void>, Hold>): Effect.Effect<void> =>\n Effect.gen(function* () {\n for (const [number, generation] of step.events)\n PubSub.publishUnsafe(events, [\n new Generation({\n number,\n at: clock.currentTimeMillisUnsafe(),\n hostTime: now(),\n state: generation,\n }),\n ]);\n for (const command of step.commands)\n switch (command._tag) {\n case \"Open\":\n runOpen(openGeneration(command.number, command.after));\n break;\n case \"Watch\":\n yield* Effect.forkIn(\n Effect.provideContext(watchGeneration(command.live, rotateBefore, apply), context),\n command.live.value.scope,\n );\n break;\n case \"Drain\": {\n const ending = new Superseded({\n generation: command.live.number,\n reason: command.ending.reason,\n revokeAt: command.ending.revokeAt,\n });\n\n yield* Deferred.succeed(command.live.value.ending, ending);\n yield* Effect.forkIn(\n until(ending.revokeAt, now).pipe(\n Effect.andThen(\n Effect.suspend(() => apply({ _tag: \"Revoke\", number: command.live.number })),\n ),\n ),\n command.live.value.scope,\n );\n break;\n }\n case \"Release\":\n case \"Leave\":\n runRelease(command.live.number, releaseGeneration(command, state, apply));\n break;\n }\n });\n\n const openOnce = acquireGeneration(options.open, own).pipe(Effect.provideContext(context));\n\n const openGeneration = (number: number, after: number | undefined) =>\n Effect.uninterruptibleMask((restore) =>\n restore(\n (after === undefined\n ? Effect.void\n : changedUntil(state, (current) => !current.draining.has(after))\n ).pipe(\n Effect.andThen(\n Effect.retry(openOnce, { schedule: reopen, while: (error) => !definite(error) }),\n ),\n ),\n ).pipe(\n Effect.exit,\n Effect.flatMap((exit) =>\n Exit.isSuccess(exit)\n ? apply({ _tag: \"Opened\", live: { number, value: exit.value } })\n : Cause.hasInterruptsOnly(exit.cause)\n ? apply({ _tag: \"Abandoned\", number })\n : apply({\n _tag: \"Failed\",\n number,\n detail: describe(exit.cause),\n cause: Cause.squash(exit.cause),\n }),\n ),\n ),\n );\n\n const use = leasing(state, apply, waitTimeout, now, clock);\n\n const end = yield* Effect.cached(PubSub.publish(events, Exit.void));\n\n const stop = (input: Lifecycle.Input<Held<A | void>, Hold>) =>\n apply(input).pipe(\n Effect.andThen(FiberHandle.clear(opening)),\n Effect.andThen(FiberMap.awaitEmpty(releases)),\n Effect.andThen(\n Effect.suspend(() =>\n Deferred.isDone(releases.deferred).pipe(\n Effect.flatMap((failed) => (failed ? FiberMap.join(releases) : Effect.void)),\n ),\n ),\n ),\n Effect.ensuring(end),\n Effect.asVoid,\n );\n\n const retire = yield* Effect.cached(stop({ _tag: \"Retire\" }));\n\n yield* Effect.addFinalizer(() => (options.keep === true ? stop({ _tag: \"Keep\" }) : retire));\n yield* perform(started);\n\n return {\n browser: Effect.map(waitFor(state, waitTimeout, clock), (live) => live.value.opened.browser),\n use,\n states: Stream.fromPubSubTake(events),\n rotate: apply({ _tag: \"Rotate\" }).pipe(\n Effect.flatMap(({ reply }) =>\n reply === undefined\n ? Effect.fail(retired())\n : Effect.map(\n waitFor(state, waitTimeout, clock, reply),\n (live) => live.value.opened.browser,\n ),\n ),\n ),\n retire,\n };\n});\n\n/** Supervise scoped generation values. Browser-only providers retain their existing void value. */\nexport function make<E, R, A = void>(\n options: Options<E, R, A>,\n): Effect.Effect<Supervisor<A>, never, Scope.Scope | Exclude<R, Scope.Scope>>;\n\nexport function make<E, R>(\n options: MakeOptions<E, R, never>,\n): Effect.Effect<Supervisor<void>, never, Scope.Scope | Exclude<R, Scope.Scope>>;\n\nexport function make<E, R, A>(options: MakeOptions<E, R, A>) {\n return makeScoped(options);\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,UAAb,cAA6B,OAAO,YAAqB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;;AAG3E,IAAa,cAAb,cAAiC,OAAO,YAAyB,CAAC,CAAC,eAAe,EAChF,QAAQ,OAAO,OACjB,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAa,WAAW,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;CACF;AACF,CAAC;AAWD,SAAgB,KAAc,SAA+B;CAC3D,OAAO,WAAW,OAAO;AAC3B"}
@@ -1,2 +1,2 @@
1
- import { _ as Settled, c as Closed, d as Kept, f as Lost, g as Reopening, h as Released, i as Supervisor, l as Down, m as Opening, n as Opened, o as Unavailable, p as Open, r as Options, s as make, t as Generation, u as GenerationState, v as Unconfirmed } from "./Supervisor-Im6-wbg5.mjs";
2
- export { Closed, Down, Generation, GenerationState, Kept, Lost, Open, Opened, Opening, Options, Released, Reopening, Settled, Supervisor, Unavailable, Unconfirmed, make };
1
+ import { S as Unconfirmed, _ as Open, a as Superseded, b as Reopening, c as Unavailable, d as Closed, f as Down, g as Lost, h as Kept, i as Options, l as UseOptions, m as GenerationState, n as Lease, o as Supervisor, p as Draining, r as Opened, t as Generation, u as make, v as Opening, x as Settled, y as Released } from "./Supervisor-CYWFK3vM.mjs";
2
+ export { Closed, Down, Draining, Generation, GenerationState, Kept, Lease, Lost, Open, Opened, Opening, Options, Released, Reopening, Settled, Superseded, Supervisor, Unavailable, Unconfirmed, UseOptions, make };
@@ -1,2 +1,2 @@
1
- import { a as Closed, c as Kept, d as Opening, f as Released, h as Unconfirmed, i as make, l as Lost, m as Settled, o as Down, p as Reopening, r as Unavailable, s as GenerationState, t as Generation, u as Open } from "./Supervisor-BtEG93gR.mjs";
2
- export { Closed, Down, Generation, GenerationState, Kept, Lost, Open, Opening, Released, Reopening, Settled, Unavailable, Unconfirmed, make };
1
+ import { _ as Unconfirmed, a as make, c as Draining, d as Lost, f as Open, g as Settled, h as Reopening, i as Unavailable, l as GenerationState, m as Released, n as Superseded, o as Closed, p as Opening, s as Down, t as Generation, u as Kept } from "./Supervisor-TNKNOVzu.mjs";
2
+ export { Closed, Down, Draining, Generation, GenerationState, Kept, Lost, Open, Opening, Released, Reopening, Settled, Superseded, Unavailable, Unconfirmed, make };
package/dist/index.d.mts CHANGED
@@ -1,17 +1,17 @@
1
1
  import { n as BrowserError_d_exports } from "./BrowserError-DXXIA6Rk.mjs";
2
- import { a as BrowserEvent_d_exports } from "./BrowserEvent-DzdNdvoh.mjs";
3
- import { n as Change_d_exports } from "./Change-DVP2IJWm.mjs";
2
+ import { a as BrowserEvent_d_exports } from "./BrowserEvent-BRu2juEz.mjs";
3
+ import { n as Change_d_exports } from "./Change-iMlcuzVD.mjs";
4
4
  import { i as Frame_d_exports } from "./Frame-BERmf_gM.mjs";
5
5
  import { i as Snapshot_d_exports } from "./Snapshot-B34hZ4Jl.mjs";
6
- import { N as Moment_d_exports, d as Page_d_exports } from "./Page-DYTdVhYa.mjs";
6
+ import { N as Moment_d_exports, d as Page_d_exports } from "./Page-C30aG2RQ.mjs";
7
7
  import { t as Browser_d_exports } from "./Browser.mjs";
8
8
  import { t as Cdp_d_exports } from "./Cdp.mjs";
9
9
  import { t as Chromium_d_exports } from "./Chromium.mjs";
10
10
  import { t as Expect_d_exports } from "./Expect.mjs";
11
11
  import { t as Motion_d_exports } from "./Motion.mjs";
12
- import { n as Plan_d_exports } from "./Plan-CNNOU1Tx.mjs";
12
+ import { r as Plan_d_exports } from "./Plan-BvCS9qAf.mjs";
13
13
  import { t as Policy_d_exports } from "./Policy.mjs";
14
14
  import { t as Presentation_d_exports } from "./Presentation.mjs";
15
15
  import { t as Stage_d_exports } from "./Stage.mjs";
16
- import { a as Supervisor_d_exports } from "./Supervisor-Im6-wbg5.mjs";
16
+ import { s as Supervisor_d_exports } from "./Supervisor-CYWFK3vM.mjs";
17
17
  export { Browser_d_exports as Browser, BrowserError_d_exports as BrowserError, BrowserEvent_d_exports as BrowserEvent, Cdp_d_exports as Cdp, Change_d_exports as Change, Chromium_d_exports as Chromium, Expect_d_exports as Expect, Frame_d_exports as Frame, Moment_d_exports as Moment, Motion_d_exports as Motion, Page_d_exports as Page, Plan_d_exports as Plan, Policy_d_exports as Policy, Presentation_d_exports as Presentation, Snapshot_d_exports as Snapshot, Stage_d_exports as Stage, Supervisor_d_exports as Supervisor };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as Motion_exports } from "./Motion.mjs";
2
2
  import { t as BrowserEvent_exports } from "./BrowserEvent.mjs";
3
3
  import { t as BrowserError_exports } from "./BrowserError.mjs";
4
- import { n as Browser_exports } from "./Browser-B5AV7zPS.mjs";
4
+ import { n as Browser_exports } from "./Browser-CNwK0r0q.mjs";
5
5
  import { t as Frame_exports } from "./Frame.mjs";
6
6
  import { a as Page_exports } from "./Page-D4281dIi.mjs";
7
7
  import { t as Snapshot_exports } from "./Snapshot.mjs";
@@ -10,9 +10,9 @@ import { t as Moment_exports } from "./Moment.mjs";
10
10
  import { t as Cdp_exports } from "./Cdp.mjs";
11
11
  import { t as Chromium_exports } from "./Chromium.mjs";
12
12
  import { t as Expect_exports } from "./Expect.mjs";
13
- import { n as Plan_exports } from "./Plan-5MdsRzE5.mjs";
13
+ import { r as Plan_exports } from "./Plan-CyQNv49C.mjs";
14
14
  import { t as Policy_exports } from "./Policy.mjs";
15
15
  import { t as Presentation_exports } from "./Presentation.mjs";
16
16
  import { t as Stage_exports } from "./Stage.mjs";
17
- import { n as Supervisor_exports } from "./Supervisor-BtEG93gR.mjs";
17
+ import { r as Supervisor_exports } from "./Supervisor-TNKNOVzu.mjs";
18
18
  export { Browser_exports as Browser, BrowserError_exports as BrowserError, BrowserEvent_exports as BrowserEvent, Cdp_exports as Cdp, Change_exports as Change, Chromium_exports as Chromium, Expect_exports as Expect, Frame_exports as Frame, Moment_exports as Moment, Motion_exports as Motion, Page_exports as Page, Plan_exports as Plan, Policy_exports as Policy, Presentation_exports as Presentation, Snapshot_exports as Snapshot, Stage_exports as Stage, Supervisor_exports as Supervisor };
@@ -956,8 +956,9 @@ const ViewportResultSchema = Schema.Struct({
956
956
  * frame. So a canvas mounted blank, or a spinner alone, is still loading. A screen that only says
957
957
  * "Loading…" in words reads as ready, and a WebGL canvas drawn once, without keeping its drawing,
958
958
  * reads as blank. Asked for a quiet spell, where the page's changes are recorded, nothing in view
959
- * may have changed for that long either. After input, it waits a task and a frame. See
960
- * `names.inpage.ts` for what a page-side part may use.
959
+ * may have changed for that long either. Content mode starts and refreshes the recorder and
960
+ * observes a full quiet interval from its first check in each document. After input, it waits a
961
+ * task and a frame. See `names.inpage.ts` for what a page-side part may use.
961
962
  */
962
963
  /** What the page is still waiting for; none when it is ready. */
963
964
  const ReadinessSchema = Schema.Array(Schema.Literals([
@@ -970,7 +971,7 @@ const ReadinessSchema = Schema.Array(Schema.Literals([
970
971
  "content",
971
972
  "changing"
972
973
  ]));
973
- const ready = (walked, texts, kept) => {
974
+ const ready = (walked, texts, kept, recorder) => {
974
975
  const { inView, visible } = walked;
975
976
  let copy;
976
977
  const boxed = (element) => {
@@ -1004,7 +1005,7 @@ const ready = (walked, texts, kept) => {
1004
1005
  else requestAnimationFrame(() => resolve(true));
1005
1006
  return promise;
1006
1007
  };
1007
- const check = (quietMillis) => painted().then((paints) => {
1008
+ const check = (quietMillis, observed) => painted().then((paints) => {
1008
1009
  const waiting = [];
1009
1010
  if (document.readyState === "loading") waiting.push("load");
1010
1011
  if (!paints) waiting.push("paint");
@@ -1016,17 +1017,22 @@ const ready = (walked, texts, kept) => {
1016
1017
  if (document.fonts.status !== "loaded") waiting.push("fonts");
1017
1018
  if (showing(document.querySelectorAll("[aria-busy=true]")).length > 0) waiting.push("busy");
1018
1019
  if (!content()) waiting.push("content");
1019
- if (kept.changing() > performance.timeOrigin + performance.now() - quietMillis) waiting.push("changing");
1020
+ if (Math.max(observed, kept.changing()) > performance.timeOrigin + performance.now() - quietMillis) waiting.push("changing");
1020
1021
  return waiting;
1021
1022
  });
1022
1023
  /**
1023
1024
  * Check until the page is ready, or for `millis`, and say what it is still waiting for; with
1024
1025
  * `quietMillis`, until nothing the record saw in view has changed for that long, too.
1025
1026
  */
1026
- const wait = async (millis, quietMillis = 0) => {
1027
+ const wait = async (millis, quietMillis = 0, contentOnly = false) => {
1027
1028
  const until = performance.now() + millis;
1029
+ let observed = contentOnly ? void 0 : Number.NEGATIVE_INFINITY;
1028
1030
  for (;;) {
1029
- const waiting = await check(quietMillis);
1031
+ if (contentOnly) {
1032
+ recorder.start();
1033
+ if (kept.begun()) observed ??= performance.timeOrigin + performance.now();
1034
+ }
1035
+ const waiting = await check(quietMillis, observed ?? Number.POSITIVE_INFINITY);
1030
1036
  if (waiting.length === 0 || performance.now() >= until) return waiting;
1031
1037
  const { promise, resolve } = Promise.withResolvers();
1032
1038
  setTimeout(resolve, Math.min(50, until - performance.now()));
@@ -2060,7 +2066,7 @@ const sight = (names, walked, texts, kept) => {
2060
2066
  */
2061
2067
  const install = (makeNames, makeWalk, makeMatch, makeContext, makeSubjects, makeExpectations, makeText, makeControls, makeFold, makeHistory, makeSight, makeMarks, makeRecord, makeChanges, makeReady, makeOutline, makeTargets, makeEvidence, makeGuard, makeEdit, makeAddresses) => {
2062
2068
  const installed = globalThis.__effectBrowser;
2063
- if (installed !== void 0 && installed.version === 18) return installed;
2069
+ if (installed !== void 0 && installed.version === 19) return installed;
2064
2070
  const named = makeNames();
2065
2071
  const walked = makeWalk(named);
2066
2072
  const placing = makeContext(named, walked);
@@ -2075,9 +2081,9 @@ const install = (makeNames, makeWalk, makeMatch, makeContext, makeSubjects, make
2075
2081
  const located = makeTargets(named, walked, placing);
2076
2082
  const guarded = makeGuard(named, located, makeEvidence(named, placing));
2077
2083
  const edited = makeEdit(named, guarded, placing);
2078
- const readiness = makeReady(walked, texts, kept);
2084
+ const readiness = makeReady(walked, texts, kept, recorder);
2079
2085
  const api = {
2080
- version: 18,
2086
+ version: 19,
2081
2087
  snapshot: read.snapshot,
2082
2088
  find: subjected.find,
2083
2089
  until: makeExpectations(named, subjected).until,
@@ -3074,6 +3080,7 @@ const make$13 = (page, sender) => {
3074
3080
  startedAt,
3075
3081
  page: id,
3076
3082
  name,
3083
+ url: redact(page.playwright.url()),
3077
3084
  correlation: yield* Correlation,
3078
3085
  target: info.target,
3079
3086
  options: Exit.isSuccess(exit) ? info.options : void 0,
@@ -4729,11 +4736,16 @@ const make$6 = Effect.fnUntraced(function* (page, bridge) {
4729
4736
  * connection of its own, a round trip there: each answer comes behind every frame sent before it on
4730
4737
  * its connection, and a frame that arrives first starts the spell again. Where the page's changes
4731
4738
  * are recorded, its evidence includes them: nothing in view may have changed for the spell, which a
4732
- * DOM page's changes show better than its paint, and no stall on the way can hide.
4739
+ * DOM page's changes show better than its paint, and no stall on the way can hide. Content
4740
+ * stillness starts that record itself and ignores capture silence. Each new document starts a
4741
+ * new observation, while retries of destroyed script contexts share the caller's deadline.
4733
4742
  */
4734
4743
  const make$5 = (page, bridge, capture) => (options = {}) => {
4735
4744
  const timeout = options.timeout ?? Duration.seconds(15);
4736
- const settled = (until) => Effect.suspend(() => bridge.evaluate("ready", scriptCall("ready", Math.max(0, Math.round(until - page.now())), options.quietMillis ?? 0))).pipe(Effect.flatMap(decodeWith("ready", ReadinessSchema)), Effect.tap((waiting) => Effect.annotateCurrentSpan({ waiting: waiting.join(",") })), Effect.filterOrElse((waiting) => waiting.length === 0, () => failWith("ready", new Timeout({ millis: Duration.toMillis(timeout) }))));
4745
+ const settled = (until) => Effect.suspend(() => bridge.evaluate("ready", scriptCall("ready", Math.max(0, Math.round(until - page.now())), options.quietMillis ?? 0, options.still === "content"))).pipe(Effect.retry({
4746
+ while: contextGone,
4747
+ schedule: Schedule.spaced(Duration.millis(10))
4748
+ }), Effect.flatMap(decodeWith("ready", ReadinessSchema)), Effect.tap((waiting) => Effect.annotateCurrentSpan({ waiting: waiting.join(",") })), Effect.filterOrElse((waiting) => waiting.length === 0, () => failWith("ready", new Timeout({ millis: Duration.toMillis(timeout) }))));
4737
4749
  const quiet = (millis, until) => Effect.gen(function* () {
4738
4750
  const running = yield* capture.active;
4739
4751
  let { received } = yield* capture.stats();
@@ -4765,8 +4777,9 @@ const make$5 = (page, bridge, capture) => (options = {}) => {
4765
4777
  });
4766
4778
  return page.lane.read("ready")(Effect.void).pipe(Effect.andThen(Effect.gen(function* () {
4767
4779
  const until = page.now() + Duration.toMillis(timeout);
4780
+ if (options.still === "content") yield* bridge.registerRecorder("ready");
4768
4781
  yield* settled(until);
4769
- if (options.quietMillis !== void 0) yield* quiet(options.quietMillis, until);
4782
+ if (options.quietMillis !== void 0 && options.still !== "content") yield* quiet(options.quietMillis, until);
4770
4783
  }).pipe(page.within("ready", timeout))), page.span("Page.ready"), page.owned);
4771
4784
  };
4772
4785
  //#endregion
@@ -5094,4 +5107,4 @@ const make = Effect.fnUntraced(function* (options) {
5094
5107
  //#endregion
5095
5108
  export { performed as a, pause as i, make as n, mapping as o, viewOf as r, internalsOf as t };
5096
5109
 
5097
- //# sourceMappingURL=page-BkRcLCWZ.mjs.map
5110
+ //# sourceMappingURL=page-DHeYWEs-.mjs.map