SharedStorage: clear() method
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Phương thức clear() của giao diện SharedStorage xóa bộ lưu trữ chia sẻ của nguồn gốc hiện tại, xóa toàn bộ dữ liệu.
Cú pháp
clear()
Tham số
Không có.
Giá trị trả về
Một Promise thực hiện với undefined.
Ngoại lệ
Promisetừ chối vớiTypeErrornếu:- Cơ sở dữ liệu không được xóa thành công do bộ lưu trữ chia sẻ không khả dụng (ví dụ: bị tắt bởi cài đặt trình duyệt).
- Trang gọi không có Shared Storage API được bao gồm trong quy trình đăng ký privacy sandbox thành công.
- Trong trường hợp
WorkletSharedStorage,Promisetừ chối vớiTypeErrornếu module worklet chưa được thêm bằngSharedStorageWorklet.addModule().
Note:
Trong trường hợp WindowSharedStorage, nếu thao tác clear() không ghi thành công vào cơ sở dữ liệu vì lý do khác ngoài bộ lưu trữ chia sẻ không khả dụng, không có lỗi nào được ném ra, thao tác vẫn thực hiện với undefined.
Ví dụ
window.sharedStorage.clear().then(() => console.log("Shared storage cleared"));
Thông số kỹ thuật
| Specification |
|---|
| Shared Storage API> # dom-sharedstorage-clear> |