Web Locks API

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.

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.

Specification

Public discussion

Status in Chromium

Blink>Storage


Enabled by default (tracking bug) in:

  • Chrome for desktop release 69
  • Chrome for Android release 69
  • Android WebView release 69
  • Opera release 56
  • Opera for Android release 56

Consensus & Standardization

After a feature ships in Chrome, the values listed here are not guaranteed to be up to date.

  • No public signals
  • No public signals
  • No public signals
  • Positive

Owner

Last updated on 2018-08-10