This Polyfill provides basic support for chrome.storage.sync and chrome.storage.local API outside of chrome extension runtime. It is using window.localStorage browser API to store data.
Inject the script at the top of the script and call following function
chromeStoragePolyfill(dbName?);
If you don't provide any database name as argument for Local Stroage then CHROME_STORAGE_API_WRAPPER_DB will be used as default.
IMPORTANT! QUOTA limit for chrome.storage.sync was not regarded.
set
chrome.storage.sync.set({key:value},cb?)
Callback is optional which has data as argument. If the Callback is not provided then Promise is returned with data.
get
chrome.storage.sync.get(['key1','key2'],cb?)
Callback is optional which has data as argument. If the Callback is not provided then Promise is returned with data with related key.
clear
chrome.storage.sync.clear(cb?)
Callback is optional which has data as argument. If the Callback is not provided then Promise is returned without any data.
set
chrome.storage.local.set({key:value},cb?)
Callback is optional which has data as argument. If the Callback is not provided then Promise is returned with data.
get
chrome.storage.local.get(['key1','key2'],cb?)
Callback is optional which has data as argument. If the Callback is not provided then Promise is returned with data with related key.
clear
chrome.storage.local.clear(cb?)
Callback is optional which has data as argument. If the Callback is not provided then Promise is returned without any data.
Great work! One minor issue
chrome.storage.sync.get('key')
doesn't work same way as original.