I am making a chrome extension, and I am using chrome storage to store a variable. Actually I am first inputing a timer from user, and then refreshing the page after every T seconds those are given as input by user. So to store this time I used chrome storage like this :
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
var currentTimer = request.timer;
if(currentTimer!=null){
currentTimer = currentTimer*1000;
alert(currentTimer);
chrome.storage.sync.set({'x': currentTimer}, function() {
console.log(currentTimer);
});
}
if(currentTimer==null){
chrome.storage.sync.get('x', function(items){
currentTimer = items.value;
});
//Here currentTimer is undefined.
}
});
Can anyone help why currentTimer is still undefined. I am debugging for very long time, but could not arrive at a solution.
The problem is that as soon as page is refreshed currentTimer will get NULL value as it is been entered only once by user.