javascript - chrome.storage.sync.get not returning complete JS object -


i trying write chrome extension allows users login internal webpage. extension show menu containing pre-defined credentials user can pick 1 , logged corresponding web page.(think bookmarks++).

as first step, wanted write functionality accepts 'name', 'url', 'username' , 'password' information in extension options page , persist using chrome.storage.sync.set. user can have multiple sets of such information persisted using chrome.storage (e.g different usernames same website). able , options page able list saved information. time being, please ignore security issues associated client-side password encryption.

this manifest.json

{     "name": "my chrome extension",     "version": "1.0",     "manifest_version": 2,     "description": "easy login webapp",      "browser_action": {         "default_icon": "images/cloud16.png",         "default_popup": "html/popup.html"     },     "options_page": "html/options.html",     "permissions": ["<all_urls>", "storage", "unlimitedstorage"]     } 

this save handler in options page (in options.js):

function savehandler() {     var name = $("#name").val(),         url = $("#url").val(),         password = $("#password").val(),         key = date.now() + "",   //key based on currenttimeinmillis         obj = {             "id": key,             "name": name,             "url": url,             "password": password         };     chrome.storage.sync.get('login_collection', function(items) {             //create new collection if not exists         if(items && !items['login_collection']) {             items['login_collection'] = {};                  }         items['login_collection'][obj.id] = obj;         chrome.storage.sync.set(items, function() {             // notify saved.             console.log('settings saved');             chrome.storage.sync.get('login_collection', function(data) {                             console.dir(data);             });         });         $("#addurldialog").slideup();         loadexistinginfo(); //read persisted data, , show. works fine!!     }); } 

when user clicks on extension icon in toolbar, show popup html has script fetch data (using chrome.storage.get) persisted in options page. code fetch data in popup looks this:

chrome.storage.sync.get('login_collection', function(items) {     var container = $("#listcontainer"),     data = items['login_collection'];     for(item in data) {                   console.dir(item); //**outputs empty object**         $("<div></div>").text(item.name).appendto(container);     } }); 

screenshot of js console popup page

as can see, fetch able top-level object information, none of attributes. should using content scripts or background pages read data set chrome.storage.sync.set? on appreciated.

you not using for...in loop correctly. key iterated, not values.

for(key in data) {     var item = data[key];     console.dir(item);     $("<div></div>").text(item.name).appendto(container); } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -