https://github.com/aermin/web-locks
Web Locks API(navigator.locks) polyfill, implement according to Specification
https://github.com/aermin/web-locks
navigator-locks navigator-locks-api-polyfill navigator-locks-polyfill web-locks web-locks-api-polyfill web-locks-polyfill
Last synced: about 1 year ago
JSON representation
Web Locks API(navigator.locks) polyfill, implement according to Specification
- Host: GitHub
- URL: https://github.com/aermin/web-locks
- Owner: aermin
- License: mit
- Created: 2020-11-22T02:26:08.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-02-20T08:05:02.000Z (over 3 years ago)
- Last Synced: 2025-05-04T06:03:28.314Z (about 1 year ago)
- Topics: navigator-locks, navigator-locks-api-polyfill, navigator-locks-polyfill, web-locks, web-locks-api-polyfill, web-locks-polyfill
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/navigator.locks
- Size: 322 KB
- Stars: 60
- Watchers: 3
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
web-locks polyfill




a [Web Locks API](https://developer.mozilla.org/en-US/docs/Web/API/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](https://wicg.github.io/web-locks/)
- implement the unit test according to [web-platform-test](https://github.com/web-platform-tests/wpt/tree/master/web-locks)
- implement all the features of [Web Locks API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API)
## Installation
```
// with npm
npm install navigator.locks
// with yarn
yarn add navigator.locks
```
## Usage
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](https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API)
## Online demo
[demo link](https://ytqq5.csb.app/)
> You could open two tabs of this API unsupported browser, operate the lock buttons to experience
## Process
### All API ✅
- navigator.locks.request
- navigator.locks.request options:
*mode*: `exclusive` | `shared`
*ifAvailable*
*steal*
*signal*
- navigator.locks.query
### CI/CD ✅
### Unit test ✅