如何檢查我的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. 如何生成的appid爲谷歌Chrome擴展
- 5. 谷歌瀏覽器擴展程序:是否有任何標籤存儲?
- 6. 谷歌Chrome擴展包錯誤
- 7. 谷歌Chrome擴展 - 重定向
- 8. 自動化谷歌Chrome擴展包裝
- 9. 谷歌Chrome擴展document.title時不工作
- 10. 離線谷歌Chrome瀏覽器擴展
- 11. 如何從URL中檢查.html擴展名是否存在?
- 12. 如何查看我已安裝的Chrome擴展程序的存儲空間?
- 13. Chrome擴展:如何檢測是否使用內容腳本安裝了擴展
- 14. 檢查存儲過程中的參數是否爲空或空
- 15. 在谷歌應用程序引擎,如何檢查模型是否爲空?
- 16. 在谷歌Chrome擴展中訪問保存的密碼
- 17. 檢查是否安裝了Chrome擴展程序
- 18. 如何閱讀谷歌Chrome擴展中的剪貼板文本
- 19. 如何在谷歌Chrome擴展中創建樹視圖
- 20. Chrome擴展如何插入按鈕的頁面谷歌日曆
- 21. 如何彈出我的谷歌Chrome瀏覽器擴展
- 22. 如何驗證多個谷歌用戶的Chrome擴展?
- 23. 如何將Firefox擴展移植到谷歌Chrome瀏覽器?
- 24. 如何在Chrome擴展中使用谷歌創建登錄
- 25. 檢查屬性是否存在與檢查是否爲空
- 26. 如何確定是否存在另一個Chrome(ium)擴展?
- 27. 檢測代碼是否作爲Chrome擴展程序運行
- 28. 檢查谷歌地圖是否安裝
- 29. Chrome擴展程序數據庫存儲
- 30. Chrome擴展存儲:設置/獲取值
使用'null' [ .get](https://developer.chrome.com/extensions/storage#method-StorageArea-get),然後用Object.keys對結果中的鍵進行計數。 – wOxxOm