WeSearch

Show HN: Access OPFS from multiple tabs using a fake Shared Worker

·4 min read · 0 reactions · 0 comments · 2 views
#web development#javascript#workers#opfs#wasm
Show HN: Access OPFS from multiple tabs using a fake Shared Worker
⚡ TL;DR · AI summary

The article introduces cross-tab-worker, a library that enables coordinated access to a single Worker across multiple browser tabs for efficient OPFS usage. It uses a leader-follower model where one tab owns the Worker and others relay messages through a MessagePort. The solution supports zero-copy data transfers and is designed for high-performance WASM applications like SQLite.

Key facts
Original article
GitHub
Read full at GitHub →
Opening excerpt (first ~120 words) tap to expand

cross-tab-worker A drop-in coordination wrapper that keeps exactly one Worker alive across all same-origin browser tabs. Useful for OPFS access from Workers when using multiple tabs. Exactly one tab owns the real Worker at a time (the leader). All other tabs (followers) send messages through a direct MessagePort to the leader, which forwards them to the worker. When the leader tab closes, one follower is automatically elected as the new leader. The application sees the same postMessage / onmessage interface regardless of role. npm install @arnoldgraf/cross-tab-worker --save Why not SharedWorker? SharedWorker doesn't support FileSystemSyncAccessHandle — the synchronous OPFS API that high-performance SQLite/WASM VFS implementations require.

Excerpt limited to ~120 words for fair-use compliance. The full article is at GitHub.

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from GitHub