Sync storage

It uses synchronized storage under the hood.

TIP

Don't forget to update your extension permissions, edit your manifest.json with:

{
  "permissions": ["storage"]
}

WARNING

If you are writing a web extension for Firefox, you must set an ID for your extension using the applications manifest.json key.

{
  "applications": {
    "gecko": {
      "id": "<your extension ID>"
    }
  }
}

Usage

import { writeToSyncStorage, readFromSyncStorage } from '@kocal/web-extension-library';

// Write
writeToSyncStorage({ fruits: ['apple', 'banana'], vegetables: ['carrot'] })
  .then(() => console.log('Items have been stored'))
  .catch(err => console.error(err));
    
// Read an item
readFromSyncStorage('fruits')
  .then(items => {
    console.log(items); // { fruits: ['apple', 'banana'] }
  })
  .catch(err => console.error(err));

// Read every items 
readFromSyncStorage()
  .then(items => {
    console.log(items); // { fruits: ['apple', 'banana'], vegetables: ['carrot'] }
  })
  .catch(err => console.error(err));