JavaScript Navigator locks Property

Beginner
5 min read
Updated: Nov 2026
5 examples
Property

Definition

navigator.locks is a read-only Navigator property that returns a LockManager (MDN) — the entry point for the Web Locks API. Tabs and workers on the same origin can request named locks and take turns on shared work.

Read the notes below before you rely on this property. Prefer feature detection when support is limited.

Syntax

Use navigator.locks. Start with this line.

JavaScript
navigator.locks
CallWhat it does
navigator.locksPrimary signature.

Built into the browser. Read navigator.locks on Navigator — no import required.

Library declarations
JavaScript
navigator.locks

Parameters

ParameterDescription
nameRequired. String id for the resource
callbackRequired. Runs while the lock is held
optionsOptional. mode, ifAvailable, signal, …

Return Value

Return ValueDescription
*The current value of navigator.locks.

JavaScript Examples

Example 1 — Feature Detection

Check whether navigator.locks is exposed before using the API.

JavaScript
const supported = Boolean(navigator.locks);
console.log(supported ? "Web Locks available" : "Web Locks missing");
Try It Yourself

How It Works

  1. Read the property. Missing APIs are undefined.
  2. Coerce to Boolean. Boolean(navigator.locks) is a clear yes/no.
  3. Branch early. Skip lock-based sync when unsupported.
  4. Still check HTTPS. Presence alone is not enough on insecure pages.

Example 2 — Secure Context Check

Confirm HTTPS / localhost together with navigator.locks.

JavaScript
const lines = [
  "secure: " + window.isSecureContext,
  "locks: " + Boolean(navigator.locks)
];

if (!window.isSecureContext) {
  lines.push("Serve over HTTPS to use navigator.locks");
} else if (!navigator.locks) {
  lines.push("Secure, but Web Locks not exposed");
} else {
  lines.push("Ready to call request / query");
}

console.log(lines.join("\n"));
Try It Yourself

How It Works

  1. Check isSecureContext. MDN requires a secure context for locks.
  2. Check the property. Some environments may still omit the API.
  3. Give a clear message. Helps students debug http:// vs https://.
  4. Only then call methods. Avoids confusing errors on plain HTTP.

Example 3 — Request an Exclusive Lock (MDN)

Acquire a named lock, inspect lock.name / mode, then auto-release.

JavaScript
async function runWithLock() {
  if (!navigator.locks) return "Web Locks not supported.";

  return navigator.locks.request("demo_resource", async (lock) => {
    return "held: " + lock.name + " (mode: " + lock.mode + ")";
  });
}

runWithLock().then(console.log);
Try It Yourself

How It Works

  1. Guard first. Skip when navigator.locks is missing.
  2. Request by name. "demo_resource" identifies the resource.
  3. Work in the callback. Default mode is "exclusive".
  4. Auto-release. When the async callback returns, the lock is freed and the outer Promise resolves with your return value.

Example 4 — Query Held and Pending Locks

Snapshot how many locks are held or waiting on this origin.

JavaScript
async function snapshot() {
  if (!navigator.locks) return "Web Locks not supported.";

  const state = await navigator.locks.query();
  return JSON.stringify({
    held: state.held.length,
    pending: state.pending.length
  }, null, 2);
}

snapshot().then(console.log);
Try It Yourself

How It Works

  1. Call query(). Returns a Promise with lock state.
  2. Read held. Locks currently owned on this origin.
  3. Read pending. Requests waiting for a free lock.
  4. Use for debugging. Great when a second tab seems “stuck” waiting.

Example 5 — ifAvailable Leader Check

Become the sync leader only if the lock is free right now.

JavaScript
async function tryBecomeLeader() {
  if (!navigator.locks) {
    return { ok: false, reason: "unsupported" };
  }

  return navigator.locks.request(
    "sync_leader",
    { ifAvailable: true },
    async (lock) => {
      if (!lock) return { ok: false, reason: "busy" };
      return { ok: true, name: lock.name };
    }
  );
}

tryBecomeLeader().then((r) => console.log(JSON.stringify(r)));
Try It Yourself

How It Works

  1. Pass ifAvailable: true. Do not join the wait queue.
  2. Check for null. MDN: callback gets null when the lock is busy.
  3. Act as leader only if granted. Useful for “one tab syncs” patterns.
  4. Exit fast when busy. Followers skip work instead of waiting.

Browser Support

navigator.locks is Baseline Widely available (MDN). Evergreen browsers have shipped the Web Locks API since about March 2022.

✓ Baseline · Widely available

Navigator.locks

Supported in modern Chrome, Firefox, Safari, Edge, and Opera on secure contexts. Not available in Internet Explorer.

95% Modern browser support
Google Chrome Web Locks · secure context
Full support
Mozilla Firefox Web Locks · secure context
Full support
Apple Safari Web Locks · secure context
Full support
Microsoft Edge Web Locks · Chromium
Full support
Opera Web Locks · modern versions
Full support
Internet Explorer No Web Locks / navigator.locks
Unavailable
navigator.locks Excellent

Bottom line: Safe for modern web apps on HTTPS. Always feature-detect and keep a non-lock fallback for older or insecure environments.

Frequently Asked Questions

A read-only LockManager — the Web Locks API entry point for requesting named locks and querying held/pending locks on the same origin (MDN).
No. MDN marks it Baseline Widely available (since about March 2022). It is not Deprecated, Experimental, or Non-standard.
Yes. It is available only in secure contexts (HTTPS or localhost) in supporting browsers.
Call navigator.locks.request(name, async (lock) => { … }). The callback runs while the lock is held; when the callback finishes (including awaited work), the lock is released automatically.
navigator.locks.query() returns a Promise that resolves with a snapshot of held and pending locks for the origin — useful for debugging waiters.
Pass { ifAvailable: true } when you want the lock only if it is free right now. If busy, the callback receives null instead of waiting.

Next: login

Learn how navigator.login connects to Federated Credential Management.

login tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful