Using navigator.locks.request() for cross-tab coordination instead of in-memory locks
In-memory mutexes only protect code within a single JavaScript context, so they fail when the same origin runs the same job across multiple tabs, workers, or a tab and a worker. The Web Locks API, via navigator.locks.request(), lets the browser manage ownership and queue waiting requesters across those contexts. It supports exclusive and shared modes, along with ifAvailable and steal options, and is available only in secure contexts and inside workers. The article recommends keeping the critical section small and recording progress durably, since the lock does not provide rollback and does not cover crashes or partial writes. A local mutex suffices when the race is confined to one context.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in