IndexedDB in latest iOS

Hi,

I know, it is not directly related to Ionic, but as there are a lot of mobile developers around, I would like to see if someone has similar issues at the moment.

Our app is using IndexedDB to store certain data. Since the latest iOS update (14.6), we experience big issues in accessing this database. When the app starts (both the native package, and the website in Safari browser), the app is not able to open the database. The call simply does not come back, no onerror, onsuccess or similar callback is called.

Thanks, Heiner

We are having exactly the same issue. We have resorted to retrying the indexedDB.open(…) if the onsuccess callback is not invoked within a short timeframe. However this feels very ‘hacky’.

Can confirm we only experience this on iOS 14.6.

I would suggest using Ionic Storage here. Its initialization code ensures that things are ready to be interacted with before trying to do so. Or, if you don’t want to do that, you could at least look at its source and do what it does.

Same here. Horror. PWA, firease and ionic storage.

Losing connection to IndexDB.

And somehow I cannot debug anymore with Techpreviewer. You have the same issue? Web Inspector | Apple Developer Forums

I am not sure if the suggestion of @rapropos helps. I am using that one with Indexdb as driver, as per documentation.

I am not sure if I want to revert to localstorage instead of indexDB.

Biggest issue is instability.

btw, earlier I had similar issues, which were somehow related to me using firebase and its oauth stuff - that one also uses indexdb under the hood to persist stuff across redirect logins and such. Somehow I got that fixed to reduce the number of writes to storage - refactoring a large chunk of the code. iOS PWA Firebase and Storage blocks - can't find issue

And on a separate note, I noticed when the PWA has an unhandled exception, Safari freaks out really easily.

Thanks but I don’t think it’s an issue about trying to interact with .indexedDB too early. Even delaying our initialisation code in a setTimeout(…, 5000) exhibits the same issue.

Our implementation was running fine until iOS 14.6.

@GSherriff - related to this, are you having issues using web inspector on Safari Techpreview? It is no longer showing console.log, so I cant debug this issue conveniently…

@Tommertom i haven’t got the latest tech preview so can’t confirm, sorry! We did however end up writing logging stuff out to the document.body for other reasons (don’t ask!)

1 Like

Hey, that got me thinking about a new way of showing console log!

I put a div before the ion-app and my logger service the writes to the inner-html of it.

When I style it as follows, I can see through and use the app :slight_smile:

<div id="log" style="position:absolute;z-index:100; pointer-events: none;"></div>

Let’s see if I can debug this way…

Can affected people post Safari versions? It could help with wading through IndexedDB Webkit bugs.

14.5.1 - will look it through.thx

The IndexedDB connect issue appeared in iOS 14.6.

Like people already said before, it doesn’t seem to be a timing issue. Even delaying the connect by several seconds does not change anything

I do have those issues with the current Safari on Big Sur. Using TP (downloaded yesterday) solved it.

I believe, but have not proven, that in iOS 14.6 the indexedDB engine is now lazy loaded and there is a bug in that initialisation code. I THINK to workaround this there needs to be a delay between first accessing the window.indexedDB property (which triggers the lazy initialisation) and calling window.indexedDB.open(…).

Yes! With me, Catalina, it is working now on regular Safari, not TechPreview… Thx for getting me to think and try!

Will start debugging the indexeddb - if possible

That was a good idea. As we know, our app will use the database, and will use it rather early during startup, I added just a simple line in app.module.ts:

export class AppModule {
    constructor() {
        // Touch DB Factory to make sure, it is properly initialized even on iOS 14.6
        const db = window.indexedDB;
    }
}

Since then I couldn’t see any problems. Still, it’s a race condition, but the startup of the app takes long enough. Maybe I will think about an additional safety net, but for now, it helps a lot.

Maybe even in main.ts? which is even earlier? Or even in index.html?

Still no solution on my end. - I notice the app (PWA on iOS Angular 11) does not stabilise in order to register the service worker (ApplicationRef.isStable). IndexedDB so it still seems.

Strangely, no issues on another app, PWA on iOS Angular 8

No issues reported (yet) with the use on PWA angular 9 and 12. I do use the wrapper of Jake Archibald.

1 Like