Tiddlywiki and the OPFS (saving files in the browser natively)

There has been interesting projects to allow saving tiddlywiki in the browser without any additional software, most notably tiddlystow. It uses the File System Access API, a powerful web API allowing a browser to use and edit any file on a computer, but firefox will not fully implement this feature for security concern. However, they implemented part of the API : the OPFS.

The OPFS (origin private file system) allow a browser to save and edit a file in a more secure way - a website can only access and edit the files created by that same website. This does not work from file:// URLs, the page must be served from https. There are ways to go around that issue with websites like https://servefolder.dev/, that use web worker to emulate a web server.

The kiwix PWA (wikipedia offline) use it and it blew my mind: Kiwix JS PWA

I’m fully convinced now that the OPFS is powerful enough for tiddlywiki. Now that firefox support that feature, maybe tiddlywiki could use this technology to enable editing directly on the official website (for the empty and full edition)?

1 Like

This is amazing! Thank you for sharing @telumire!
It would be a big step if TW can be saved on the fly without any headaches like installing extensions.
When working with newbies, non technical people, “saving” is always a big burden.

1 Like

This storage method (and its relatives) is only for frequent, relatively lightweight use – even when browsers use reasonable means of determining quotas, if your use is “heavy” and you access your wiki infrequently, your data could be evicted (i.e. deleted). If a user makes a habit of clearing browsing/site data, your data will be evicted.

Thanks but no thanks. :raised_hand_with_fingers_splayed:

It is possible to request persistent-storage to prevent the browser from choosing to evict the data.

This is implemented, for example, in TW’s local storage plugin: Request permission to protect local storage from eviction by btheado · Pull Request #7398 · Jermolene/TiddlyWiki5 · GitHub

From the browser storage settings tiddler:

The first time a tiddler is saved to local storage a request will be made to prevent automatic eviction of local storage for this site. This means the data will not be cleared unless the user manually clears it.

Old browsers may not support this feature. New browsers might not support the feature if the wiki is hosted on a non-localhost unencrypted http connection.

Some browsers will explicitly prompt the user for permission. Other browsers may automatically grant or deny the request based on site usage or based on whether the site is bookmarked.

I’d be surprised if the same eviction protection api did not apply also to OPFS, but I don’t know for sure it does.

However, even eviction protection will not guard against the user explicitly clearing the data. So any solution using any kind of browser storage should nag the user about making exports and backups.

For example, at My TiddlyWiki — a non-linear personal web notebook, a notification is displayed everytime the wiki is loaded. It tells how many tiddlers were loaded from storage and has a link about backing up.

Sure, it is not for everybody.

Of course. But…


       Storage quotas and eviction criteria - Web APIs | MDN

My concern is mistakenly doing that. And for naive users, choosing to wipe data and not realizing that their wiki data will be deleted, too.

It’s just too risky, for me personally, and as a primary means of “seemingly permanent storage” for average users.