This API allows scripts running in one tab to asynchronously acquire a lock, hold it while work is performed, then release it. While held, no other script in the origin can acquire the same lock. A lock represents some potentially shared resource, identified by a name chosen by the web app. For example, if a web app running in multiple tabs wants to ensure that only one tab is syncing to the network, each tab could try to acquire a "my_net_sync" lock, but only one tab will succeed.
Specification
Status in Chromium
Enabled by default (tracking bug) in:
- Chrome for desktop release 69
- Chrome for Android release 69
- Android WebView release 69
Consensus & Standardization
After a feature ships in Chrome, the values listed here are not guaranteed to be up to date.
- No signal
- No signal
- No signal
- Positive
Owner
Search tags
locks, lock, locking,Last updated on 2020-11-09
Comments
await navigator.locks.request('my_resource', async lock => { // The code in here runs once the lock for 'my_resource' // is acquired. The lock is released once this callback // completes. const url = await look_up_in_database(); const response = await fetch(url); const body = await response.text(); await store_body_in_database(body); }); // The 'await' above completes once the lock has been released, // so code can continue running here.