5

In my PWA (a calendar), the user can select a date and save it. This works fine with local storage.

But if the user now adds the PWA to his or her Homescreen ("add to homescreen"), this data will not be taken over and must be re-entered. Is there a way to access this data?

ReneP
  • 87
  • 6
  • So if the PWA is installed, your app is not writing the date entered to local storage? You cannot see it using the dev tools? – Mathias Aug 12 '19 at 13:18
  • @Mathias: Yes and no. It's like this: When I open the app in the browser (ios/safari) and enter a date, it is stored in the local storage. So far so good. Then I add the PWA to my homescreen, but the date from the local storage of the website is not taken over. The local storage is empty when I open the app from the homescreen. I have to enter the date again. – ReneP Aug 12 '19 at 17:13
  • Ah. So the Local storage for a website PWA is separate than an Installed PWA. Sorry I never knew that. The browser may consider them to to be two different sites (a guess). Specific browsers only? Does your App pass the Chrome lighthouse test as a valid PWA? – Mathias Aug 13 '19 at 00:20
  • @Mathias: That's right. It seems that they are different pages - the one you open in your browser and the one you open using the Homescreen button. I suspected the Start URL (`start_url`), but it is the same for both pages. The Lighthouse test is passed. – ReneP Aug 13 '19 at 09:15
  • 1
    This makes sense, since they are coming from two locations. Google recommends using only IndexedDB for local storage in a PWA. I don't see that it should work any better in this case, but it might be worth a try. See https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/offline-for-pwa – TimHayes Aug 13 '19 at 13:19
  • @TimHayes: I have now tried this with indexedDB. The result is the same. You're right, there are two different locations and the stored date is not taken over. Can the homescreen-PWA access the browser-PWA data? Probably not, right? – ReneP Aug 15 '19 at 16:32
  • @user2402747 That is the way it seems to me... which is both unfortunate and understandable. But it doesn't look like it was always this way - if you look at the way Apple handled the "add to home screen" apps which were similar to PWAs https://stackoverflow.com/questions/21109615/ios7-safari-saving-to-home-screen-and-persist-token – TimHayes Aug 15 '19 at 19:28
  • @TimHayes I wanted to avoid doing this via the URL for privacy reasons, but if it's the only way in ios, I have to. Thank you for the link and for yor time! – ReneP Aug 16 '19 at 07:51
  • @user2402747 No problem, I'm happy to help! I can see this impacting some of my future projects and would like know how to work around it. – TimHayes Aug 16 '19 at 14:13
  • I recently (2022) developed a PWA that uses IndexedDB - on Windows, Android, and iOS, I have seen that the same data is shared between the homescreen and browser versions. – HorusKol Apr 10 '22 at 23:52
  • @HorusKol Thank you for the answer! Can you explain how you did that? Because even with indexedDB I have the problem that the data is not copied when the PWA is added to the homescreen. Neither in the one, nor in the other direction. – ReneP Apr 16 '22 at 18:40
  • Hi, I'm sorry, but I was mistaken - I was just testing again yesterday and the data storage on iOS is separated (installed/Safari/Chrome). – HorusKol Apr 16 '22 at 20:10

0 Answers0