Cross-browser locks with a ServiceWorker #24
Replies: 3 comments 1 reply
-
I'm not 100% sure what you're accomplishing here, but did you also try SharedWorker()? |
Beta Was this translation helpful? Give feedback.
-
Safari added the Web Locks API in its Technology Preview release 137 (12/20/21). The release notes only mention the changeset for the initial single-process implementation but I think the changeset range includes the full implementation (see r286455 and r286514). Hopefully this will reach the main release soon. |
Beta Was this translation helpful? Give feedback.
-
Safari 15.4 now supports the Web Locks API, BUT... it looks like some new features, including Web Locks and Origin Private File System, are only enabled for macOS 12 (Monterey) and not macOS 11 (Big Sur). Another long-awaited feature in 15.4, BroadcastChannel, is available on Big Sur, so perhaps Web Locks needs some Monterey operating system feature. That's a little disappointing. Monterey was released in October 2021. Unfortunately, Apple stopped updating macOS version in the Safari user agent so public market share metrics can't provide a breakdown. Looking at an older transition, macOS 10 (Catalina) reached 65.81% at 13 months when Big Sur was released, and Catalina + Big Sur reached 80% after 24 months. |
Beta Was this translation helpful? Give feedback.
-
Safari doesn't support the Web Locks API, and while you might be able to implement some form of synchronization with IndexedDB or even localStorage, a store-based approach by itself will have trouble with orphaned locks. At the moment the best cross-browser approach looks to be ServiceWorker.
ServiceWorker has its own quirks but I did get a proof-of-concept implementation working with an online demo. I didn't wrap it all up into a library because (1) I wanted to expose how it works, and (2) I don't need it for any current project.
Beta Was this translation helpful? Give feedback.
All reactions