SharedStorage: clear() 方法
SharedStorage 介面的 clear() 方法會清除當前源的共享儲存,並從中移除所有資料。
語法
js
clear()
引數
無。
返回值
一個 Promise,它將以 undefined 解析。
異常
- 如果出現以下情況,
Promise會以TypeError拒絕:- 由於共享儲存不可用(例如,在瀏覽器設定中被停用),資料庫未能成功清除。
- 呼叫站點未在成功的 隱私沙盒註冊流程中包含共享儲存 API。
- 對於
WorkletSharedStorage,如果未透過SharedStorageWorklet.addModule()新增 worklet 模組,Promise會以TypeError拒絕。
注意:對於 WindowSharedStorage,如果 clear() 操作由於共享儲存不可用以外的原因未能成功寫入資料庫,則不會丟擲錯誤 — 操作仍會以 undefined fulfilled。
示例
js
window.sharedStorage.clear().then(() => console.log("Shared storage cleared"));
規範
| 規範 |
|---|
| 共享儲存 API # dom-sharedstorage-clear |
瀏覽器相容性
載入中…