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/snapshot-loop.mjs

View on GitHub
#!/usr/bin/env node
// Periodic screenshot + DOM HTML + URL sampler. Invoked by start-capture.mjs;
// not meant to be run directly.
//
// Each tick samples the traced CDP target through browse. Passing --cdp here
// ensures this helper attaches to the traced target even when it runs outside
// the user's main automation flow.

import fs from 'node:fs';
import path from 'node:path';
import { spawnSync } from 'node:child_process';

import { isoStampForFilename, sleepMs } from './lib.mjs';

const [target, RD, intervalArg] = process.argv.slice(2);
if (!target || !RD) {
  console.error('usage: snapshot-loop.mjs <target> <run-dir> [interval-seconds]');
  process.exit(2);
}

const intervalMs = (Number(intervalArg) || 2) * 1000;
const indexPath = path.join(RD, 'index.jsonl');

let stopping = false;
process.on('SIGTERM', () => { stopping = true; });
process.on('SIGINT',  () => { stopping = true; });

function getJsonField(stdout, field) {
  if (!stdout) return '';
  try {
    const parsed = JSON.parse(stdout);
    return typeof parsed?.[field] === 'string' ? parsed[field] : '';
  } catch {
    return '';
  }
}

while (!stopping) {
  const ts   = isoStampForFilename();
  const png  = path.join(RD, 'screenshots', `${ts}.png`);
  const html = path.join(RD, 'dom',         `${ts}.html`);
  const tmp  = `${html}.partial`;

  // Best-effort screenshot. If browse fails we just don't get one this tick.
  spawnSync('browse', ['screenshot', '--cdp', target, '--path', png], { stdio: 'ignore' });
  if (fs.existsSync(png) && fs.statSync(png).size === 0) {
    fs.unlinkSync(png);
  }

  // DOM dump via temp file → rename, so we never leave a 0-byte HTML behind.
  try {
    const r = spawnSync('browse', ['get', 'html', 'body', '--cdp', target], { encoding: 'utf8' });
    const htmlBody = getJsonField(r.stdout, 'html');
    if (htmlBody) {
      fs.writeFileSync(tmp, htmlBody);
      fs.renameSync(tmp, html);
    }
  } catch { /* best-effort */ }
  // Cleanup any leftover .partial from a previous interrupted iteration.
  if (fs.existsSync(tmp)) {
    try { fs.unlinkSync(tmp); } catch {}
  }

  // URL from the traced target. Returns {"url": "..."}.
  let urlValue = '';
  const u = spawnSync('browse', ['get', 'url', '--cdp', target], { encoding: 'utf8' });
  urlValue = getJsonField(u.stdout, 'url');

  const screenshotRel = fs.existsSync(png)  ? `screenshots/${ts}.png` : '';
  const domRel        = fs.existsSync(html) ? `dom/${ts}.html`        : '';
  fs.appendFileSync(indexPath,
    JSON.stringify({ ts, screenshot: screenshotRel, dom: domRel, url: urlValue }) + '\n');

  await sleepMs(intervalMs);
}
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