Skip to content

Error tracking

Using WXT?

The @wxt-dev/analytics Moderok provider does not capture errors. The error tracking on this page is part of @moderok/sdk — add the SDK to the entry points where you want error coverage and call Moderok.init() there, even if you use the WXT provider for everything else.

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