Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage.session quota enforcement #35629

Merged
merged 11 commits into from
Oct 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ The amount of data that an extension can store in the session storage area is li

When the browser stops, all session storage is cleared. When the extension is uninstalled, its associated session storage is cleared.

## Properties

- {{WebExtAPIRef("storage.session.QUOTA_BYTES")}}
- : The maximum amount of data (in bytes) that can be stored in session storage.

## Methods

The `session` object implements the methods defined on the {{WebExtAPIRef("storage.StorageArea")}} type:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: storage.session.QUOTA_BYTES
slug: Mozilla/Add-ons/WebExtensions/API/storage/session/QUOTA_BYTES
page-type: webextension-api-property
browser-compat: webextensions.api.storage.session.QUOTA_BYTES
---

{{AddonSidebar}}

The maximum amount of data (in bytes) that can be stored in session storage. Use {{WebExtAPIRef("storage.StorageArea.getBytesInUse()", "storage.session.getBytesInUse()")}} to determine the amount of stored data.

Its value is `10485760`.

{{WebExtExamples("h2")}}

## Browser compatibility

{{Compat}}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
let clearing = browser.storage.<storageType>.clear()
```

`<storageType>` is one of the writable storage types — {{WebExtAPIRef("storage.local")}}, {{WebExtAPIRef("storage.session")}}, or {{WebExtAPIRef("storage.sync")}}
Where `<storageType>` is one of the writable storage types — {{WebExtAPIRef("storage.local")}}, {{WebExtAPIRef("storage.session")}}, or {{WebExtAPIRef("storage.sync")}}

### Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let results = browser.storage.<storageType>.get(
)
```

`<storageType>` will be one of the writable storage types — {{WebExtAPIRef("storage.sync", "sync")}}, {{WebExtAPIRef("storage.local", "local")}}, or {{WebExtAPIRef("storage.managed", "managed")}}.
Where `<storageType>` is one of the storage types — {{WebExtAPIRef("storage.sync", "sync")}}, {{WebExtAPIRef("storage.local", "local")}}, {{WebExtAPIRef("storage.session", "session")}}, or {{WebExtAPIRef("storage.managed", "managed")}}.

### Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ browser-compat: webextensions.api.storage.StorageArea.getBytesInUse

{{AddonSidebar}}

Gets the amount of storage space, in bytes, used one or more items being stored in the storage area.
Gets the amount of storage space, in bytes, used by one or more items stored in the storage area.

This function only exists in browser.storage.sync
It does not exist in browser.storage.local
See <https://bugzil.la/1385832>
> [!NOTE]
> Firefox only provided support in {{WebExtAPIRef("storage.session")}} from Firefox 131. Firefox doesn't provide this method in {{WebExtAPIRef("storage.sync")}}, see [Firefox bug 1385832](https://bugzil.la/1385832). Firefox doesn't provide this method in {{WebExtAPIRef("storage.managed")}}.
rebloor marked this conversation as resolved.
Show resolved Hide resolved

This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
This is an asynchronous method that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).

## Syntax

Expand All @@ -23,16 +22,18 @@ let gettingSpace = browser.storage.<storageType>.getBytesInUse(
)
```

`<storageType>` can only be {{WebExtAPIRef("storage.sync")}}, not {{WebExtAPIRef("storage.local")}} because of [this bug](https://bugzil.la/1385832).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<storageType> refers to the fragment in the code sample. Let's keep it but refer to all formats that are supported. For example, see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/remove

While looking at other docs I noticed that "writable" should be dropped from https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/get . Let's drop it (managed storage is not writable).

Where `<storageType>` is one of the storage types — {{WebExtAPIRef("storage.sync", "sync")}}, {{WebExtAPIRef("storage.local", "local")}}, {{WebExtAPIRef("storage.session", "session")}}, or {{WebExtAPIRef("storage.managed", "managed")}}.

In Firefox, `<storageType>` can't be {{WebExtAPIRef("storage.local")}}, because of [bug 1385832](https://bugzil.la/1385832).

### Parameters

- `keys`
- : A key (string) or keys (an array of strings) to identify the item(s) whose storage space you want to retrieve. If an empty array is passed in, 0 will be returned. If you pass `null` or `undefined` here, the function will return the space used by the entire storage area.
- : A key (string) or keys (an array of strings) to identify the items whose storage space you want to retrieve. If an empty array is passed in, 0 is returned. If you pass `null` or `undefined`, the function returns the space used by the entire storage area.

### Return value

A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an integer, `bytesUsed`, representing the storage space used by the objects that were specified in `keys`. If the operation failed, the promise will be rejected with an error message.
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is fulfilled with an integer, `bytesUsed`, representing the storage space used by the objects specified in `keys`. If the operation fails, the promise is rejected with an error message.

## Browser compatibility

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let removingItem = browser.storage.<storageType>.remove(
)
```

`<storageType>` is one of the writable storage types — {{WebExtAPIRef("storage.local")}}, {{WebExtAPIRef("storage.session")}}, or {{WebExtAPIRef("storage.sync")}}.
Where `<storageType>` is one of the writable storage types — {{WebExtAPIRef("storage.local")}}, {{WebExtAPIRef("storage.session")}}, or {{WebExtAPIRef("storage.sync")}}.

### Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let settingItem = browser.storage.<storageType>.set(
)
```

`<storageType>` is one of the writable storage types — {{WebExtAPIRef("storage.local")}}, {{WebExtAPIRef("storage.session")}}, or {{WebExtAPIRef("storage.sync")}}.
Where `<storageType>` is one of the writable storage types — {{WebExtAPIRef("storage.local")}}, {{WebExtAPIRef("storage.session")}}, or {{WebExtAPIRef("storage.sync")}}.

### Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ await browser.storage.<storageType>.setAccessLevel(
)
```

`<storageType>` can be the {{WebExtAPIRef("storage.session")}} storage type.
Where `<storageType>` is the {{WebExtAPIRef("storage.session")}} storage type.

### Parameters

Expand Down
2 changes: 2 additions & 0 deletions files/en-us/mozilla/firefox/releases/131/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ This article provides information about the changes in Firefox 131 that affect d

## Changes for add-on developers

- The 10 MB quota for data stored by the {{WebExtAPIRef("storage.session")}} API is now enforced in Firefox Nightly 131. Previously, Firefox didn't implement this quota. This enforcement rolls out to release versions of Firefox from version 134 ([Firefox bug 1915688](https://bugzil.la/1915688)). This enables extensions that rely on the previous behavior to correct any issues. ([Firefox bug 1908925](https://bugzil.la/1908925))
- {{WebExtAPIRef("storage.session")}} now supports the {{WebExtAPIRef("storage.StorageArea.getBytesInUse()")}} API and the {{WebExtAPIRef("storage.session.QUOTA_BYTES")}} property. ([Firefox bug 1908925](https://bugzil.la/1908925))
- {{WebExtAPIRef("tabs.onUpdated")}} is now triggered when `openerTabId` is changed through `tabs.update()` ([Firefox bug 1409262](https://bugzil.la/1409262)).
- {{WebExtAPIRef("tabs.update")}} now accepts `openerTabId` set to `-1` to clear `openerTabId` ([Firefox bug 1409262](https://bugzil.la/1409262)).

Expand Down