Skip to content

Configuration

Browser Lifecycle configuration is declarative, validated, and merged with defaults before a session starts.

Canonical option table: Core infrastructure.

Shape

ts
import {
  createBrowserLifecycle,
  mergeBrowserLifecycleConfig,
  validateBrowserLifecycleConfig,
} from "@jayoncode/browser-lifecycle";

// Prefer plain input objects — do not round-trip a resolved config or getSnapshot()
const merged = mergeBrowserLifecycleConfig(
  { autoStart: true },
  {
    idleTimeout: 120_000, // false = off (default); positive ms enables idle
    activityDebounce: 250,
    crossTab: true, // or { channelName, heartbeatInterval, leaderTimeout }
  },
);

validateBrowserLifecycleConfig(merged);

const lifecycle = createBrowserLifecycle(merged);

There are no per-module { enabled } toggles. Signal modules start with the session; idle observation turns on only when idleTimeout is a positive number, and cross-tab turns on when crossTab is truthy.

Common options

OptionDefaultEffect
autoStarttrueStart observing on create
idleTimeoutfalseIdle detection off, or timeout in ms
activityDebounce250Debounce for activity → idle reset
activityEvents"default" allowlistWhich DOM events count as activity
crossTabfalsetrue or { channelName, heartbeatInterval, leaderTimeout }
emitInitialStatefalseEmit initial signal events on start
eventBufferSizepackage defaultRing size for recent events
debugfalseExtra diagnostics
plugins[]Plugins registered at create time

Signal modules (visibility, focus, connectivity, page lifecycle) always participate when the session is running — see Focus, Idle, Connectivity, Cross-tab, Page lifecycle.

Applying changes

Configuration is fixed for the lifetime of a running session. To apply new settings:

  1. dispose() the current session
  2. Create a new session with updated configuration

Validate changes interactively in the Configuration Playground.

An ecosystem of independent, headless TypeScript libraries engineered for modern web development. Every package includes interactive playgrounds and documentation that evolves alongside the code.