如何檢查我的google chrome擴展程序中的存儲是否爲空?我嘗試了很多可能性,但沒有爲我工作。谷歌Chrome擴展如何檢查存儲是否爲空?
0
A
回答
1
這很簡單。
要獲得當前正在使用的存儲字節數,可以使用chrome.storage API。
如果您將擴展詳細信息存儲在名爲'settings'的對象中,則可以通過以下方式檢索正在使用的字節數。
function logBytes(bytes) {
console.log(bytes);
}
// gets the number of bytes used in sync storage area
chrome.storage.sync.getBytesInUse(['settings'], logBytes);
// gets the number of bytes used in the local storage area
chrome.storage.local.getBytesInUse(['settings'], logBytes]);
的getBytesInUse參數採用一個字符串數組或一個字符串,表示存儲數據的要計數的字節的按鍵的每個字符串。
如果您的擴展沒有使用任何空格(空),您將使用零字節。
更多文檔,Chrome Storage API
擴展在wOxxOm的評論可以發現,你可以在存儲通過執行以下保持的當前對象:在鍵名
function logBytes(bytes) {
console.log(bytes);
}
function getSyncBytes(settings) {
var keys = Object.keys(settings);
chrome.storage.sync.getBytesInUse(keys, logBytes);
}
function getLocalBytes(settings) {
var keys = Object.keys(settings);
chrome.storage.local.getBytesInUse(keys, logBytes);
}
chrome.storage.sync.get(null, getSyncBytes);
chrome.storage.local.get(null, getLocalBytes);
+0
非常感謝!你不相信我正在研究這個問題多久了! – Doppler
+0
@多普勒不是問題!我只是擴展了答案,展示瞭如何通過擴展wOxxOm的評論來獲得擴展使用的所有空間。 –
相關問題
- 1. 如何檢查是否有新版本的谷歌Chrome擴展
- 2. 谷歌Chrome擴展
- 3. 如何查看/檢查Chrome擴展的本地存儲?
- 4. 谷歌Chrome Socket API擴展
- 5. 在谷歌Chrome擴展
- 6. 檢查 - Chrome擴展
- 7. 檢查是否通過Chrome擴展存在從清單
- 8. 如何生成的appid爲谷歌Chrome擴展
- 9. 谷歌瀏覽器擴展程序:是否有任何標籤存儲?
- 10. 從Chrome擴展如何檢查頁面上是否存在網元?
- 11. 翻譯谷歌Chrome擴展HTML表單
- 12. 谷歌Chrome擴展 - 重定向
- 13. 離線谷歌Chrome瀏覽器擴展
- 14. 自動化谷歌Chrome擴展包裝
- 15. 更改谷歌Chrome網頁的擴展
- 16. 谷歌Chrome擴展document.title時不工作
- 17. 谷歌Chrome擴展的Facebook JavaScript API
- 18. 谷歌Chrome擴展怪異渲染
- 19. 谷歌Chrome擴展HTTPS AJAX請求
- 20. 谷歌Chrome擴展:webdb或不?
- 21. 谷歌Chrome擴展包錯誤
- 22. 谷歌Chrome擴展webrequest攔截
- 23. 谷歌Chrome擴展POST VS GET
- 24. 谷歌翻譯API的Chrome擴展
- 25. 值無效:谷歌Chrome擴展
- 26. 谷歌Chrome擴展:不拋出錯誤?
- 27. 如何從URL中檢查.html擴展名是否存在?
- 28. 如何檢查文件是否存在文件擴展名? C#
- 29. 如何查看我已安裝的Chrome擴展程序的存儲空間?
- 30. Chrome擴展:如何檢測是否使用內容腳本安裝了擴展
使用'null' [ .get](https://developer.chrome.com/extensions/storage#method-StorageArea-get),然後用Object.keys對結果中的鍵進行計數。 – wOxxOm