Search code examples
safariprogressive-web-apps

Sharing session between Safari and PWA


Currently, "Add to homescreen" functionality in Safari breaks the user flow, where the data persisted in localStorage/sessionStorage/cookies won't be carried over to the PWA, making user starts from logged out state in PWA even if they have logged in the Safari before.

Do we have solution for this? The solutions I asked for are:

  1. Shared storage between PWA and Safari
  2. How to open a link from safari to PWA directly? (I plan to share the session by url, which can be triggered by clicking a button)

I have searched methods for shared storage, but I haven't found a reliable one

Also tried to use a href to the link with target="_blank" but it also just opens a new tab in safari, not opening in PWA.


Solution

    There is no method available for sharing data between Safari and the PWA, or even between two installations of the same PWA, as each is considered to have a different origin.

    This will work fine on Android but not on iOS.

    The only workaround is to compute a fingerprint in Safari, store it on a remote server to identify the device, and, once the PWA is installed, compute the same fingerprint and use the remote server for recovery. You can use something like ClientJS for this purpose.

    It's noteworthy that, in my experience, this only works on iOS and not on Android.

    2)

    You cannot open a PWA using a link since a PWA can be installed multiple times on iOS (but not on Android), and the OS cannot determine which one to open. In my experience, it always opens in Safari. You also cannot store the session link in the URL before installing the PWA, hoping it will be passed through, as the PWA is installed with the start_url only.

    I understand your objectives, and I've spent time attempting similar solutions. It's challenging. I eventually opted not to pursue it and instead created a landing page on Safari to prompt users to install the PWA before proceeding.

    Good luck!