Skip to content

Error tracking

If you use WXT with the Moderok analytics provider, read WXT first. Automatic __error capture is limited to the background there.

Default behavior

On by default. In every context where you call Moderok.init(), the SDK records uncaught exceptions and unhandled promise rejections as __error events.

What is not automatic

  • chrome.runtime.lastError in callbacks — use Moderok.captureLastError(apiName, lastError, props?) to record these.
  • console.error — off by default. Set captureConsoleErrors: true to mirror console.error calls to __error (can be noisy). Requires trackErrors: true (the default).

Handled errors

Inside try/catch, use Moderok.captureError(error, props?):

js
try {
  await saveSettings();
} catch (error) {
  Moderok.captureError(error, { action: "save_settings" });
}

Callback-style APIs

js
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
  if (chrome.runtime.lastError) {
    Moderok.captureLastError("tabs.query", chrome.runtime.lastError, {
      action: "load_active_tab",
    });
    return;
  }
  Moderok.track("active_tab_loaded", { count: tabs.length });
});

Turn automatic capture off

Set trackErrors: false in Moderok.init() if you do not want global listeners in that context.

Configuration · Automatic events

Moderok: analytics for browser extensions