capacitor
capacitor copied to clipboard
[Feature]: Ability to add custom headers, enabling use of OPFS
Description
Ability to set custom headers - so I can use OPFS and SQLite WASM backed by OPFS
Platforms
- [X] iOS
- [X] Android
- [ ] Web
Request or proposed solution
I am trying to get the SQLite WASM build backed by OPFS working, and ran into the issue where it requires certain headers be set to work:
- https://sqlite.org/wasm/doc/trunk/persistence.md#coop-coep
- https://www.npmjs.com/package/@sqlite.org/sqlite-wasm (has example on how these headers are configured with vite, which is how I have OPFS working on Web - but on iOS / Android? there's no equivalent)
After searching I couldn't find a way to do this in Capacitor. It seems that this issue has cropped up a few times, and I think the use of the official SQLite WASM build, and OPFS will become more frequent.
It also seems like a reasonable successor to jeep-sqlite. If I understand the history of the SQLite+WASM library space - the approach of putting SQLite into IndexedDB was a sort of hack to get around not having a place to store the SQLite db file on the web client, and has some downsides (performance and ACID compliance from what I've read). OPFS would resolve those - and open up the possibility of building doing "local-first" type architectures where all platforms use the same configuration for accessing a local SQLite database.
Related issues (Closed as completed but no resolution):
- https://github.com/ionic-team/capacitor/issues/6182
- https://github.com/ionic-team/capacitor/issues/6965
Alternatives
Another option would be to update the capacitor-community/sqlite plugin to use OPFS instead of jeep-sqlite on the "web" platform.
Additional Information
My motivation for exploring alternatives to capacitor-community/sqlite is that I need access to the actual SQLite .db file, from JS (I haven't explored this much - so maybe it's possible). I've also seen some issues regarding performance issues ( https://github.com/capacitor-community/sqlite/issues/602 ) that were concerning - and I assume using the more recent / official SQLite WASM build would be more future proof.
This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed. Please see the Contributing Guide for how to create a Sample App. Thanks! Ionitron 💙
Can we get a small sample of this failing to see whats going on?
I have this need too. I'm seeking to use SQLocal (https://sqlocal.dev/guide/introduction) so my use case would probably be a simple database creation using it. I'll seek to provide a repo by the weekend.
Apologies for the delay in adding another comment.
I've done a lot more research on this now, and don't believe it's possible at the moment because Webview doesn't implement the support that's needed. Apparently (I haven't tried it yet) implementing a Service Worker is a workaround:
https://stackoverflow.com/questions/71245695/running-serviceworker-in-capacitor-app-on-ios https://dev.to/stefnotch/enabling-coop-coep-without-touching-the-server-2d3n