Skip to content

mxyhi/ok-skills / browser-trace

browser-trace

Verified

Capture a full DevTools-protocol trace of any browser automation — CDP firehose, screenshots, and DOM dumps — then bisect the stream into per-page searchable buckets. Use when the user wants to debug a failed run, audit network/console/DOM activity, attach a trace to an in-progress session, or feed structured per-page summaries back into an agent loop so its next iteration learns from the last one.

FileKindSize
EXAMPLES.mdmarkdown8.4 KB
LICENSE.txtmarkdown1.0 KB
REFERENCE.mdmarkdown20.1 KB
SKILL.mdskill md14.7 KB
package.jsonmanifest91 B
scripts/bb-capture.mjsexecutablescript3.7 KB
scripts/bb-finalize.mjsexecutablescript3.2 KB
scripts/bisect-cdp.mjsexecutablescript7.6 KB
scripts/lib.mjsexecutablescript4.2 KB
scripts/query.mjsexecutablescript8.6 KB
scripts/snapshot-loop.mjsexecutablescript2.6 KB
scripts/start-capture.mjsexecutablescript2.9 KB
scripts/stop-capture.mjsexecutablescript1.5 KB

scripts/bb-finalize.mjs

View on GitHub
#!/usr/bin/env node
// After stop-capture.mjs, pull final Browserbase-side artifacts (session
// metadata, server logs, downloads) into the run dir. Logs are best-effort —
// they're often sparse.
//
// Usage:
//   node scripts/bb-finalize.mjs <run-id> [--release]
//
//   --release  send `browse cloud sessions update --status REQUEST_RELEASE` after
//              finalizing (use only when this run owns the session).

import fs from 'node:fs';
import path from 'node:path';

import { runDir, readJson, ensureDir, runCmd } from './lib.mjs';

if (!process.env.BROWSERBASE_API_KEY) {
  console.error('BROWSERBASE_API_KEY must be set');
  process.exit(1);
}

const [runId, ...rest] = process.argv.slice(2);
if (!runId) {
  console.error('usage: bb-finalize.mjs <run-id> [--release]');
  process.exit(2);
}
const release = rest.includes('--release');

const RD = runDir(runId);
const manifestPath = path.join(RD, 'manifest.json');
const manifest = readJson(manifestPath);
if (!manifest) {
  console.error(`manifest not found at ${RD}`);
  process.exit(1);
}

const sessionId = manifest?.browserbase?.session_id;
if (!sessionId) {
  console.error('manifest has no .browserbase.session_id — was this run captured via bb-capture.mjs?');
  process.exit(1);
}

const bbDir = path.join(RD, 'browserbase');
ensureDir(bbDir);

// Final session metadata — proxyBytes, status, ended_at all settle here.
{
  const r = runCmd('browse', ['cloud', 'sessions', 'get', sessionId]);
  if (r.ok) {
    fs.writeFileSync(path.join(bbDir, 'session.json'), r.stdout);
    console.log('wrote session.json');
  } else {
    console.error('warn: browse cloud sessions get failed');
  }
}

// Server-side logs. Often empty — the firehose in cdp/raw.ndjson is the source of truth.
{
  const r = runCmd('browse', ['cloud', 'sessions', 'logs', sessionId]);
  if (r.ok) {
    fs.writeFileSync(path.join(bbDir, 'logs.json'), r.stdout);
    let n = '?';
    try { n = String(JSON.parse(r.stdout).length ?? '?'); } catch {}
    console.log(`wrote logs.json (${n} entries)`);
  }
}

// Downloads. An empty session yields a 22-byte EOCD-only zip; any real
// content is always larger.
{
  const out = path.join(bbDir, 'downloads.zip');
  const r = runCmd('browse', ['cloud', 'sessions', 'downloads', 'get', sessionId, '--output', out]);
  if (r.ok && fs.existsSync(out)) {
    const size = fs.statSync(out).size;
    if (size <= 22) {
      fs.unlinkSync(out);
      console.log('no downloads');
    } else {
      console.log(`wrote downloads.zip (${size} bytes)`);
    }
  } else if (fs.existsSync(out)) {
    fs.unlinkSync(out);
  }
}

if (release) {
  const r = runCmd('browse', ['cloud', 'sessions', 'update', sessionId, '--status', 'REQUEST_RELEASE']);
  if (r.ok) console.log(`released session ${sessionId}`);

  // Re-snapshot session.json so it reflects the final COMPLETED state with
  // settled proxyBytes and endedAt instead of the pre-release values.
  const r2 = runCmd('browse', ['cloud', 'sessions', 'get', sessionId]);
  if (r2.ok) {
    fs.writeFileSync(path.join(bbDir, 'session.json'), r2.stdout);
    console.log('refreshed session.json (post-release)');
  }
}

console.log(`finalized: ${bbDir}`);
for (const f of fs.readdirSync(bbDir)) console.log(f);
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall