I’ve stumbled upon a peculiar issue while implementing LocalForage in my web app, and I’m wondering if anyone else has encountered this or if I’m doing something wrong here.
I’m using LocalForage to handle data persistence with IndexedDB as the storage engine. The architecture is pretty straightforward:
- Main thread handles data saving via LocalForage
- WebWorker reads the stored data and sends it to the server
- Everything runs smoothly on Android, but not on iOS.
On iOS, if you navigate away from the page while either reading or writing data, the IndexedDB access gets completely blocked – you can’t read or write anything until you reset the browser.
Here’s a simplified version of what I’m doing:
// Main thread
localforage.setItem('key', value).then(() => {
// This works fine... until it doesn't
});
// Web Worker
localforage.getItem('key').then(value => {
// This is where iOS decides to throw a tantrum
});
Steps to reproduce:
- Open this demo on iOS
- Start a save/read operation
- Navigate to a different page during the operation
- IndexedDB is now blocked
The only way to fix this is a full browser reset.
My questions are:
- Has anyone else run into this iOS-specific behavior?
- Is this a known limitation of IndexedDB/LocalForage on iOS?
- Are there any workarounds?
Environment details:
- iOS: Tested on 16.7.10, also reproduced on lower and higher versions
- Browser: Safari and other iOS browsers (they all use WebKit anyway)
- LocalForage: Latest version
- IndexedDB: Used as storage driver