7

Is it possible to share IndexedDB stores and data between a progressive web app (PWA) and stand-alone Safari on iOS? If so, what steps do I need to take to share the stores/data?

My use case is that I have a would-be PWA that uses third party authentication. The normal behavior is that when navigating to the third party authentication page, the PWA automatically opens the page in a new Safari window since it is out of scope. I would like to save the authentication token in IndexedDB from this Safari instance, open my PWA, and then load the token from IndexedDB in my PWA.

I have tested this implementation. It works fine (ie I can read the token from IndexedDB) in Safari standalone, but when I navigate back to my PWA and attempt to read the data, it doesn't exist. This suggests that the stores cannot be shared, but I am looking for a more definitive answer. I find no indication one way or the other in internet searches.

Note: local storage, session storage, and cookies are not shared between Safari and PWAs on iOS, so those solutions do not work which necessitated the use of IndexedDB

digiplant
  • 273
  • 1
  • 10
  • indexedDB is local storage – Josh May 04 '18 at 01:03
  • 1
    It can be shared between Chrome and pwa. Sadly, not with Safari though. Ideally one can use the answer proposed below of using a pop up instead. – Saurabh Rajpal May 09 '18 at 14:40
  • Also just wondering if there's a way of authenticating using Ajax call instead of toggling between separate pages. Will try sometime soon and revert if poss. – Saurabh Rajpal May 09 '18 at 14:42
  • @SaurabhRajpal, that is not possible – digiplant May 24 '18 at 17:48
  • @digiplant I have the same issue. Did you figure this out yet? – Wonka Aug 01 '18 at 18:03
  • 2
    @Wonka It is not possible to share the indexedDB instance or any other type of local storage. I solved my specific problem by creating a native java authentication function and deployed it in a AWS Lambda function behind a REST API endpoint. – digiplant Aug 03 '18 at 18:03
  • there is a workaround check this : https://stackoverflow.com/questions/62669966/how-to-maintain-login-status-in-a-pwa-initially-loaded-via-safari-14-ios-14 – Pooya Estakhri Oct 02 '20 at 11:40
  • hellow there is solved? 2021 say hi – Lonyui Nov 02 '21 at 06:00

1 Answers1

0

Rather than opening a new tab, you can use a pop up, like how it has been beautifully explained here with example and source code. The key idea used here is window.postMessage, which allows windows and frames to send data across domains to one another.

Saurabh Rajpal
  • 1,537
  • 9
  • 14