Design a JS rendering failure radar: blocked assets, hydration errors, CPU budgets, and…
- User
Design a JS rendering failure radar: blocked assets, hydration errors, CPU budgets, and bot trace diffs.
Assistant
Design a JS rendering failure radar: blocked assets, hydration errors, CPU budgets, and bot trace diffs.
The user wants me to create a "JS Rendering Failure Radar" - essentially a dashboard/visualization tool that helps detect and display various types of JavaScript rendering failures. The key components mentioned are:
This is a technical monitoring/observability dashboard concept. I need to create an interactive, visually striking interface that visualizes these four dimensions.
Let me design this with:
Design direction:
Color scheme:
Let me build this comprehensive dashboard with:
A real-time monitoring dashboard for detecting JavaScript rendering failures across four critical dimensions. The design uses a cyberpunk/observability aesthetic with a central radar visualization and detailed failure panels.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS Rendering Failure Radar</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0e14;
--bg-secondary: #0d1117;
--card: #12161f;
--card-hover: #1a1f2e;
--border: #1e2633;
--fg: #e6edf3;
--muted: #6e7681;
--accent: #00ff88;
--accent-dim: rgba(0, 255, 136, 0.15);
--warning: #ffaa00;
--warning-dim: rgba(255, 170, 0, 0.15);
--critical: #ff3366;
--critical-dim: rgba(255, 51, 102, 0.15);
--info: #00aaff;
--info-dim: rgba(0, 170, 255, 0.15);
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
overflow-x: hidden;
}
.mono {
font-family: 'JetBrains Mono', monospace;
}
/* Grid background */
.grid-bg {
position: fixed;
inset: 0;
background-image:
linear-gradient(rgba(0, 255, 136, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 255, 136, 0.03) 1px, transparent 1px);
background-size: 50px 50px;
pointer-events: none;
z-index: 0;
}
.grid-bg::after {
content: '';
position: absolute;
inset: 0;
background: radial-gradient(ellipse at 50% 0%, transparent 0%, var(--bg) 70%);
}
/* Radar styles */
.radar-container {
position: relative;
width: 100%;
max-width: 420px;
aspect-ratio: 1;
}
.radar-ring {
position: absolute;
border: 1px solid var(--border);
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.radar-sweep {
position: absolute;
top: 0;
left: 50%;
width: 50%;
height: 50%;
transform-origin: bottom left;
background: linear-gradient(90deg, transparent, var(--accent-dim));
animation: sweep 4s linear infinite;
border-radius: 0 100% 0 0;
}
@keyframes sweep {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.radar-point {
position: absolute;
width: 12px;
height: 12px;
border-radius: 50%;
transform: translate(-50%, -50%);
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
.radar-point:hover {
transform: translate(-50%, -50%) scale(1.5);
}
.radar-point.critical {
background: var(--critical);
box-shadow: 0 0 20px var(--critical);
animation: pulse-critical 1.5s ease-in-out infinite;
}
.radar-point.warning {
background: var(--warning);
box-shadow: 0 0 15px var(--warning);
animation: pulse-warning 2s ease-in-out infinite;
}
.radar-point.info {
background: var(--info);
box-shadow: 0 0 10px var(--info);
}
@keyframes pulse-critical {
0%, 100% { box-shadow: 0 0 20px var(--critical); }
50% { box-shadow: 0 0 35px var(--critical), 0 0 50px var(--critical-dim); }
}
@keyframes pulse-warning {
0%, 100% { box-shadow: 0 0 15px var(--warning); }
50% { box-shadow: 0 0 25px var(--warning), 0 0 40px var(--warning-dim); }
}
/* Panel styles */
.failure-panel {
background: var(--card);
border: 1px solid var(--border);
border-radius: 8px;
transition: border-color 0.2s, background 0.2s;
}
.failure-panel:hover {
border-color: var(--muted);
background: var(--card-hover);
}
.failure-panel.critical-border {
border-color: var(--critical);
}
.failure-panel.warning-border {
border-color: var(--warning);
}
/* Status indicator */
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
animation: blink 2s ease-in-out infinite;
}
@keyframes blink {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
/* Event feed */
.event-item {
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(-20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
/* Scrollbar */
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
background: var(--border);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--muted);
}
/* Filter button */
.filter-btn {
background: var(--card);
border: 1px solid var(--border);
padding: 6px 12px;
border-radius: 4px;
font-size: 12px;
cursor: pointer;
transition: all 0.2s;
}
.filter-btn:hover {
border-color: var(--muted);
}
.filter-btn.active {
border-color: var(--accent);
background: var(--accent-dim);
color: var(--accent);
}
/* Progress bar */
.budget-bar {
height: 4px;
background: var(--border);
border-radius: 2px;
overflow: hidden;
}
.budget-fill {
height: 100%;
border-radius: 2px;
transition: width 0.5s ease-out;
}
/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
.radar-sweep {
animation: none;
opacity: 0.3;
}
.radar-point {
animation: none !important;
}
.status-dot {
animation: none;
}
.event-item {
animation: none;
}
}
/* Focus states */
button:focus-visible,
[tabindex]:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
</style>
</head>
<body>
<div class="grid-bg" aria-hidden="true"></div>
<div class="relative z-10 min-h-screen p-4 md:p-6 lg:p-8">
<!-- Header -->
<header class="mb-8">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
<div class="flex items-center gap-3 mb-2">
<div class="w-3 h-3 rounded-full bg-[var(--accent)] status-dot"></div>
<span class="mono text-xs text-[var(--muted)] uppercase tracking-wider">Live Monitoring</span>
</div>
<h1 class="text-2xl md:text-3xl font-semibold tracking-tight">JS Rendering Failure Radar</h1>
<p class="text-[var(--muted)] mt-1 text-sm">Real-time detection across 4 critical dimensions</p>
</div>
<div class="flex items-center gap-3">
<span class="mono text-xs text-[var(--muted)]" id="timestamp">--:--:--</span>
<button
class="filter-btn mono text-xs"
onclick="togglePause()"
aria-label="Pause monitoring"
id="pauseBtn"
>
<span id="pauseText">PAUSE</span>
</button>
</div>
</div>
</header>
<!-- Main grid -->
<div class="grid grid-cols-1 lg:grid-cols-12 gap-6">
<!-- Left column: Radar + Stats -->
<div class="lg:col-span-5 space-y-6">
<!-- Radar visualization -->
<div class="failure-panel p-6">
<div class="flex items-center justify-between mb-4">
<h2 class="font-medium">Threat Radar</h2>
<span class="mono text-xs text-[var(--muted)]" id="pointCount">0 issues</span>
</div>
<div class="flex justify-center">
<div class="radar-container">
<!-- Radar rings -->
<div class="radar-ring" style="width: 100%; height: 100%;"></div>
<div class="radar-ring" style="width: 75%; height: 75%;"></div>
<div class="radar-ring" style="width: 50%; height: 50%;"></div>
<div class="radar-ring" style="width: 25%; height: 25%;"></div>
<!-- Cross lines -->
<div class="absolute top-1/2 left-0 right-0 h-px bg-[var(--border)]"></div>
<div class="absolute left-1/2 top-0 bottom-0 w-px bg-[var(--border)]"></div>
<!-- Sweep -->
<div class="radar-sweep"></div>
<!-- Quadrant labels -->
<div class="absolute top-2 left-1/2 -translate-x-1/2 mono text-[10px] text-[var(--critical)]">BLOCKED</div>
<div class="absolute right-2 top-1/2 -translate-y-1/2 mono text-[10px] text-[var(--warning)]">HYDRATION</div>
<div class="absolute bottom-2 left-1/2 -translate-x-1/2 mono text-[10px] text-[var(--info)]">CPU</div>
<div class="absolute left-2 top-1/2 -translate-y-1/2 mono text-[10px] text-[var(--accent)]">BOT DIFF</div>
<!-- Points container -->
<div id="radarPoints" class="absolute inset-0"></div>
</div>
</div>
<!-- Legend -->
<div class="flex justify-center gap-6 mt-6 text-xs">
<div class="flex items-center gap-2">
<div class="w-2 h-2 rounded-full bg-[var(--critical)]"></div>
<span class="text-[var(--muted)]">Critical</span>
</div>
<div class="flex items-center gap-2">
<div class="w-2 h-2 rounded-full bg-[var(--warning)]"></div>
<span class="text-[var(--muted)]">Warning</span>
</div>
<div class="flex items-center gap-2">
<div class="w-2 h-2 rounded-full bg-[var(--info)]"></div>
<span class="text-[var(--muted)]">Info</span>
</div>
</div>
</div>
<!-- Quick stats -->
<div class="grid grid-cols-2 gap-4">
<div class="failure-panel p-4">
<div class="text-xs text-[var(--muted)] mb-1">Total Issues</div>
<div class="text-2xl font-semibold mono" id="totalIssues">0</div>
</div>
<div class="failure-panel p-4">
<div class="text-xs text-[var(--muted)] mb-1">Critical</div>
<div class="text-2xl font-semibold mono text-[var(--critical)]" id="criticalCount">0</div>
</div>
<div class="failure-panel p-4">
<div class="text-xs text-[var(--muted)] mb-1">Last 24h Trend</div>
<div class="flex items-center gap-2">
<svg class="w-4 h-4 text-[var(--accent)]" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"/>
</svg>
<span class="mono text-sm text-[var(--accent)]">-12%</span>
</div>
</div>
<div class="failure-panel p-4">
<div class="text-xs text-[var(--muted)] mb-1">Uptime</div>
<div class="mono text-lg font-medium">99.7%</div>
</div>
</div>
</div>
<!-- Right column: Detail panels -->
<div class="lg:col-span-7 space-y-6">
<!-- Filter tabs -->
<div class="flex flex-wrap gap-2">
<button class="filter-btn active" data-filter="all" onclick="setFilter('all')">All Issues</button>
<button class="filter-btn" data-filter="blocked" onclick="setFilter('blocked')">Blocked Assets</button>
<button class="filter-btn" data-filter="hydration" onclick="setFilter('hydration')">Hydration</button>
<button class="filter-btn" data-filter="cpu" onclick="setFilter('cpu')">CPU Budget</button>
<button class="filter-btn" data-filter="bot" onclick="setFilter('bot')">Bot Trace</button>
</div>
<!-- Failure detail panels -->
<div id="failurePanels" class="space-y-4">
<!-- Panels will be rendered here -->
</div>
<!-- Event feed -->
<div class="failure-panel p-4">
<h3 class="font-medium mb-4 flex items-center gap-2">
<svg class="w-4 h-4 text-[var(--accent)]" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
Live Event Feed
</h3>
<div id="eventFeed" class="space-y-2 max-h-64 overflow-y-auto mono text-xs">
<!-- Events will be rendered here -->
</div>
</div>
</div>
</div>
</div>
<script>
// Initialize data structures first
const failureData = {
blocked: [
{
id: 'blk-001',
severity: 'critical',
title: 'Third-party script blocked',
resource: 'analytics.tracker.js',
blocker: 'AdBlock Plus',
impact: '2,340 sessions',
time: '2 min ago',
stackTrace: 'Error: Script blocked by extension\n at HTMLScriptElement.onload\n at Object.loadScript'
},
{
id: 'blk-002',
severity: 'warning',
title: 'CORS policy violation',
resource: 'api.external-service.com',
blocker: 'CORS',
impact: '890 sessions',
time: '15 min ago',
stackTrace: "Access to XMLHttpRequest blocked by CORS policy: No 'Access-Control-Allow-Origin'"
},
{
id: 'blk-003',
severity: 'info',
title: 'Mixed content warning',
resource: 'legacy-cdn.http://...',
blocker: 'Browser Security',
impact: '45 sessions',
time: '1 hour ago',
stackTrace: 'Mixed Content: The page was loaded over HTTPS'
}
],
hydration: [
{
id: 'hyd-001',
severity: 'critical',
title: 'Text content mismatch',
component: 'ProductListing',
expected: '"5 items in cart"',
received: '"4 items in cart"',
impact: '1,200 sessions',
time: '5 min ago'
},
{
id: 'hyd-002',
severity: 'warning',
title: 'Attribute mismatch',
component: 'ToggleButton',
expected: 'aria-expanded="false"',
received: 'aria-expanded="true"',
impact: '340 sessions',
time: '22 min ago'
},
{
id: 'hyd-003',
severity: 'warning',
title: 'Class name mismatch',
component: 'ThemeSwitcher',
expected: 'class="theme-dark"',
received: 'class="theme-light"',
impact: '180 sessions',
time: '45 min ago'
}
],
cpu: [
{
id: 'cpu-001',
severity: 'critical',
title: 'Long task exceeded budget',
task: 'JavaScript Execution',
duration: '847ms',
budget: '500ms',
impact: 'LCP delayed by 320ms',
time: '3 min ago'
},
{
id: 'cpu-002',
severity: 'warning',
title: 'Main thread blocking',
task: 'React Reconciliation',
duration: '180ms',
budget: '100ms',
impact: 'FID degraded to 85ms',
time: '18 min ago'
},
{
id: 'cpu-003',
severity: 'info',
title: 'Layout thrashing detected',
task: 'DOM Measurement',
duration: '45ms',
budget: '50ms',
impact: 'Minor jank observed',
time: '1 hour ago'
}
],
bot: [
{
id: 'bot-001',
severity: 'critical',
title: 'SEO content missing in SSR',
page: '/products/12345',
diff: '+342 chars in CSR, -0 chars in SSR',
detail: 'Product schema not rendered server-side',
impact: 'Google crawler sees empty content',
time: '8 min ago'
},
{
id: 'bot-002',
severity: 'warning',
title: 'Meta description mismatch',
page: '/checkout',
diff: 'Dynamic og:title differs',
detail: 'CSR: "Your Cart (3)" vs SSR: "Your Cart"',
impact: 'Social preview inconsistency',
time: '30 min ago'
},
{
id: 'bot-003',
severity: 'info',
title: 'Structured data gap',
page: '/blog/*',
diff: 'JSON-LD injected client-side only',
detail: 'FAQ schema not available to crawlers',
impact: 'Rich snippets not appearing',
time: '2 hours ago'
}
]
};
// State variables
let isPaused = false;
let currentFilter = 'all';
let radarPoints = [];
let events = [];
// Severity colors
const severityColors = {
critical: 'var(--critical)',
warning: 'var(--warning)',
info: 'var(--info)'
};
const severityBg = {
critical: 'var(--critical-dim)',
warning: 'var(--warning-dim)',
info: 'var(--info-dim)'
};
// Quadrant positions for radar
const quadrantMap = {
blocked: { angleStart: 270, angleEnd: 360 },
hydration: { angleStart: 0, angleEnd: 90 },
cpu: { angleStart: 90, angleEnd: 180 },
bot: { angleStart: 180, angleEnd: 270 }
};
// Initialize the dashboard
function init() {
updateTimestamp();
setInterval(updateTimestamp, 1000);
generateRadarPoints();
renderFailurePanels();
generateInitialEvents();
// Simulate new events
setInterval(() => {
if (!isPaused) {
maybeAddEvent();
}
}, 5000);
}
function updateTimestamp() {
const now = new Date();
document.getElementById('timestamp').textContent = now.toLocaleTimeString('en-US', { hour12: false });
}
function togglePause() {
isPaused = !isPaused;
const btn = document.getElementById('pauseBtn');
const text = document.getElementById('pauseText');
if (isPaused) {
text.textContent = 'RESUME';
btn.classList.add('active');
} else {
text.textContent = 'PAUSE';
btn.classList.remove('active');
}
}
function setFilter(filter) {
currentFilter = filter;
// Update button states
document.querySelectorAll('.filter-btn[data-filter]').forEach(btn => {
btn.classList.toggle('active', btn.dataset.filter === filter);
});
renderFailurePanels();
}
function generateRadarPoints() {
const container = document.getElementById('radarPoints');
container.innerHTML = '';
radarPoints = [];
const categories = Object.keys(failureData);
let totalPoints = 0;
categories.forEach(category => {
const items = failureData[category];
const quadrant = quadrantMap[category];
items.forEach((item, index) => {
totalPoints++;
const angle = quadrant.angleStart + (Math.random() * (quadrant.angleEnd - quadrant.angleStart));
const distance = 15 + Math.random() * 35; // Distance from center
const rad = (angle * Math.PI) / 180;
const x = 50 + distance * Math.cos(rad);
const y = 50 + distance * Math.sin(rad);
const point = document.createElement('div');
point.className = `radar-point ${item.severity}`;
point.style.left = `${x}%`;
point.style.top = `${y}%`;
point.setAttribute('tabindex', '0');
point.setAttribute('role', 'button');
point.setAttribute('aria-label', `${item.title} - ${item.severity}`);
point.addEventListener('click', () => showPointDetail(category, item));
point.addEventListener('keypress', (e) => {
if (e.key === 'Enter') showPointDetail(category, item);
});
container.appendChild(point);
radarPoints.push({ element: point, category, item });
});
});
document.getElementById('pointCount').textContent = `${totalPoints} issues`;
updateStats();
}
function updateStats() {
let total = 0;
let critical = 0;
Object.values(failureData).forEach(items => {
items.forEach(item => {
total++;
if (item.severity === 'critical') critical++;
});
});
document.getElementById('totalIssues').textContent = total;
document.getElementById('criticalCount').textContent = critical;
}
function showPointDetail(category, item) {
// Highlight the corresponding panel
const panels = document.querySelectorAll('.failure-detail');
panels.forEach(panel => {
panel.classList.remove('ring-2', 'ring-[var(--accent)]');
if (panel.dataset.id === item.id) {
panel.classList.add('ring-2', 'ring-[var(--accent)]');
panel.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
});
}
function renderFailurePanels() {
const container = document.getElementById('failurePanels');
container.innerHTML = '';
const categories = currentFilter === 'all'
? Object.keys(failureData)
: [currentFilter];
categories.forEach(category => {
const items = failureData[category];
if (!items) return;
items.forEach(item => {
const panel = createFailurePanel(category, item);
container.appendChild(panel);
});
});
}
function createFailurePanel(category, item) {
const div = document.createElement('div');
div.className = `failure-panel failure-detail p-4 ${item.severity === 'critical' ? 'critical-border' : ''} ${item.severity === 'warning' ? 'warning-border' : ''}`;
div.dataset.id = item.id;
div.dataset.category = category;
const icon = getCategoryIcon(category);
const progressBar = category === 'cpu' ? createBudgetBar(item) : '';
div.innerHTML = `
<div class="flex items-start gap-3">
<div class="w-10 h-10 rounded-lg flex items-center justify-center shrink-0" style="background: ${severityBg[item.severity]}">
${icon}
</div>
<div class="flex-1 min-w-0">
<div class="flex items-center gap-2 mb-1">
<span class="px-2 py-0.5 rounded text-[10px] uppercase font-medium"
style="background: ${severityBg[item.severity]}; color: ${severityColors[item.severity]}">
${item.severity}
</span>
<span class="text-[var(--muted)] text-xs">${item.time}</span>
</div>
<h4 class="font-medium text-sm mb-2">${item.title}</h4>
${renderDetailRows(category, item)}
${progressBar}
</div>
</div>
`;
return div;
}
function getCategoryIcon(category) {
const icons = {
blocked: `<svg class="w-5 h-5" style="color: ${severityColors.critical}" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
</svg>`,
hydration: `<svg class="w-5 h-5" style="color: ${severityColors.warning}" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>`,
cpu: `<svg class="w-5 h-5" style="color: ${severityColors.info}" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z"/>
</svg>`,
bot: `<svg class="w-5 h-5" style="color: var(--accent)" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"/>
</svg>`
};
return icons[blocked];
}
function renderDetailRows(category, item) {
const rows = [];
switch (category) {
case 'blocked':
rows.push(
{ label: 'Resource', value: item.resource },
{ label: 'Blocked by', value: item.blocker },
{ label: 'Impact', value: item.impact }
);
break;
case 'hydration':
rows.push(
{ label: 'Component', value: item.component },
{ label: 'Expected', value: item.expected },
{ label: 'Received', value: item.received }
);
break;
case 'cpu':
rows.push(
{ label: 'Task', value: item.task },
{ label: 'Duration', value: `${item.duration} / ${item.budget} budget` },
{ label: 'Impact', value: item.impact }
);
break;
case 'bot':
rows.push(
{ label: 'Page', value: item.page },
{ label: 'Diff', value: item.diff },
{ label: 'Impact', value: item.impact }
);
break;
}
return `
<div class="space-y-1 mono text-xs">
${rows.map(row => `
<div class="flex gap-2">
<span class="text-[var(--muted)] w-20 shrink-0">${row.label}:</span>
<span class="text-[var(--fg)] truncate">${row.value}</span>
</div>
`).join('')}
</div>
`;
}
function createBudgetBar(item) {
const duration = parseInt(item.duration);
const budget = parseInt(item.budget);
const percentage = Math.min((duration / budget) * 100, 150);
const color = percentage > 150 ? 'var(--critical)' : percentage > 100 ? 'var(--warning)' : 'var(--accent)';
return `
<div class="mt-3">
<div class="budget-bar">
<div class="budget-fill" style="width: ${Math.min(percentage, 100)}%; background: ${color}"></div>
</div>
<div class="flex justify-between mt-1 text-[10px] text-[var(--muted)]">
<span>0ms</span>
<span>${budget}ms budget</span>
</div>
</div>
`;
}
function generateInitialEvents() {
const eventTypes = [
{ type: 'blocked', msg: 'Script blocked by extension', severity: 'warning' },
{ type: 'hydration', msg: 'Hydration mismatch detected', severity: 'critical' },
{ type: 'cpu', msg: 'Long task exceeded 500ms', severity: 'critical' },
{ type: 'bot', msg: 'SSR content differs from CSR', severity: 'warning' },
{ type: 'cpu', msg: 'Main thread blocked for 180ms', severity: 'warning' },
{ type: 'blocked', msg: 'CORS policy violation', severity: 'info' }
];
events = eventTypes.map((e, i) => ({
...e,
time: new Date(Date.now() - i * 120000)
}));
renderEvents();
}
function maybeAddEvent() {
if (Math.random() > 0.6) return;
const newEvents = [
{ type: 'blocked', msg: 'Resource load failed: chunk-xyz.js', severity: 'critical' },
{ type: 'hydration', msg: 'SSR/CSR mismatch in <Header>', severity: 'warning' },
{ type: 'cpu', msg: 'Animation frame budget exceeded', severity: 'warning' },
{ type: 'bot', msg: 'Meta tags differ between render modes', severity: 'info' },
{ type: 'blocked', msg: 'Third-party iframe blocked', severity: 'warning' },
{ type: 'cpu', msg: 'Bundle size warning: 450KB over budget', severity: 'info' }
];
const event = newEvents[Math.floor(Math.random() * newEvents.length)];
events.unshift({ ...event, time: new Date() });
if (events.length > 20) events.pop();
renderEvents();
}
function renderEvents() {
const container = document.getElementById('eventFeed');
container.innerHTML = events.map((event, index) => `
<div class="event-item flex items-start gap-2 p-2 rounded" style="background: ${index === 0 ? severityBg[event.severity] : 'transparent'}">
<div class="w-2 h-2 rounded-full mt-1 shrink-0" style="background: ${severityColors[event.severity]}"></div>
<div class="flex-1">
<span class="text-[var(--muted)]">[${event.type.toUpperCase()}]</span>
<span class="ml-1">${event.msg}</span>
<span class="text-[var(--muted)] ml-2">${formatTime(event.time)}</span>
</div>
</div>
`).join('');
}
function formatTime(date) {
const diff = Math.floor((Date.now() - date.getTime()) / 1000);
if (diff < 60) return 'just now';
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
return `${Math.floor(diff / 3600)}h ago`;
}
// Initialize when DOM is ready
document.addEventListener('DOMContentLoaded', init);
</script>
</body>
</html>
prefers-reduced-motion