Example 1 — Feature Detection
Check whether navigator.locks is exposed before using the API.
const supported = Boolean(navigator.locks);
console.log(supported ? "Web Locks available" : "Web Locks missing"); How It Works
- Read the property. Missing APIs are
undefined. - Coerce to Boolean.
Boolean(navigator.locks)is a clear yes/no. - Branch early. Skip lock-based sync when unsupported.
- Still check HTTPS. Presence alone is not enough on insecure pages.

