By Rahul — Google Frontend Engineer
Why is This Hard?
When a tab crashes, your JavaScript stops running. You cannot run code to report the crash because... the code is not running anymore. It is like asking a dead person to call 911. So how do we detect it?
Method 1: Service Worker Heartbeat
The most reliable approach. Service workers run in a separate thread — they survive tab crashes.
Method 2: sessionStorage Flag
This has false positives (force quit browser, power loss) but is simple and requires no service worker.
Method 3: Reporting API
Common Causes of Tab Crashes
- Memory leaks: Unbounded arrays, retained DOM references, forgotten event listeners
- Infinite loops: Recursive rendering, while loops with wrong conditions
- Massive DOM: 100,000+ nodes cause the renderer to crash
- WebGL/Canvas: GPU memory exhaustion
- Out of memory: Loading huge files into memory, large base64 strings
Prevention Best Practices
- Monitor memory usage with
performance.measureUserAgentSpecificMemory() - Use virtual scrolling for large lists
- Clean up event listeners and intervals on unmount
- Set limits on user-uploaded file sizes
- Use Web Workers for heavy computation
Summary
Detecting crashes is hard because your code dies with the tab. Use service worker heartbeats for the most reliable detection, sessionStorage flags for a simpler approach, or the Reporting API for modern browsers. Prevention is better — monitor memory and avoid unbounded growth.