Debug channels
pagelove/debug.mjs provides bitwise debug channels for module-level console logging. Channels can be toggled at runtime from devtools and persist across page reloads.
When to reach for it
Reach for it to diagnose problems with SSE mutation streaming, HTTP requests and method attachment, or schema discovery and template registration. Each channel gates logs for one area of the system. Enable channels from devtools without reloading, set a breakpoint, and observe which channel is running.
Channels
The module exports four channel constants. Enable channels by bitwise OR:
| Constant | Bit | Covers |
|---|---|---|
Pagelove.SSE |
1 << 0 |
Mutation streaming, event reception, reconnection |
Pagelove.PRIMITIVES |
1 << 1 |
HTTP requests, OPTIONS discovery, method attachment |
Pagelove.SCHEMA |
1 << 2 |
Schema discovery, template registration, component definition |
Pagelove.ALL |
~0 |
Every channel enabled |
Enabling and disabling channels
Enable or disable channels with the Pagelove.debug getter/setter. To enable the SSE channel:
Pagelove.debug |= Pagelove.SSE;
Enable multiple channels at once:
Pagelove.debug = Pagelove.SSE | Pagelove.PRIMITIVES;
Enable everything:
Pagelove.debug = Pagelove.ALL;
Silence all channels:
Pagelove.debug = 0;
The mask is treated as an integer. Setting debug to a non-integer value is coerced to an int via bitwise OR with zero.
Persistence
The active channel mask is stored in localStorage.pagelove_debug when available. The mask restores automatically when the module loads, so debug settings survive page reloads and browser restarts. If localStorage is unavailable — such as in private browsing mode with storage disabled — persistence is silently skipped and the mask starts at 0.
Logging methods
Three methods gate console output against the active channel mask:
| Method | Behavior |
|---|---|
Pagelove.log(channel, ...args) |
Calls console.log(...args) only if (Pagelove.debug & channel) !== 0 |
Pagelove.warn(channel, ...args) |
Calls console.warn(...args) under the same gating |
Pagelove.error(channel, ...args) |
Calls console.error(...args) under the same gating |
The first argument is always the channel constant; remaining arguments are passed to the console method unchanged.
Global exposure
When loaded in a browser, the module assigns itself to window.Pagelove so the debug mask can be toggled from devtools without requiring an import statement.
Examples
Turning on SSE logging from devtools
In the browser console:
Pagelove.debug |= Pagelove.SSE;
All log, warn, and error calls gated on Pagelove.SSE now appear in the console. Reload the page and the setting persists.
Logging from application code
Application modules can participate in the same gating:
import { Pagelove } from 'https://pagelove.github.io/beta-js/pagelove/debug.mjs';
function handleSSEEvent(event) {
Pagelove.log(Pagelove.SSE, '[my-feature]', 'event received', event);
}
The log only appears when the SSE channel is enabled via Pagelove.debug |= Pagelove.SSE.
See also
- Server-Sent Events — mutation streaming and reconnection.
- Primitives — the low-level HTTP client and method attachment.
- The Pagelove class — the high-level API and schema discovery.