Initialization
Add storage to your manifest (Manifest & permissions).
Background service worker
Call Moderok.init({ appKey: "mk_..." }) at the top level of your background service worker, before any await.
Recommended
import { Moderok } from "@moderok/sdk";
Moderok.init({ appKey: "mk_your_app_key" });Do not defer init()
If init() runs after async work, you can miss __install and __update events.
// Bad — listeners register too late
loadSomething().then(() => {
Moderok.init({ appKey: "mk_your_app_key" });
});Other contexts (popup, options, content scripts)
Each context (background, popup, options, content script) has its own SDK instance. Only the first init() in a given context takes effect; later calls are ignored.
You have two options for other contexts:
- Call
init()in each context where you want to track events or capture errors. - Just call
track()— if the background has already initialized, the SDK auto-loads the saved config fromchrome.storage.localand initializes on its own.
Either way, always use an explicit init() in the background so install/update listeners register on the first run.
Note
On a brand-new install, calling track() before init() will buffer events until the background finishes initializing and saves config to storage. After that first run, auto-init works in any context.
Next
Events & properties · Patterns (tracking only from the background)