IO-Design-Team / hive_ce

Hive Community Edition - A spiritual continuation of Hive v2
https://pub.dev/packages/hive_ce
Apache License 2.0
30 stars 2 forks source link

IndexedDB inaccessible in Safari iframe #18

Closed sgehrman closed 2 months ago

sgehrman commented 2 months ago

It works on Chrome and firefox, but no prefs are saved in Safari.

sgehrman commented 2 months ago

Same issue in Hive

Rexios80 commented 2 months ago

I've used hive in safari for a long time with no issue. Are you sure you're not in a private window or something?

sgehrman commented 2 months ago

hmm. I did a quick test and it does seem to work using your example. But my customers are saying things are not getting saved. Let me get more data... I don't use a mac, I'm on linux, so it's not easy to repo on my end.

sgehrman commented 2 months ago

Hey, I have a clue and wanted you to try it. My code is running in an iFrame. I'm wondering if Safari is blocking the iFrame from writing into the Indexed Database? It works in Chrome and Firefox, but maybe Safari is blocking this?

Rexios80 commented 2 months ago

iFrames can be weird like that. Is it a headers issue maybe?

sgehrman commented 2 months ago

no idea. what headers issue?

sgehrman commented 2 months ago

Looks hopeless. It seems firebase users had a similar issue. https://github.com/firebase/firebase-js-sdk/issues/2393

Maybe you could print() a warning to the console if you detect a failure to open the indexedDB too.

Rexios80 commented 2 months ago

Just to confirm, the original hive package has the same issue?

sgehrman commented 2 months ago

yeah.

I was wondering if hive used localstorage rather than indexedDB would that work?

I'm thinking of switching to shared_preferences instead of hive (if it works)

If localStorage did work, then an ideal solution would be something like:


if (indexedDBNotSupported) {
  useLocalstorage();
} else {
  useIndexedDB();
}

would that be easy to implement in hive_ce?

Rexios80 commented 2 months ago

Do we know what causes Safari to not support indexed db in some cases? Shared preferences isn't meant to store large amounts of data, so performance may suffer depending on your use-case.

sgehrman commented 2 months ago

Yeah, Safari fails when opening indexedDB in an iframe. See that firebase link above

all my prefs are stored using hive. just strings, ints and bools. Nothing large.

Rexios80 commented 2 months ago

If you're just storing app settings then shared preferences is the better solution anyways.

sgehrman commented 2 months ago

sure, the only problem is I already have linux/windows users and I would have to migrate everything over, but I'll have to deal with it.

Thanks.

sgehrman commented 2 months ago

I tried shared_preferences and that doesn't work in Safari either at least in my case where it's a browser extension that runs on localhost. It might work for a normal domain.