diff options
Diffstat (limited to 'source/helpers/used-storage.ts')
-rw-r--r-- | source/helpers/used-storage.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/source/helpers/used-storage.ts b/source/helpers/used-storage.ts new file mode 100644 index 00000000..8a95bf18 --- /dev/null +++ b/source/helpers/used-storage.ts @@ -0,0 +1,10 @@ +/** `getBytesInUse` polyfill */ +export default async function getStorageBytesInUse(area: 'local' | 'sync'): Promise<any> { + const storage = browser.storage[area]; + // From https://bugzilla.mozilla.org/show_bug.cgi?id=1385832#c20 + return 'getBytesInUse' in storage ? storage.getBytesInUse() : new TextEncoder().encode( + Object.entries(await storage.get()) + .map(([key, value]) => key + JSON.stringify(value)) + .join(''), + ).length; +} |