@wranggle/storage-chrome-adapter

Use chrome.storage APIs as underlying store for WranggleStorage feature layers

Usage no npm install needed!

<script type="module">
  import wranggleStorageChromeAdapter from 'https://cdn.skypack.dev/@wranggle/storage-chrome-adapter';
</script>

README

ChromeAdapter

The ChromeAdapter lets WranggleStorage use the Google Chrome Storage API for its underlying persistent store in a browser extension.

Constructing WranggleStorage with ChromeAdapter

You can apply this adapter using the chrome or chromeSynchronized shortcuts when constructing your WranggleStorage instance.

chrome specifies the chrome.storage.local API, and chromeSynchronized specifies the chrome.storage.sync API.

Eg:

const store = new WranggleStorage({ chrome: true }); // or new WranggleStorage('chrome')

Installing From Individual Packages

For a web page, it is easiest to use the @wranggle/storage-web bundle.

Or you can add/install individual packages:

  1. Add the @wranggle/storage-core and @wranggle/storage-chrome-adapter packages to your project:

    # From the command line using yarn:
    yarn add @wranggle/storage-core @wranggle/storage-chrome-adapter
    
    # or with npm:
    npm install @wranggle/storage-core @wranggle/storage-chrome-adapter
    
  2. In your JavaScript, import or require the packages:

    import WranggleStorage from '@wranggle/storage-core'; 
    import ChromeAdapter from '@wranggle/storage-chrome-adapter'
    // or:
    const WranggleStorage = require('@wranggle/storage-core');
    const ChromeAdapter = require('@wranggle/storage-chrome-adapter')
    
  3. Instantiate your store:

    const store = new WranggleStorage({ chrome: true });
    

    Or do so without the construction shortcut:

    const store = new WranggleStorage({ persist: new ChromeAdapter({ location: 'local' }));