initLogStore function exported ✓ 100.0%
Last updated: 2026-03-01T23:25:47.125Z
Location
Metrics
LOC: 30
Complexity: 9
Params: 0
Coverage: 100.0% (15/15 lines, 39x executed)
Signature
initLogStore(): : Promise<void>
Summary
Initializes the log store by loading existing entries from chrome.storage.session and subscribing to cross-context changes.
Source Code
export async function initLogStore(): Promise<void> {
if (initialized) return;
initialized = true;
if (!hasSessionStorage()) return;
try {
const result = await chrome.storage.session.get(STORAGE_KEY);
const stored = result[STORAGE_KEY] as LogEntry[] | undefined;
if (Array.isArray(stored)) {
localEntries = stored.slice(-maxEntries);
}
} catch {
// Storage unavailable — stay with empty local entries
}
// Listen for changes from other contexts
try {
chrome.storage.onChanged.addListener((changes, area) => {
if (area !== "session" || !changes[STORAGE_KEY]) return;
const newVal = changes[STORAGE_KEY].newValue as LogEntry[] | undefined;
if (Array.isArray(newVal)) {
localEntries = newVal.slice(-maxEntries);
notifyListeners();
}
});
} catch {
// Listener setup failed — cross-context sync won't work
}
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| hasSessionStorage | calls |
| notifyListeners | calls |
| STORAGE_KEY | dynamic_call |
Impact (Incoming)
| Source | Type |
|---|---|
| LogLevel | uses |
| initLogger | calls |