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,48 @@
---
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. The amount of data in session storage is the sum of the size of every value (as measured by the StructuredCloneHolder) plus the sum of every key's length.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The maximum amount of data (in bytes) that can be stored in session storage. The amount of data in session storage is the sum of the size of every value (as measured by the StructuredCloneHolder) plus the sum of every key's length.
The maximum amount of data (in bytes) that can be stored in session storage.

StructuredCloneHolder is an internal inplementation detail. Let's drop it.

May make sense to refer to getBytesInUse to query hoe much quota is used.


Its value is `10485760`.

{{WebExtExamples("h2")}}

## Browser compatibility

{{Compat}}

<!--
Copy link
Member

Choose a reason for hiding this comment

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

Let's drop this whole section.

// Copyright 2015 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ 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>
This method is supported in {{WebExtAPIRef("storage.local")}}, {{WebExtAPIRef("storage.session")}}, and {{WebExtAPIRef("storage.sync")}}. It's not supported in {{WebExtAPIRef("storage.managed")}}.

This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
> [!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).

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

## Syntax

Expand All @@ -23,16 +24,14 @@ 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).


### 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
3 changes: 3 additions & 0 deletions files/en-us/mozilla/firefox/releases/131/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ 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))

### Removals

### Other
Expand Down