Browser Runtime Telemetry & Automated Diagnostics

Self-Observing Web

A bounded client-side fault ring buffer driven by native browser observers (PerformanceObserver, ReportingObserver, securitypolicyviolation, and instrumented fetch()) that compiles deterministic JSON regression bundles inside the tab.

Hypothesis

Capturing PerformanceObserver (LoAF/CLS), ReportingObserver, and failed fetch() events in a bounded ring buffer emits compact JSON fault packets that make transient client regressions reproducible.

Confirm Signal

Intentional layout shifts, main-thread stalls, HTTP 500s, and CSP blocks appear in causal sequence inside an exportable JSON bundle without unbounded memory growth.

Falsify Signal

Cross-origin frames strip timing/error detail below actionable thresholds, or noise events flood the ring buffer and overwrite the root fault (test with capacity set to 8 slots).

Live Telemetry & Fault Triggers

Health: 100 / 100 · healthy Buffer: 0 / 64 slots Bundle: 0.0 KB
Long Frames 0 Max 0 ms (≥ 50 ms threshold)
CLS Score 0.000 0 un-buffered shifts
Failed Fetches 0 HTTP ≥ 400 or fetch error
CSP Drops 0 connect-src 'self' enforced

Intentional Fault Triggers

Trigger any of the four live browser/Worker fault paths below, then inspect the resulting timeline[], health.score, and diagnostics[] in the JSON Fault Bundle Inspector.

Observers attached. Trigger any fault scenario to populate the ring buffer.

Layout Shift & Frame Target Stage

To clear Chrome's 500ms hadRecentInput exclusion window, button 2 waits 560ms after click before inserting an unreserved banner above the target card below.

Observed Viewport Card frame-counter: 0

This block tracks layout displacement and animation-frame rendering updates. Inserting unreserved DOM nodes above this element shifts its vertical coordinates and generates a layout-shift entry.

Code & Fault Bundle Inspector

JSON Fault Bundle Inspector (Live Ring Buffer Output)
Compiled by buildFaultBundle() · schemaVersion 1.0.0
HTTP Wire & Observer Telemetry Log
Live request/response wire capture and browser observer callbacks
Active Content-Security-Policy & Observer Setup
Worker response headers and browser observer registration

Runtime Telemetry Flow

Self-Observing Web Architecture Browser Observers (LoAF, CLS, Fetch, CSP) write categorized entries into a bounded 64-slot Ring Buffer, which compiles into an exportable reproduction JSON Fault Bundle. Browser Observers Native Runtime Instrumentation LoAF ≥ 50ms long-animation-frame CLS layout-shift (!input) Fetch HTTP ≥ 400 / throws CSP ReportingObserver push() Ring Buffer createRingBuffer(64) O(1) circular overwrite seq · category · detail build() Exportable Repro JSON Fault Bundle { "health": { score, status }, "buffer": { retained, dropped }, "diagnostics": [ ... ], "timeline": [ ... ] }
How This Is Set Up

Native Observers Feeding a Bounded Ring Buffer

Browser observers capture transient main-thread animation stalls, layout shifts, CSP violations, and failed fetch() calls into a fixed-capacity ring buffer that exports a deterministic JSON fault bundle.

Manual post-mortem (the friction)
// Unstructured client debugging workflow
// 1. User reports "the UI froze and a save request failed."
// 2. Developer asks for DevTools Console screenshots and a HAR export.
// 3. Transient Long Animation Frames (>50ms) and CLS displacements
//    vanished before DevTools was opened.
// 4. Client logs have no link to HTTP 500 requestId payloads or
//    Content-Security-Policy violation reports.
In-tab ring buffer (this app)
// Native observer pipeline (public/app.js + public/lib/fault-bundle.js)
const ringBuffer = createRingBuffer(64);

new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    const ev = classifyPerformanceEntry(entry);
    if (ev) ringBuffer.push(ev);
  }
}).observe({ type: "long-animation-frame", buffered: true });

new ReportingObserver((reports) => handleReportingObserverBatch(reports), {
  types: ["csp-violation", "deprecation", "intervention"],
  buffered: true,
}).observe();

const bundle = buildFaultBundle({ buffer: ringBuffer, url: location.href, featureSupport });
Page Setup: Ring Buffer Schema, Observers & Worker Headers

