Chrome扩展程序在两个浏览器之间无法同步

时间:2015-10-06 13:56:18

标签: google-chrome synchronization

我正在尝试创建在两个浏览器之间共享信息的chrome扩展程序。 我使用相同的密钥"key":"myawesomeextensionmyawesomeexten"进行了调试并尝试上传网上商店[仅供私人使用],但结果相同 - 无法检索值

通过chrome://sync查看同步日志时一切正常,我得到:

{
"commit": {
"cache_guid": "64YTgq9pf4aEBeuJdKjwcA==",
"config_params": {
"enabled_type_ids": [
"32904",
"37702",
"45873",
"63951",
"31729",
"306270",
"41210",
"40781",
"48119",
"88610",
"50119",
"48364",
"103656",
"96159",
"150251",
"170540",
"182019",
"181534",
"154522",
"163425",
"194582",
"202026",
"229170",
"47745",
"161496"
],
"tabs_datatype_enabled": true
},
"entries": [
{
"attachment_id": [],
"client_defined_unique_tag": "ZVSOWG9AJz1oMEN+CPO1LtiK3JU=",
"ctime": "1444047162286",
"folder": false,
"id_string": "Z:ADqtAZyfnDGA95mhey4QDFcumpRWpE+p0dQA1SAFSSalHzx9zDzOq7xEoo67SMB/3YfyukM9A8/OghX4bdeWhuE+RbfdZ2JV8Q==",
"mtime": "1444047162286",
"name": "ARTURAS",
"non_unique_name": "ARTURAS",
"version": "1444138864965868"
},
{
"attachment_id": [],
"client_defined_unique_tag": "c5FGio5gj27CzEdOoHlwf0rfRjE=",
"ctime": "1444137218436",
"folder": false,
"id_string": "Z:ADqtAZzdeALpaWbtNyJ+NzEwos5Sb5+A+8nvv/cEewlnQn4AJN2SUML9cQ8edt6lGfHqPE2uGbeDQdB1xvdrcqhSq93MUetZqg==",
"mtime": "1444137218436",
"name": "auth",
"non_unique_name": "auth",
"version": "1444137721670768"
},
{
"attachment_id": [],
"client_defined_unique_tag": "N2M+eSp0/5zaUImLY+GwoNh2lYE=",
"ctime": "1444137218611",
"folder": false,
"id_string": "Z:ADqtAZzdeALpaWbtNyJ+NzEwos5SYxsuyBBHqHUDls7djJwslxBuU6C+W/dnREEz7coKqJtsSMi1Y6AJcle6CO1VsM7PRkG5iA==",
"mtime": "1444137218611",
"name": "pushed_time",
"non_unique_name": "pushed_time",
"version": "1444139081029437"
}
}

我的代码是发送:

chrome.tabs.query({"status":"complete","windowId":chrome.windows.WINDOW_ID_CURRENT,"active":true}, function(tab)
{
   
       
                        chrome.cookies.getAll({"url":tab[0].url},function (cookie)
                        {

                            for(i=0;i<cookie.length;i++)
                            {
                                if(
                                    cookie[i].name == "XSRF-TOKEN" ||
                                    cookie[i].name == "ttc" ||
                                    cookie[i].name == "mbox" ||
                                    cookie[i].name == "iStockSession" ||
                                    cookie[i].name == "iStockContainer_Info" ||
                                    cookie[i].name == "IS_MARIN_UUID"
                                )
                                {
                                    cfg[cookie[i].name] = cookie[i].value;
                                    
                                    chrome.browserAction.setBadgeBackgroundColor({ color: [62, 143, 62, 255] });
                                    chrome.browserAction.setBadgeText({text: 'Host'});
                                }
                            }

                            sync_push_data('auth', JSON.stringify(cfg));
                            debug('[host] ' + ' ' + current_time() + ' [' +  JSON.stringify(cfg) + '] ');
                        });
                        save_identificator(); //save user ip to remote server
   
}
                  
                  
function sync_push_data(c_name, c_value)
{
    if(!c_name && !c_value)
    {
        debug('Error: no JSON array');
    }
    else
    {
       var save = {};
       var is_saved = "";



        save[c_name] = c_value;
        chrome.storage.sync.set(save, function()
        {
           
            if(chrome.runtime.error)
            {
                debug('Runtime error. ')
            }
            else
            {
                debug('[host] ' + current_time() + ' [' + c_name + '] ');
                

            }
        });



    }
}

function save_identificator()
{
  
}


                  

获取:

                        chrome.storage.sync.get(null, function(items) 
                        {
                            
                            r_cookie = JSON.parse(JSON.stringify(items));

                            $.each(r_cookie, function(index, value)
                            {
                                    
                                if(index == "auth" && value.length > 2)
                                {
                                    new_value = JSON.parse(value);

                                    if(new_value['cookie1'])
                                    {
                                        save_cookie('cookie1', new_value['cookie1']);
                           
                                    }      

                                    if(new_value['cookie2'])
                                    {
                                        save_cookie('cookie2', new_value['cookie2']);
                                     
                                    }    

                                    if(new_value['cookie3'])
                                    {
                                        save_cookie('cookie3', new_value['cookie3']);
                                 
                                    }   

                                    if(new_value['cookie4'])
                                    {
                                        save_cookie('cookie4', new_value['cookie4']);
                            
                                    }    

                                    if(new_value['cookie5'])
                                    {
                                        save_cookie('cookie5', new_value['cookie5']);
                                   
                                    }

                                    if(new_value['cookie6'])
                                    {
                                        save_cookie('cookie6', new_value['cookie6']);
                              
                                    }

                                    debug('[user] ' + ' ' + current_time() + ' [' + index + '] ');
                                    chrome.browserAction.setBadgeBackgroundColor({ color: [51, 122, 183, 255] });
                                    chrome.browserAction.setBadgeText({text: 'User'});
                                }
                              
                               
                                }

                            }); 
                        }); 

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,不是使用chrome.storage.sync.set而是通过AJAX保存在FTP服务器