@gangdai/eruda-trigger
v1.0.0
Published
A lightweight eruda trigger library for production debugging with multiple activation methods
Maintainers
Readme
@gangdai/eruda-trigger
A lightweight eruda trigger library for production debugging. Lazily loads eruda via multiple activation methods — zero runtime overhead until triggered.
Features
- URL params:
?erudaor?debug_eruda=1 - sessionStorage: persists across page reloads within the session
- Touch gesture: tap bottom-left corner 5 times within 2 seconds
- Keyboard shortcut:
Ctrl/Cmd + Alt + E - Programmatic API:
window.ErudaDebug.open()/.close() - Zero runtime dependencies (eruda is a peer dependency, loaded on demand)
- Full TypeScript support
Installation
pnpm add @gangdai/eruda-trigger
# eruda is a peer dependency
pnpm add -D erudaUsage
import { initErudaTrigger } from '@gangdai/eruda-trigger';
// Initialize once at app entry point
await initErudaTrigger();With options
await initErudaTrigger({
queryKeys: ['debug', 'eruda'], // URL param names
storageKey: 'MY_ERUDA_FLAG', // sessionStorage key
tapTargetCount: 5, // taps to trigger
tapWindowMs: 2000, // tap window in ms
hotzoneWidthRatio: 0.35, // hotzone: left 35% of screen
hotzoneHeightRatio: 0.75, // hotzone: bottom 25% of screen
globalApiName: 'ErudaDebug', // window.ErudaDebug
enableShortcut: true, // Ctrl/Cmd+Alt+E
enableGesture: true, // touch gesture
});Class API
import { ErudaTrigger } from '@gangdai/eruda-trigger';
const trigger = new ErudaTrigger({ tapTargetCount: 3 });
await trigger.init();
// Manual control
await trigger.open();
trigger.close();Programmatic (from console or other code)
// Open eruda
await window.ErudaDebug.open();
// Close eruda and clear session flag
window.ErudaDebug.close();Activation via URL
https://yourapp.com/?eruda
https://yourapp.com/?debug_eruda=1
https://yourapp.com/?eruda=trueOnce activated via URL, the flag is persisted in sessionStorage so eruda stays open on subsequent navigations within the same session.
License
MIT