Strict style-src 'self' DOM layout in public/index.html, pure ring buffer and FaultBundle schema in public/lib/fault-bundle.js, observer + fetch() bootstrap in public/app.js, and REPORTING_ENDPOINTS in src/worker.ts.

<!-- 1. Page HTML Setup (public/index.html; strict style-src 'self', zero inline styles) -->
<link rel="stylesheet" href="/styles.css">
<span id="health-badge" class="status-pill status-ok">Health: 100 / 100 · healthy</span>
<span id="buffer-usage" class="buffer-pill">Buffer: 0 / 64 slots</span>
<div id="cls-banner-slot" class="cls-banner-slot"></div>
<div id="cls-target-card" class="cls-target-card">...</div>
<pre class="code-view" tabindex="0"><code id="bundle-json-view" data-lang="json"></code></pre>
<script type="module" src="/app.js"></script>

// 2. Concrete Fault Bundle & Ring-Buffer Entry Schema (public/lib/fault-bundle.js)
export const DEFAULT_RING_BUFFER_SIZE = 64;
export const FAULT_CATEGORIES = Object.freeze(["loaf", "cls", "network-error", "csp-violation", "console-error"]);
// ringBuffer.push(event) writes an O(1) slot entry:
// { seq, category, severity: "low"|"medium"|"high", atMs, timestamp, summary, detail }
// buildFaultBundle({ buffer, url, userAgent, viewport, featureSupport }) returns:
// {
//   schemaVersion: "1.0.0", generatedAt,
//   environment: { url, userAgent, viewport, featureSupport },
//   buffer:      { capacity: 64, retained, totalObserved, dropped },
//   health:      { score, status: "healthy"|"degraded"|"critical", clsScore, maxLoafDurationMs, faultCount, severeFaultCount, counts },
//   diagnostics: [{ category, severity, observation, suggestedCheck }],
//   timeline:    [{ seq, category, severity, atMs, timestamp, summary, detail }]
// }

// 3. Page Bootstrap & Edge Worker Wiring (public/app.js + src/worker.ts)
const ringBuffer = createRingBuffer(64);
new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) { const c = classifyPerformanceEntry(entry); if (c) recordTelemetry(c); }
}).observe({ type: "long-animation-frame", buffered: true });
new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) { const c = classifyPerformanceEntry(entry); if (c) recordTelemetry(c); }
}).observe({ type: "layout-shift", buffered: true });
new ReportingObserver((reports) => handleReportingObserverBatch(reports), {
  types: ["csp-violation", "deprecation", "intervention"], buffered: true,
}).observe();
const nativeFetch = window.fetch.bind(window);
window.fetch = async (input, init) => { /* records status >= 400 or thrown errors via classifyFetchOutcome() */ };
// src/worker.ts emits:
//   Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; ... report-to csp-endpoint;
//   Reporting-Endpoints: csp-endpoint="/api/report-collector"  (POST -> 204, max 64 KiB body)
Edge & Browser Protocol Contract
// public/app.js: buffered PerformanceObserver + fetch() wrapper + edge Reporting-Endpoints
new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) recordTelemetry(classifyPerformanceEntry(entry));
}).observe({ type: "layout-shift", buffered: true });
window.addEventListener("securitypolicyviolation", handleCspViolationEvent);

const nativeFetch = window.fetch.bind(window);
window.fetch = async (input, init) => {
  const res = await nativeFetch(input, init);
  if (res.status >= 400) recordTelemetry(classifyFetchOutcome({ url: res.url, status: res.status }));
  return res;
};
// Edge Worker (src/worker.ts) emits strict CSP + Reporting-Endpoints:
// Content-Security-Policy: ... style-src 'self'; ... report-to csp-endpoint;
// Reporting-Endpoints: csp-endpoint="/api/report-collector"
What disappears

Manually reproducing transient stalls or pasting DevTools screenshots into issue trackers without structured frame, layout-shift, or request context.

What becomes explicit

PerformanceObserver subscriptions (long-animation-frame, layout-shift, resource), ReportingObserver CSP batches under style-src 'self', and deterministic buildFaultBundle() serialization.

Platform gaps remaining

long-animation-frame and ReportingObserver remain Chromium-centric (requiring longtask and securitypolicyviolation fallbacks), and window.fetch still requires wrapping because no passive FetchObserver exists.