javascript - How to sync chrome bookmarks with server in extension using API -


i creating chrome extension allows view, update, create, , remove chrome bookmarks. able load , save user's bookmarks through our server instead of syncing through google account. problem i'm having i'm not sure how sync these bookmarks across devices. since chrome bookmarks api not have method(s) load/sync tree, figure save each bookmark/folder in array on server such

[{id: "", parentid: "", index: "", title: "", url: ""}, ...] 

when user logs account on new device/browser, obtain bookmark/folder array server , loop through them. in loop, use chrome.bookmarks.get id check if bookmark exists, , if not, use create function create bookmark. problem is, there no way can see in documentation specify id of newly created bookmark/folder. if bookmark/folder created on new device/browser has different id original device/browser? using function (which requires specify id looking for) not allow me compare bookmarks correctly. there solution problem?

i ended using chrome bookmarks search function search bookmark url , title, matching see if parent id matched. kind of screwy way this, works!

function initbookmarks(){   //hit endpoint array of current bookmarks   var curbookmarks = [     {       id : "7",       parentid : "1",       index : 12,       title : "a programmatically generated bookmark",       url : "http://google.com"     },     {       id : "8",       parentid : "1",       index : 13,       title : "a programmatically generated bookmark 2",       url : "http://google.com"     }   ];    if(curbookmarks.length > 0){     curbookmarks.foreach(function(bookmark,index){       console.log("searching.. ", {url : bookmark.url, title : bookmark.title});       chrome.bookmarks.search({url : bookmark.url, title : bookmark.title}, function(result){         console.log('result search is', result, bookmark.title);         var flagexists = false;         for(var = 0; < result.length; i++){           if(result[i].parentid === bookmark.parentid) flagexists = true;         }          if(!flagexists){           chrome.bookmarks.create({             parentid: bookmark.parentid,             index: bookmark.index,             title: bookmark.title,             url: bookmark.url           }, function(){             console.log('ive created!!!');             if(index === curbookmarks.length-1)               chrome.bookmarks.gettree(parsebookmarks);           });         }         else{           if(index === curbookmarks.length-1)             chrome.bookmarks.gettree(parsebookmarks);         }       })     })   }   else{     chrome.bookmarks.gettree(parsebookmarks);   }  } 

Comments