I have a small snippet that works with LocalStorage, but I still canβt get it working on the Chrome Storage scheme.
When my application starts, I check the variable in localStorage
var bookNarration=parseInt(localStorage.getItem("narration"));
If this variable is undefined, it means that my application was opened for the first time, and after processing bookLanguage, I switched 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 as follows:
var bookNarration=parseInt(chrome.storage.local.get("narration"));
But I immediately get this error:
A call to the get (string) form does not match the definition of get (optional string or array or object keys, function callback)
I searched for many hours trying to find a solution, but I can't get it to work. I believe that I just need to check if a value is defined, so if it is not, I could use the set () method to store the default value.
Juan David Saab
source share