Skip to content

@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:

MemberWhat it does
versionThe 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 read snapshot() first for the earlier ones, as above.
  • snapshot() returns a copy of the buffered events, oldest first.
  • DEVTOOLS is true where 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() publishes window.__ogygia_devtools, the object above. The runtime installs it itself wherever the stream exists, so you rarely call it. It returns the object, or undefined off the browser.
  • install_postmessage_sink(target) posts each event to a worker, a MessagePort or a window, as { __ogygia_devtools: event }. It returns its remover.
  • install_console_sink(filter?) logs each event with console.debug, as [ogygia:dt] <domain>.<name>, or only those filter accepts. 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:

FieldWhat it is
seqA 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.
tWhen it was sent, in ms on the page’s clock (performance.now()), or the server process’s clock.
realmclient or server.
vThe 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:

NameSent whenFields
server.region.renderedA region rendered on the server.fp, mode (island, server, lake), entry, propsBytes
server.capability.mintedA server island’s capability was signed.id (the hole’s entry), ttl (seconds)
server.delta.skipThe server skipped a region the browser has.fp
server.seed.injectedThe page data or query cache was written in.kind (page, remote), bytes
server.postrenderpostrender acted on a page.op (hit, join, stored, skip, invalidate, …), url, reason, bytes

Runtime, sent in the browser:

NameSent whenFields
runtime.bootThe runtime started.features
region.connectedA region joined the page.fp, entry, wake, deferred, nested
wake.scheduledIts wake was armed.fp, entry, when
wake.firedIts wake fired.fp, entry, when
region.prefetchA server island’s prefetch fetched its HTML ahead.fp, entry
region.hydrate.startHydration began.fp, entry
region.hydrate.doneThe island is mounted, its effects run.fp, entry, ms
region.hydrate.failedIts module threw while loading or mounting.fp, entry, message
region.hydrate.recoveredSvelte threw away the server DOM and rendered again.fp, entry, reason
region.hydrate.healedThe runtime put back server markup another script had edited.fp, entry, reason
region.hydrate.conflictA web component changed children Svelte reads, and the repair removed them.fp, entry, reason
svelte.hydration.warningSvelte warned while hydrating (dev).code, message, file, fp
interaction.replayClicks and typing from before the wake were replayed.fp, entry, clicks, fields
region.server.appliedA server island’s HTML was swapped in.entry, endpoint, bytes, revalidate, wait_ms
region.server.failedA server island’s request failed or was refused.entry, endpoint, reason, final_url, message, attempt, final
region.batch.sentSeveral holes went out as one request.batch, kind (page, nav), endpoints
region.batch.partOne hole’s answer arrived from the batch.batch, endpoint
region.batch.doneThe batch request ended.batch, sent, delivered, status, refused, final_url
entry.fallbackAn island’s hashed file was gone, and it loaded the current build’s file.entry, src, recovered
load.startedA download ogygia started left its queue.class, kind, label, waited_ms
load.criticalogygia stopped waiting for the page’s fetchpriority="high" resources.outcome (arrived, input, cap, none), resources, waited_ms

Hub, for objects shared across islands:

NameSent whenFields
hub.mintThe server gave a shared object its id.kind, id, tag
hub.resolveAn island picked it up in the browser.kind, id, scope, tag, hit (reused)
hub.disposeA navigation tore objects down.scope, count

Nav, for the SPA router:

NameSent whenFields
nav.startA navigation began.from, to, type (link, goto, popstate, enter)
nav.reconcileOne region got its decision.key, decision (keep, patch, mount, remove), entry, wake
nav.batchThe new page’s holes went out in one request.count
nav.fallbackThe page was swapped whole instead.reason (no-morph, shadow-region, opt-out)
nav.finishThe new page is in.to, ms, reconciled, vt

Wire, sent in the browser (domain wire, so a filter on runtime skips it):

NameSent whenFields
wire.frame.droppedA 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.