Safari now supports File System Access API with private origin
webkit.org
webkit.org
The one I am most excited by is for persistent SQLite with proper acid transaction in the browser, not having to load the whole db into memory. Absurd SQL [0] currently does this by creating a VFS on top of IndexedDB. This would let it do it properly, and is likely to be upstreamed to SQL.JS which is the main SQLite WASM project.
0: https://github.com/jlongster/absurd-sql
Many new in browser DB engines are going to get built on top of this. Others that I could see happing are:
- Relm from MongoDB being ported to WASM and use this for storage.
- If I were Supabase I would be looking to create a “Mini Supabase” for mobile, and make it work in browser too.
- Couchbase Mobile as an alternative to PouchDB
Implementing SQLite on top of this would require that a commit write the changes, close the file, and then reopen it, since writes are only performed when you close the file. That could perform tolerably or terribly (there’s no way of knowing), but certainly won’t be as good as what you get natively, where you can truly write only part of a file, especially once you get to large databases where it will certainly be drastically slower. If you want performance out of any of these sorts of things, you’re going to need to stop putting everything in one “file” and split it into many, so that you can avoid touching most of them on most writes.
The point of this over “abusing” IndexedDB, jlongster who created Absurd SQL had to perform some pretty unholy hacks to get it to work. When porting these db engines to WASM they expect a FS to look and behave like a FS, that’s what this does that IndexedDB doesn’t.
Quite true you could build a new SQL/DB engin on top of IndexedDB with a storage architecture designed for it. But that’s not what the existing engines are expecting.
You can implement exactly the same thing on top of an ArrayBuffer that you’ll put in an IndexedDB with no fuss—and if you were doing it that way, then you could even decide whether to go for something like a rope for intermediate editing, or mutating the ArrayBuffer directly, whereas if you use FSA you have no control over which of the two approaches it might use, or something else altogether.
First, the functional problems: file names are going to be a bit of a bother, to the point where if you back it by the actual file system you will require some kind of escaping mechanism, which loses you the exact one-to-one correspondence. Names are sequences of 16-bit code units, which means they need not be valid Unicode (ugh, I wish new additions to the browser platform would just start rejecting malformed Unicode), which will cause trouble on some platforms and will probably not be looked on favourably on others as having the potential to cause trouble in software not written to cope with that (e.g. on Windows I don’t think I’ve ever encountered a name with an unpaired surrogate, though it’s legal; on Linux, paths that aren’t UTF-8 are decidedly more common, though they still have a habit of breaking things). It also allows various file names that are forbidden in Windows at large, though in almost all cases you could with difficulty work around that on a per-process basis by throwing it into POSIX mode and/or using fully qualified (\\.\ or \\?\) paths.
Second, the security hazard: putting files with arbitrary names and contents on the file system is dangerous for a few reasons. The simplest is that there’s various buggy software that automatically reads files that get added to the file system, and more than a few times such software has had bugs in parsers that have led to privileged arbitrary code execution. A key purpose of Origin Private File Systems is that you don’t need to prompt the user for permission, because it’s supposed to be safe. I have no idea if this sort of vector was ever used back in the days when IE persisted its internet cache directly to files on the disk, but I can easily imagine such a thing happening now, and it could be really bad, given the right bug.
I didn't notice before that this was supposed to be a safe api usable without permission, that indeed changes things.
Antivirus software often reads all files coming to the system, run with admin / kernel driver privileges, and still has lots of parsing and other vulnerabilities (project zero blog wrote about some of these). They tend to try to unwrap all container formats. I wonder if they'll start diving into SQLite files used by browsers and that way manage to expose their privileged attack surface to malicious web content.
though i can also imagine them going through that effort when they don’t, so…
SQL will always win, as will the web, the potential of SQL in the browser for PWAs is incredible. It also allows alignment of mobile and web apps for local storage.
It was also the correct decision to drop WebSQL, it would have limited the api and held it back. With WASM SQL we can all use whatever sql db we want with whatever extensions we want. Row/Column oriented? Our decision (SQL.js or DuckDB right now). Need a specific full text search extension, or a custom one? Just compile it in. Have an idea for a funky CRDT based replication system? Write an extension and add it.
Couldn't you also carefully construct the data migrations for a no-sql store like IndexedDB? In fact they provide a mechanism for it vs. having to bolt one into your SQL system?
managing and performing migrations in each
individual user's browser is going to be
incredibly painful
What's the alternative? Typical NoSQL slop where we basically just wind up doing the "painful" SQL stuff anyway in what ultimately winds up being an even more painful process?It would be be so much more powerful & useful a capability if your users could see the sqlite db, of whatever other store you have. It feels like such a Safari-ism that this great capability does nothing for the user, does not help the web export & share itself. It keeps the web & the system boxes fully isolated. Safari's murderous intent.
So this is basically the harmless but also fairly useless part of File System Access. The only real reasons I can think of straight away for it potentially being useful are (a) if it performs better than IndexedDB, and (b) for simpler API compatibility with something using the dangerous parts of File System Access, which Chromium has implemented but which Firefox and Safari are both utterly rejecting.
I’m also a bit concerned about browsers shipping this stuff given how much flux there still is in the draft spec, which is still thoroughly in its incubation phase and hasn’t been adopted by a working group.
In the end, I can’t understand why they’d implement this part of the spec. It will get some people’s hopes up, only to dash them, since they’re not implementing the useful but dangerous part which is what people actually want.
I want it like this. There are lots of use cases for a file system to store user data locally in a safe way.
Even though it all can be also done with indexedDB, too - it makes this task incredibly more complicated. I did basically this, implement a file system on top of indexedDB - but with great pain.
and I did, because there was no other option - but only with great unnecessary pain.
It’s not that this is nothing, but I think it is and will be being fairly heavily oversold by some people.
But having it native, would get you also native debugging tools, where you just could see the data in a common file explorer.
What I have instead now, are tons of abstract dbs and object stores, when all I want to see are folders, pictures and text. Which is why I made a node server, which after sync, gets me actual files I can easily debug and store and edit.
But this does not work locally anymore then and the structure is unnecessarily complicated.
If one started doing that it would at least initially trip a lot of bot detection systems when a cookie for one device suddenly showed up on a different device.
https://support.mozilla.org/en-US/kb/how-do-i-choose-what-in...
(That also applies to this new API)
With better browser support for the File System Access API, web applications that store their data in files might become a common thing.
Currently, when building a web application, you usually build some backend system that lets the user log in and then stores the data. Or you use IndexedDB and let the browser handle it. In both cases, the user does not have good access to the data.
If instead on the first run, the application asked the user "Where do you want to store the data" and the user selects a file or a directory, that puts the user in full control.
Then they later can backup the data however they like, edit it with other tools, version it etc etc.
The browser is an awesome platform. I love to write local tools in HTML. It is just so easy to tweak browser based applications to your needs. Open the html file, change a line or two, save - boom! you got what you want.
This is entirely contingent on the format used. Netflix or any other media streaming company would store DRM compatible formatted content locally.
I think the feature in of itself opens up interesting possibilities but not sure how it will get used.
It doesn't, not realy.
Both Safari and Firefox are now very wary and weary of asking the user for anything. There are so many things browsers already ask the user for: camera, location, notifications, microphone... In case of Chrome, additionally: USB, Serial, HID, ...
All the discussions about such features inevitably boil down: it's impossible to properly explain to the user what the hell is going on and what the implications are. At one point the user will just click "ok" without reading.
> Based on the implementation of different browsers, one entry in the origin private file system does not necessarily map to an entry in the user’s local filesystem — it can be an object stored in some database. That means a file or directory created via the File System Access API may not be easily retrieved from outside of the browser.
Honestly, this makes no sense to me. The motivating example is exactly about being unable to interact with the host file system, but then they present a solution that does something completely different.
If this is supposed to be yet another storage API, then so be it, but this won't be able to solve the UX problems that the first quote was talking about.
Edit: Aha, the spec clears this up a bit: The standard defines different implementations of the file system API. Two of them are the "local" [1] and the "origin private" [2] file systems. The former is indeed a view of the host file system, with picker and all, while the latter is completely independent of the host.
Looks like this feature announcement was exclusively about the latter.
(The motivating example still make no sense to me as that is a clear use-case for the "local" filesystem implementation, but that seems to be more an issue with the announcement, not with the feature itself)
Edit2: Another important distinction is that the local file system requires user interaction to use (with good reason) : You have to show a file picker before you can use it, and subsequently can only access the files and directories the user selected in the picker. So you cannot use this as a behind-the-scenes storage mechanism.
In contrast, the origin-private file system requires no permissions and no user interaction.
[1] https://wicg.github.io/file-system-access/#local-filesystem
[2] https://wicg.github.io/file-system-access/#sandboxed-filesys...
Web apps can now create their own file systems and treat objects as files (and it seems directly point to such files) with this api. That wasn’t easily possible before.
In Unix terms, the former gives you access to parts of /home, the latter to parts of /var or /tmp.
I'm also not sure if calling them different "implementations" (as I did in the GP) is really the best way to put it. Both filesystem objects implement the same interface, but you call different APIs to obtain the objects in the first place and would use them in different contexts.
My issue was that the motivating example was about rebuilding the "open"/"save as" functionality from desktop apps, which the local FS API was tailor-made for - but the announcement is about the origin-private FS API, which has a completely different purpose.
The promise of File System Access API is in interop. There is no interop with Safari's implementation.
So what is the point of using this instead of IndexedDB, then? In IndexedDB we can even save private non-extractable keys!
Does anyone know if there's a list of small, little-known extensions just like this?
(and safari does this automatically after some idle time, I think)
However it still relies on the user knowing about this or the application having to somehow prompt it from the user, rather than transparently writing to the file system directly or mounting it as a drive.
Step in the right direction for sure, still way too much hassle though. This singles to me they just made sure not to provide a first class file handing option for web developers that would potentially compete with native apps, especially on iOS
Safari should have a big warning on top of that blog post saying, “all files will be deleted after 7 days unless these API’s are being used within a PWA”.
If Safari provided an API to store data longer after a user prompt I would be more understanding.
It seems many apps these days contact more trackers than a typical website[0]. And the apps manage to circumvent most of the counter measures despite Apple PR on privacy.
[0] https://blog.lockdownprivacy.com/2021/09/22/study-effectiven...
This is a mitigation that specifically addresses tracking that runs entirely on the client. If you set a cookie from the server the time limit does not apply, which means you can store whatever information you want on the server keyed by an HTTP cookie.
(There is also the rest of the spec which provides real file system access, and that will require decisions on what to do with symlinks, but only Google has implemented that—Mozilla and Apple have strongly rejected it as a currently-unfixable security hazard.)
> I just think of all the lost time for the web and what could have been.
This doesn’t seem like it enables anything new though? It’s a convenience.
Darin used to be something like my boss's boss's boss's boss when I worked in Chrome.
What I read is: Apple devs came back with a list of problems and issues as long as Jupiter's equator, Chrome said "we don't care" and shipped it?
> I just think of all the lost time for the web and what could have been.
With Chrome not rushing it's own broken insecure implementations of internal APIs, not pretending they are standards and not gaslighting other browser vendors? Oh, the Web would be a much, much better place.
Firefox and Safari have said “you what!? No way we’re implementing that as it is”. And Safari are now implementing the safe and boring part of the spec, not the part that people actually want.
If Chrome matters, Firefox doesn’t, and Safari is measured against when Chrome supports something rather than when the specification becomes stable, it sounds like you think the web is defined by “whatever Chrome supports, whenever Chrome supports it”.
I can guarantee you Firefox will eventually be running Blink because Mozilla has no vision for the future of the web anymore. Mark my words.
Positioning Chrome as the definition of the web is incredibly harmful for the long-term health of the web. A web independent of a single vendor is vital.
Where did I say that?
the difference is that Microsoft wanted to protect the Desktop platform. Google isn't in that position with the Andorid platform, but requires improvement on the Web.
That said: I fear the power Google has in that realm.
Google has ploughed ahead with File System Access in order to meet a developer desire (and occasionally user desire). Mozilla and Apple have declined to implement it (or at least the dangerous half) because no one can find an acceptable solution to the security problems.
File System Access is not currently a good web standard—in fact, it has not even progressed to being a web standard, because of these problems.