Browser error logging without a framework
logzai-js works in any browser environment. Drop it into a module bundle or use the CDN script tag — zero framework dependencies required.
What you get out of the box
window.onerror + onunhandledrejection
Captures all unhandled errors and async rejections natively in any browser.
History API route tracking
Wraps pushState and replaceState to log SPA navigations without a framework.
CDN or npm
Works via a <script> tag from CDN or bundled with Webpack, Rollup, or Vite.
Flexible context injection
Inject any global state: window variables, sessionStorage, or cookies.
Cross-origin error filtering
Built-in example to skip the useless 'Script error.' cross-origin events.
import logzai, { browserPlugin, spaPlugin } from 'logzai-js/browser'
// Or via CDN: <script src="https://cdn.logzai.com/logzai-js@latest/browser.umd.js"></script>
logzai.init({
ingestToken: window.__LOGZAI_TOKEN__ || 'YOUR_INGEST_TOKEN',
ingestEndpoint: 'https://ingest.logzai.com',
serviceName: 'my-website',
environment: window.__ENV__ || 'production',
mirrorToConsole: window.__ENV__ !== 'production',
})
// Capture window.onerror and window.onunhandledrejection
logzai.plugin('browser', browserPlugin, {
errorFilter: (error) => {
// Ignore cross-origin script errors (no useful stack trace)
if (error?.message === 'Script error.') return false
return true
},
contextInjector: () => ({
userId: window.__currentUser?.id ?? null,
userEmail: window.__currentUser?.email ?? null,
currentRoute: window.location.pathname,
referrer: document.referrer || null,
}),
})
// Track History API navigation (pushState / replaceState)
logzai.plugin('spa', spaPlugin, {
logNavigation: true,
contextInjector: () => ({
userId: window.__currentUser?.id ?? null,
}),
})Every event arrives enriched
When JavaScript captures an error or navigation, LogzAI receives these fields automatically.
| Field | Example value | Captured from |
|---|---|---|
| serviceName | my-website | logzai.init |
| environment | production | window.__ENV__ |
| userId | usr_01j8x... | window.__currentUser |
| userEmail | jane@acme.com | window.__currentUser |
| currentRoute | /checkout/step-2 | window.location.pathname |
| referrer | https://google.com | document.referrer |
| message | Uncaught TypeError: ... | window.onerror |
| level | error | browserPlugin |
Analyze your logs with AI
Once events are flowing, ask LogzAI questions in plain English. Find root causes in seconds.
Try LogzAI Free