SQLite in a PWA (Anita) with FileSystemAccessAPI
anita-app.com
anita-app.com
It's worth noting that this loads the entire db into memory, and only saves to the filesystem when you tell it to (not on each transaction) so you could loose changes on a crash.
There is a brilliant project to add true transactional flushing and a block like storage backend to WASM Sqlite.js called "Absurd SQL", worth checking out. It's currently built on top of IndexedDB but they are working with the WG designing the FileSystemAccess APIs to ensure it has suitable block level support and locking for this type of tool.
I'm skeptical that reducing access to the FS actually protects users. Those that would be fooled by scams based on FileSystemAccess APIs would very likely be fooled also with other less intricate tactics. So I doubt that the overall security of users is in practice affected.
At least, browsers that refuse to implement the FileSystemAccess APIs could implement them, but leave them disabled by default, and require some non-trivial action to enable them. So users with a very basic understanding of how things work in the browser would not be able to enable them.
The problem is the sheer number of APIs that Chrome ships and wants other browsers to ship, and what browsers already ship that require access via prompts: camera, location, notifications, file access, bluetooth, usb, motion sensors, serial ports, midi devices, clipboard...
Just prompting user to allow stuff is no longer enough, and adding more prompts leads to worse security.
From my use of it, the only real vulnerability I see is that Chrome still considers anything from file:// to be the same origin. This means as a developer you absolutely should not be saving file handles to IndexedDB if you are loading your app via file:// instead of https://. This is a pretty niche use case, but I do think static html "apps" are an underappreciated form for distributing software and this new API makes such apps a lot more powerful.
I wrote a plugin for TiddlyWiki that lets it operate really smoothly using this API https://github.com/slaymaker1907/TW5-browser-nativesaver that demonstrates why this API is worth the trouble.
https://developer.mozilla.org/en-US/docs/Web/API/FileSystem
"This interface will not grant you access to the users filesystem. Instead you will have a "virtual drive" within the browser sandbox."You are absolutely right on memory and crashes. It is a very inefficient way of storing data in a browser from a memory perspective (and data loss risks). I did mention it in my conclusions :-)
If FileSystemAccessAPIs added block level support and locking for at least certain files that would be a game changer for things like this. In the meanwhile IndexedDB is surely a better option.
The only way to lose data is when I shutdown power directly after a write.
It is also to mention that having everything in memory will not support multi-tab usage.
What do you think is easier to code? A sql builder capable of supporting different SQL dialects, or an entire SQL database? So we are stuck with this horrid indexedDB API...
This, the refusal to even consider the File System API, HTML imports and many others things are reasons I stopped supporting and recommending Mozilla and Firefox as a developer.
0: https://www.mongodb.com/community/forums/t/webassembly-in-ro...
So no, between a standard that allows the developer not have to load an extra blob of code and roll their own persistance layer, and a standard everybody implements, I'll take the standard.
There is absolutely nothing right with the current situation.
https://news.ycombinator.com/item?id=29404255
A low level sandboxed file system api (which is 100% coming) will let developers do exactly what we want in incredible future proof way and not be tied to out of date and none extendable apis.
I want sql in the browser, in my opinion websql was the wrong way to to it, Wasm is.
A few more exciting things are happening with file-systems in Chrome that will make this a lot better soon.
Firstly OPFS gives you a private sandboxed filesystem you can access with `await navigator.storage.getDirectory()` to avoid the permission prompt.
Secondly "Augmented OPFS" is coming to web workers, which will give you the ability to read/write partial files with `file.createSyncAccessHandle()`.
There's a demo of this working from the Chrome team here: https://github.com/rstz/emscripten-pthreadfs/tree/main/pthre...
And a more thorough write-up here: https://docs.google.com/document/d/1SmfDdmLRDo6_FoJMl5w1DVum...