MDN self-hosted library · e01.org

Lock: mode property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
// Should show "exclusive" (the default)
navigator.locks.request("my_resource", showLockProperties);

// Should show "exclusive"
navigator.locks.request(
  "my_resource",
  { mode: "exclusive" },
  showLockProperties,
);

// Should show "shared"
navigator.locks.request("my_resource", { mode: "shared" }, showLockProperties);

function showLockProperties(lock) {
  console.log(`The lock name is: ${lock.name}`);
  console.log(`The lock mode is: ${lock.mode}`);
}