Back to Content

StorageAccessHandle: localStorage property

files/en-us/web/api/storageaccesshandle/localstorage/index.md

latest920 B
Original Source

{{APIRef("Storage Access API")}}

The localStorage property of the {{domxref("StorageAccessHandle")}} interface returns an unpartitioned local {{domxref("Storage")}} object if access was granted, and throws a SecurityError {{DOMxRef("DOMException")}} otherwise.

Value

A {{domxref("Storage")}} object.

Examples

js
document.requestStorageAccess({ localStorage: true }).then(
  (handle) => {
    console.log("localStorage access granted");
    handle.localStorage.setItem("foo", "bar");
  },
  () => {
    console.log("localStorage access denied");
  },
);

[!NOTE] See Using the Storage Access API for a more complete example.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also