StorageArea.setAccessLevel()

Sets the access level for the storage area.

Use this method to:

  • Expose the session storage area to content scripts. Unlike other storage areas, by default, storage.session is only available to privileged (trusted) extension contexts by default.
  • Restrict content scripts' access to local, managed, and sync storage areas. By default, these storage areas are exposed to all extension contexts, including content scripts.

Syntax

js
await browser.storage.<storageType>.setAccessLevel(
  accessLevel             // string
)

Where <storageType> is any of the storage types: storage.local, storage.managed, storage.session, or storage.sync.

Parameters

accessLevel

String. The access level of the storage area. Possible values are TRUSTED_CONTEXTS or TRUSTED_AND_UNTRUSTED_CONTEXTS.

Return value

A Promise that is fulfilled with no arguments if the operation succeeded. If the operation failed, the promise is rejected with an error message.

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
setAccessLevel
Chrome – Full support
Chrome 96 (Release date: 2021-11-15)
footnote
footnote Supported by the session storage area from Chrome 96.
footnote Supported by all storage areas from Chrome 140.
Edge – Full support
Edge 96 (Release date: 2021-11-19)
footnote
footnote Supported by the session storage area from Edge 96.
footnote Supported by all storage areas from Edge 140.
Firefox – No support
Firefox
footnote
footnote See bug 1724754
Opera – Full support
Opera 82 (Release date: 2021-12-02)
footnote
footnote Supported by the session storage area from Opera 82.
footnote Supported by all storage areas from Opera 124.
Safari – Full support
Safari 17.1 (Release date: 2023-10-25)
footnote
footnote Only supported for the session storage area.
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1724754
Safari on iOS – Full support
Safari on iOS 17.1 (Release date: 2023-10-25)
footnote
footnote Only supported for the session storage area.

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

Note: This API is based on Chromium's chrome.storage API. This documentation is derived from storage.json in the Chromium code.