web api instance method
SharedStorage: clear() method
The clear() method of the SharedStorage interface clears the current origin’s shared storage, removing all data from it.
Syntax
clear()
Parameters
None.
Return value
A Promise that fulfills with undefined.
Exceptions
- The
Promiserejects with aTypeErrorif:- The database was not cleared successfully due to shared storage not being available (for example it is disabled using a browser setting).
- The calling site does not have the Shared Storage API included in a successful privacy sandbox enrollment process.
- In the case of
WorkletSharedStorage, thePromiserejects with aTypeErrorif the worklet module has not been added withSharedStorageWorklet.addModule().
[!NOTE] In the case of
WindowSharedStorage, if theclear()operation doesn’t successfully write to the database for a reason other than shared storage not being available, no error is thrown — the operation still fulfills withundefined.
Examples
window.sharedStorage.clear().then(() => console.log("Shared storage cleared"));
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.