a Web Locks API polyfill, work for the browsers which haven't support web lock API: navigator.lock
, e.g. Firefox
, Safari
, IE
.
-
implement features according to Web Locks API Specification
-
implement the unit test according to web-platform-test
-
implement all the features of Web Locks API
install this lib
npm i navigator.locks
import this lib and use it follow Web Locks API
import "navigator.locks";
navigator.locks.request("my_resource", async (lock) => {
// The lock has been acquired.
await do_something();
await do_something_else();
// Now the lock will be released.
});
// if you use Typescript, could import these types to use
import type {
LockManager,
Lock,
LockInfo,
LockManagerSnapshot,
LocksInfo,
} from "navigator.locks";
you could open this URL in two tabs, operate the lock buttons and see the page and console
-
navigator.locks.request
-
navigator.locks.request options:
mode
|ifAvailable
|steal
|signal
-
navigator.locks.query