I have a little snippet working with LocalStorage but I cannot make it work on Chrome Storage scheme yet.
When my application starts I check a variable in localStorage
var bookNarration=parseInt(localStorage.getItem("narration"));
If that variable is undefined, it means that my app has been opened for the first time and I after handle bookLanguage in a switch using the "default" declaration.
switch(window.bookNarration)
{
case 2:
window.narrationShift = window.spanishShift;
break;
case 3:
window.narrationShift = window.frenchShift;
break;
case 10:
window.narrationShift = window.neutralShift;
break;
default:
window.narrationShift = 0; }
To make it work with Chrome Storage I change my code on this way:
var bookNarration=parseInt(chrome.storage.local.get("narration"));
But I immediately get this error:
Invocation of form get(string) doesn't match definition get(optional string or array or object keys, function callback)
I have been searching for many hours trying to find a solution but I can't make it work. I thing that I just need to check if the value is already defined so if It isn't, I could use set() method to store my default value.
With the extension's background page open, just go to the developer tools by pressing F12, then go to the Application tab. In the Storage section expand Local Storage. After that, you'll see all your browser's local storage there.
sync , the stored data will automatically be synced to any Chrome browser that the user is logged into, provided the user has sync enabled. When Chrome is offline, Chrome stores the data locally. The next time the browser is online, Chrome syncs the data. Even if a user disables syncing, storage.
chrome. storage. local. get (['key'], function (result) {console. log ('Value currently is ' + result. key);}); When using storage.sync, the stored data will automatically be synced to any Chrome browser that the user is logged into, provided the user has sync enabled. When Chrome is offline, Chrome stores the data locally.
The easiest way to check storage space on Chromebook is using the Files app. Once you open the Files app, click on the 3-dot menu on the top-right corner, and it will display the remaining storage space on your Chromebook at the very bottom. 2.
Local storage is not in the cloud. Here is how to view the data: First, go the extension page of Chrome. For the extension that you want to examine, open its background page. Each extension has a "Inspect views: background page" link for this.
Chrome DevTools allows you to easily see multiple variables throughout your application. Watching variables within Sources keeps you out of the console and focused on improving your code. The Sources panel provides the ability to watch variables within your application. This is located in the watch section of the debugger sidebar.
The function expects a callback:
chrome.storage.local.get("narration", function(data)
{
if(chrome.runtime.lastError)
{
/* error */
return;
}
var bookNarration = parseInt(data.narration);
switch(bookNarration)
{
/* ... */
};
});
There's no need to use the catch now (meaning I don't know if this changed since the accepted answer and now).
You can pass in the item(s) you want along with defaults should the item not exist
chrome.storage.local.get({narration: "", num: 0, books: []}, function(data)
{
var bookNarration = parseInt(data.narration);
switch(bookNarration)
{
var numBooks= data.books.length
/* ... */
};
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With