support Web Locks API work in major browsers
npm install navigator.locks!push workflow
!release workflow
!npm
!license
a Web Locks API polyfill, work when the browser does not support web lock API: navigator.lock, resolve the browser compatibility issue.
- 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
``
// with npm
npm install navigator.locks
// with yarn
yarn add navigator.locks
`
Just import It.
`js
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.
});
`
`ts`
// if you use Typescript, could import these types to use
import type {
LockManager,
Lock,
LockInfo,
LockManagerSnapshot,
LocksInfo,
} from "navigator.locks";
> navigator.locks API usage follow MDN API Doc
> You could open two tabs of this API unsupported browser, operate the lock buttons to experience
- navigator.locks.request
- navigator.locks.request options:
mode: exclusive | shared`
ifAvailable
steal
signal
- navigator.locks.query