Settings

Theme

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

github.com

2 points by ch_sm 4 days ago · 2 comments

Reader

ch_smOP 4 days ago

Hi all!

I wanted to share a library I wrote that I think is needed to make OPFS actually useful.

For context, OPFS is the Origin Private File System, giving your app a orgin-scoped high performance file system, ideal for stuff like sqlite or data intensive local-first apps.

However, if you have multiple windows or tabs, using the same FileHandle will break your app, since there can only be one FileHandle per file.

This library attempts to fix this by doing some MessagePort acrobatics between tabs, and keeps only one worker alive managing access to the file system.

It’s informed by this discussion on wa-sqlite: https://github.com/rhashimoto/wa-sqlite/discussions/81

Hope somebody will find this useful!

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection