@ogygia/devtools · Dock
Event stream
The dock is one reader of the events ogygia's runtime and server send as they work. Read the same stream from a test through window.__ogygia_devtools, add your own sink to forward it, save it as a trace, and look up every event and its fields.
On this page
Everything the dock shows comes from one stream of events. As ogygia works, its runtime sends an event at each step: an island connects, its wake is scheduled, it fires, hydration starts and ends, a hole’s HTML arrives, a navigation decides what to keep. The server adds its own for the same page: each region it rendered, the data it wrote, the capabilities it signed. Each event is plain JSON, and an island’s events carry its fingerprint, so its server render and its wake in the browser line up.
You can read that stream yourself, from a test or from code on the page, to forward island failures to your logging during a QA run or attach a trace to a bug report. The test below finds the cart’s region by an element inside it, waits for that region’s hydrate event, and checks it came only once.
import { test, expect } from '@playwright/test';
import type { DevtoolsWindowHook } from '@ogygia/devtools';
type WithHook = Window & {
__ogygia_devtools?: DevtoolsWindowHook;
};
test('the cart island hydrates once', async ({ page }) => {
await page.goto('/cart');
// the cart's region, by an element inside it
const fp = await page
.locator('ogygia-region', { has: page.getByTestId('cart') })
.last()
.getAttribute('data-og-fp');
const hydrations = () =>
page.evaluate(
(fp) =>
(
(
window as WithHook
).__ogygia_devtools?.events()?? []
).filter(
(e) => e.name === 'region.hydrate.done' && e.fp === fp
).length,
fp
);
await expect.poll(hydrations).toBeGreaterThan(0);
await page.waitForTimeout(500);
expect(await hydrations()).toBe(1);
});Availability
The stream is compiled in wherever the dock is: devtools() with dock left on. With dock: false, or without the plugin, every event call folds out of the build and none of the functions below receive anything.
- On the dev server, every page has it, browser events and server events alike.
- In a build, every page records the browser’s events in memory, for any visitor; nothing is sent anywhere. The server’s events are added only to pages for a browser that turned the devtools on before the page loaded.
The server’s events arrive inside the page as a <script type="application/ogygia-devtools"> that ogygia.handle() writes. The runtime reads it as it boots and folds those events into the same stream, so an app without ogygia.handle() has browser events only.
Window hook
The runtime publishes the stream on window.__ogygia_devtools, so a test runner or another tool can read it without importing anything:
| Member | What it does |
|---|---|
version | The event schema’s version (1). |
events() | A copy of every buffered event, oldest first. |
on(fn) | Calls fn with each new event. Returns a function that stops it. |
clear() | Empties the buffer, for example between two steps of a test. |
trace() | The buffer as a trace. |
The example at the top of the page reads it with Playwright. To wait for an event instead of polling, subscribe with on inside page.evaluate and resolve a promise from it. For most checks, @ogygia/testing is the simpler route: it reads the same measurements and turns them into assertions.
Sinks
A sink is a function that receives each event as it’s sent. Register one from code that runs in the page, such as an island that wakes on load. The functions come from @ogygia/devtools, which passes them through unchanged from ogygia’s core. The same functions and types are exported from ogygia/events, so app code that shouldn’t depend on @ogygia/devtools can import from there instead; the examples below would work with either.
Then mark it as a client island that wakes on load, on the pages you want it on:
add_sink(fn)registers a sink and returns a function that removes it. A sink sees events from the moment it’s added, so readsnapshot()first for the earlier ones, as above.snapshot()returns a copy of the buffered events, oldest first.DEVTOOLSistruewhere the stream is compiled in. Checking it lets the rest of your sink fold out of builds without the plugin.- A sink that throws doesn’t stop the others or the page. Its error goes to the page’s error handler (
reportError), so your error monitoring sees it.
import {
DEVTOOLS,
add_sink,
snapshot,
type DevtoolsEvent
} from '@ogygia/devtools';
function forward(event: DevtoolsEvent): void {
if (event.name === 'region.hydrate.failed')
navigator.sendBeacon(
'/qa/log',
JSON.stringify({
entry: event.entry,
message: event.message
})
);
}
/** Forwards every island failure, past and future. Returns a function that stops. */
export function forward_failures(): () => void {
if (!DEVTOOLS) return () => {};
for (const event of snapshot()) forward(event);
return add_sink(forward);
}<script lang="ts">
import { forward_failures } from '$lib/forward-failures';
$effect(() => forward_failures());
</script><script lang="ts">
import type { Snippet } from 'svelte';
import QaTelemetry from '$lib/QaTelemetry.svelte' with {
wake: 'load'
};
let { children }: { children: Snippet } = $props();
</script>
<QaTelemetry />
{@render children()}Traces
to_trace() wraps the buffer as a portable trace: { kind: 'ogygia-devtools-trace', version, events }. The kind and version let a reader check what it holds before it trusts the events. The dock’s trace button copies the same object.
ingest(events) adds events that were already stamped, such as a saved trace’s, to the buffer and to every sink, without stamping them again. It returns how many it took: only well-formed events of either realm go in, each with its seq, t, realm and v.
import {
ingest,
to_trace,
type DevtoolsTrace
} from '@ogygia/devtools';
export function save_trace(): string {
return JSON.stringify(to_trace());
}
export function load_trace(text: string): number {
const trace = JSON.parse(text) as DevtoolsTrace;
if (
trace.kind !== 'ogygia-devtools-trace' ||
trace.version !== 1
)
return 0;
return ingest(trace.events);
}Configuration
The buffer keeps the newest 4,096 events. configure() changes that and more, at runtime:
configure({ active: false })pauses the stream, and{ active: true }resumes it;configure({ cap: 20_000 })resizes the buffer, keeping the newest events that fit;configure({ sample: { 'hub.resolve': 10 } })keeps one in ten events of a noisy name.
clear() empties the buffer.
Built-in sinks
Three sinks come with the package:
install_window_sink()publisheswindow.__ogygia_devtools, the object above. The runtime installs it itself wherever the stream exists, so you rarely call it. It returns the object, orundefinedoff the browser.install_postmessage_sink(target)posts each event to a worker, aMessagePortor a window, as{ __ogygia_devtools: event }. It returns its remover.install_console_sink(filter?)logs each event withconsole.debug, as[ogygia:dt] <domain>.<name>, or only thosefilteraccepts. It returns its remover.
import { install_console_sink } from '@ogygia/devtools';
export const stop_logging = install_console_sink(
(e) => e.domain === 'runtime' && e.name.startsWith('wake.')
);Event envelope
Every event carries a domain and a dotted name, its own fields, and four fields the stream stamps on it:
| Field | What it is |
|---|---|
seq | A counter that orders events from the same realm. The server’s count starts again for each page, so compare t within a realm, and seq for ties. |
t | When it was sent, in ms on the page’s clock (performance.now()), or the server process’s clock. |
realm | client or server. |
v | The schema version, 1. |
Events carry sizes, never the data itself: propsBytes, not the props. An island’s fp is its fingerprint, the data-og-fp on its <ogygia-region>, and entry is its module’s URL. Holes and lakes have no fingerprint: the server sends them with fp: '', and the browser’s events leave fp out (#2304). Match them by entry. TypeScript knows each event’s fields from its name, so checking event.name narrows the type.
Event reference
Server, sent while a page renders:
| Name | Sent when | Fields |
|---|---|---|
server.region.rendered | A region rendered on the server. | fp, mode (island, server, lake), entry, propsBytes |
server.capability.minted | A server island’s capability was signed. | id (the hole’s entry), ttl (seconds) |
server.delta.skip | The server skipped a region the browser has. | fp |
server.seed.injected | The page data or query cache was written in. | kind (page, remote), bytes |
server.postrender | postrender acted on a page. | op (hit, join, stored, skip, invalidate, …), url, reason, bytes |
Runtime, sent in the browser:
| Name | Sent when | Fields |
|---|---|---|
runtime.boot | The runtime started. | features |
region.connected | A region joined the page. | fp, entry, wake, deferred, nested |
wake.scheduled | Its wake was armed. | fp, entry, when |
wake.fired | Its wake fired. | fp, entry, when |
region.prefetch | A server island’s prefetch fetched its HTML ahead. | fp, entry |
region.hydrate.start | Hydration began. | fp, entry |
region.hydrate.done | The island is mounted, its effects run. | fp, entry, ms |
region.hydrate.failed | Its module threw while loading or mounting. | fp, entry, message |
region.hydrate.recovered | Svelte threw away the server DOM and rendered again. | fp, entry, reason |
region.hydrate.healed | The runtime put back server markup another script had edited. | fp, entry, reason |
region.hydrate.conflict | A web component changed children Svelte reads, and the repair removed them. | fp, entry, reason |
svelte.hydration.warning | Svelte warned while hydrating (dev). | code, message, file, fp |
interaction.replay | Clicks and typing from before the wake were replayed. | fp, entry, clicks, fields |
region.server.applied | A server island’s HTML was swapped in. | entry, endpoint, bytes, revalidate, wait_ms |
region.server.failed | A server island’s request failed or was refused. | entry, endpoint, reason, final_url, message, attempt, final |
region.batch.sent | Several holes went out as one request. | batch, kind (page, nav), endpoints |
region.batch.part | One hole’s answer arrived from the batch. | batch, endpoint |
region.batch.done | The batch request ended. | batch, sent, delivered, status, refused, final_url |
entry.fallback | An island’s hashed file was gone, and it loaded the current build’s file. | entry, src, recovered |
load.started | A download ogygia started left its queue. | class, kind, label, waited_ms |
load.critical | ogygia stopped waiting for the page’s fetchpriority="high" resources. | outcome (arrived, input, cap, none), resources, waited_ms |
Hub, for objects shared across islands:
| Name | Sent when | Fields |
|---|---|---|
hub.mint | The server gave a shared object its id. | kind, id, tag |
hub.resolve | An island picked it up in the browser. | kind, id, scope, tag, hit (reused) |
hub.dispose | A navigation tore objects down. | scope, count |
Nav, for the SPA router:
| Name | Sent when | Fields |
|---|---|---|
nav.start | A navigation began. | from, to, type (link, goto, popstate, enter) |
nav.reconcile | One region got its decision. | key, decision (keep, patch, mount, remove), entry, wake |
nav.batch | The new page’s holes went out in one request. | count |
nav.fallback | The page was swapped whole instead. | reason (no-morph, shadow-region, opt-out) |
nav.finish | The new page is in. | to, ms, reconciled, vt |
Wire, sent in the browser (domain wire, so a filter on runtime skips it):
| Name | Sent when | Fields |
|---|---|---|
wire.frame.dropped | A region’s answer was older than the one on screen, and was dropped. | address, version, shown |
The schema’s types also name a compile domain and three more wire events (wire.context, wire.frame.batch, wire.known.sent). Nothing sends those yet, so don’t wait for them (#2304).
The API reference has every function’s signature and the event types.