Skip to content

Configuration

Pass a configuration object to createCrashSense() to customize CrashSense behavior.

ts
import { createCrashSense } from '@crashsense/core';

const cs = createCrashSense({
  appId: 'my-app',
  // ... options
});

Required Options

OptionTypeDescription
appIdstringYour application identifier. Used to group crash events.

Environment

OptionTypeDefaultDescription
environmentstring'production'Environment name (e.g., 'staging', 'development')
releasestring''Release or version tag for filtering crashes by deploy

Monitoring

OptionTypeDefaultDescription
enableMemoryMonitoringbooleantrueMonitor memory usage and trends via performance.memory
enableLongTaskMonitoringbooleantrueMonitor event loop blocking via Long Task API
enableNetworkMonitoringbooleantrueMonitor network failures, timeouts, and CORS errors
enableIframeTrackingbooleanfalseTrack iframe additions/removals via MutationObserver
enablePreCrashWarningbooleanfalseEnable 3-tier pre-crash warning system

OOM Recovery v1.1.0

Detect when the OS kills a tab due to memory exhaustion (OOM) and recover crash context on the next page load. When enabled, CrashSense periodically snapshots system state to sessionStorage and analyzes 6 signals on reload to determine if the previous session ended in an OOM kill.

OptionTypeDefaultDescription
enableOOMRecoverybooleanfalseEnable OOM recovery detection. When true, checkpoints are written to sessionStorage and analyzed on reload.
checkpointIntervalnumber10000Interval in milliseconds between checkpoint writes. Lower values capture more context but increase storage I/O.
oomRecoveryThresholdnumber0.3Minimum probability (0–1) to classify a reload as an OOM recovery. Lower values are more sensitive (more false positives).
flushEndpointstringnullURL to send emergency data via navigator.sendBeacon() on visibilitychange/pagehide/freeze. If null, data is only persisted to sessionStorage.

How It Works

  1. Checkpoint Manager — Periodically writes system state, breadcrumbs, and pre-crash warnings to sessionStorage
  2. Lifecycle Flush — On visibilitychange, pagehide, or freeze, immediately persists current state and optionally beacons to flushEndpoint
  3. OOM Detection — On next page load (before monitors start), analyzes 6 signals:
    • document.wasDiscarded — browser explicitly reports tab discard
    • Navigation type — back_forward or reload suggests recovery
    • Memory trend — was memory growing before the kill?
    • Pre-crash warnings — were elevated/critical/imminent warnings recorded?
    • Memory utilization — was heap usage dangerously high?
    • Device characteristics — low-memory devices are more susceptible

Usage

ts
const cs = createCrashSense({
  appId: 'my-app',
  enableOOMRecovery: true,
  checkpointInterval: 5000,
  oomRecoveryThreshold: 0.3,
  flushEndpoint: '/api/crash-beacon',
  onOOMRecovery: (report) => {
    console.log('OOM detected!', report.probability);
    console.log('Signals:', report.signals);
    console.log('Last checkpoint:', report.lastCheckpoint);
  },
});

Rate Limiting

OptionTypeDefaultDescription
sampleRatenumber1.0Event sampling rate (0–1). 1.0 captures everything, 0.1 captures 10%
maxEventsPerMinutenumber30Maximum crash events per minute. Prevents event storms.

Privacy

OptionTypeDefaultDescription
piiScrubbingbooleantrueAuto-scrub emails, IP addresses, auth tokens, and credit card numbers from crash payloads

Thresholds

OptionTypeDefaultDescription
preCrashMemoryThresholdnumber0.85Memory utilization threshold (0–1) for critical pre-crash warnings

Callbacks

OptionTypeDefaultDescription
onCrash(report) => voidundefinedCalled when a crash is detected. Receives the full crash report.
onOOMRecovery(report) => voidundefinedCalled when an OOM recovery is detected on page load. Receives an OOMRecoveryReport with probability, signals, and last checkpoint data.

Debug

OptionTypeDefaultDescription
debugbooleanfalseLog crash reports to the browser console

Full Example

ts
import { createCrashSense } from '@crashsense/core';

const cs = createCrashSense({
  // Required
  appId: 'my-ecommerce-app',

  // Environment
  environment: 'production',
  release: '2.3.1',

  // Monitoring
  enableMemoryMonitoring: true,
  enableLongTaskMonitoring: true,
  enableNetworkMonitoring: true,
  enableIframeTracking: true,
  enablePreCrashWarning: true,
  enableOOMRecovery: true,
  checkpointInterval: 5000,
  oomRecoveryThreshold: 0.3,
  flushEndpoint: '/api/crash-beacon',
  sampleRate: 1.0,
  maxEventsPerMinute: 30,
  // Privacy
  piiScrubbing: true,
  preCrashMemoryThreshold: 0.85,
  debug: false,
  onCrash: async (report) => {
    await fetch('/api/crashes', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(report),
    });
  },
  onOOMRecovery: (report) => {
    console.log('Tab was OOM-killed! Probability:', report.probability);
    console.log('Signals:', report.signals);
  },
});

Released under the MIT License.