You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To store user data for your extension, you can use either storage.sync or storage.local
Keep in mind that storing and fetching data in chrome storage is an asynchronous process so you must wait for the callback function to execute your code synchronously.
/*global chrome*/
// Setting data func
function setDataToStorage(data, callback){
chrome.storage.sync.set(data, callback);
}
// Getting data func
function getDataFromStorage(key, callback){
chrome.storage.sync.get(key, callback);
}
// Calling set data function .
let data = {"id": "1234", "name": "Jhon", "age": 24};
setDataToStorage(data, function(){
console.log("Data saved successfully!");
// Calling get data function.
getDataFromStorage(["name", "age"], function(result){
console.log('Name: ' + result.name, 'Age: ' + result.age);
})
})
Note: The above example is to just show you how to store data and fetch it.
I am calling getDataFromStorage function inside setDataToStorage callback function to make sure we will get the output. You can use it independently as per your use case.
Make sure to use /*global chrome*/ at top of your file to use any chrome API.
i am trying to access local storage using chrome api but not able to get the values. can u show me how to access it
The text was updated successfully, but these errors were encountered: