0

I am storing an array URLarry, using chrome.storage.sync.set in background.js and accessing it from options.js. Everything is running perfectly fine. I can use the URLarray in options.js with no problem. But when I shutdown chrome and reopen it, all the data disappears. Please advice.

background.js

 save["myKey"] = URLarray; chrome.storage.sync.set(save, function() { // console.log('Settings saved'); }); 

URLarray is populated as follows:

URLarray.push({website: websiteName, time:0, startTime:0, endTime:0}); 

options.js

chrome.storage.sync.get('myKey', function (obj) { // console.log('myKey', obj); x = obj.myKey; console.log(x); } 

manifest.json

{ "name": "Animated Page Action", "description": "This extension adds an animated browser action to the toolbar.", "version": "1.2", "background": { "scripts": ["jquery-3.1.1.min.js","background.js"] }, "page_action": { "default_title": "First icon", "default_icon": "icon_0.png" }, "options_page": "options.html", "permissions": ["tabs","storage"], "manifest_version": 2 } 
6
  • likely an issue with your hardware. try on a different computer. Commented Nov 6, 2016 at 12:50
  • Hi @ZigMandel, I did as you say but no success. Can you tell any other way to do this? Commented Nov 6, 2016 at 14:16
  • to troubleshoot, try instead saving JSON.stringify(array) and see if that one survives. Commented Nov 6, 2016 at 16:41
  • URLarray is a simple array so the problem is elsewhere. The posted code isn't enough to diagnose it. Use the devtools debugger to set breakpoints inside the background page script functions and check the actual values of your variables. Commented Nov 7, 2016 at 11:45
  • possible duplicate: stackoverflow.com/questions/34953717/… Commented Nov 7, 2016 at 11:58

1 Answer 1

1

Your background code (which you don't include here) never actually reads data.

It does, however, write data, using that snippet you show, which is initialized by an empty array.

So each time you open the extension again, the data in background is empty, and it overwrites the saved data. To fix this, you must first perform initialization of your background URLarray from storage.

Sign up to request clarification or add additional context in comments.

1 Comment

I am so thankful to you. I couldn't have figured it out myself. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.