I consider creating a webapp. The webapp must be capable of working offline and syncing the data when connection is available, so I think I should use localStorage.
However, I am concerned about users that open the app in multiple tabs multiple times. I believe this has no reasonable use case, but I fear of parallel access to a single localStorage and race conditions arising from that.
The easiest approach seems to be to implement run once behavior, so when the user tries to (rather accidentally) open the app second time, they get a warning or they get ideally switched to the existing app. I know this is not holly grail of UX, but it might be a reasonable tradeoff between UX and development costs. However, I am not sure how to properly implement it. Maybe I could use window names, but this look much like a hack that can easily break.
Alternatively, I am thinking of a more advanced variant that allows multiple instances of the same page, but:
- it syncs the local copy of data across them and
- it ensures exactly one instance of background sync
This looks like a task for ServiceWorkers, but their compatibility is limited. I am mostly concerned about iOS, which seems to have some fresh support for them in beta version.
I am not sure which approach to choose and how to properly implement it. I'll probably take the approach that looks easier, unless it is an ugly hack or there is some major drawback.
Some context on this: It is an internal app that is expected to be used by few users on their own devices. So, I expect various devices, mostly Android and iOS. It might be also used on a laptop. The app is just a simplified domain-specific interface for easy data entrance into some Google Sheet, which works as a storage backend. We can educate the users of the app a bit (that's the reason why I consider run once restriction as acceptable), but we should not expect any IT skills from them. So I do not want to rely on user not opening the webapp twice.