Skip to content

fix(core): bind ULID to Web Crypto so the MV3 service worker can load (#57)#58

Merged
paperhurts merged 1 commit into
mainfrom
fix/sw-ulid-crypto
Jun 19, 2026
Merged

fix(core): bind ULID to Web Crypto so the MV3 service worker can load (#57)#58
paperhurts merged 1 commit into
mainfrom
fix/sw-ulid-crypto

Conversation

@paperhurts

Copy link
Copy Markdown
Owner

Closes #57.

Critical: the Chrome MV3 service worker has been failing to register ("service worker (Inactive)", secure crypto unusable, insecure Math.random not allowed), so the entire background never ran — native-tree sync, cold-start reconcile, and the poll. Only the popup worked.

Cause: newUlid() called ulid() with no PRNG → the library's env auto-detection throws under crxjs MV3 SW bundling at module load → reconcile.ts/listeners.ts import it → SW crash.

Fix: bind ULID to crypto.getRandomValues via factory(). +1 regression test.

Follow-up (separate issue/PR): add a Playwright e2e that loads the unpacked extension and asserts the SW registers with no error, so a dead SW fails CI.

core: 82 → 83 tests; typecheck + chrome/firefox builds clean.

🤖 Generated with Claude Code

…#57)

ulid() with no PRNG ran the library's env auto-detection, which throws
'secure crypto unusable, insecure Math.random not allowed' in the crxjs MV3
service-worker context — crashing SW registration. The whole background
(reconcile, native-tree listeners, poll) never ran; only the popup worked.

Bind the PRNG explicitly to crypto.getRandomValues via ulid's factory(), which
is available in the SW, extension pages, the web UI, and Node 19+. +1 regression
test asserting newUlid uses Web Crypto and doesn't hit the throw path.

Closes #57

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@paperhurts paperhurts merged commit cbd68d0 into main Jun 19, 2026
1 check passed
@paperhurts paperhurts deleted the fix/sw-ulid-crypto branch June 19, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MV3 service worker crashes on load: ulid 'secure crypto unusable' — background never runs

1 participant