2015-09-04 55 views
0

我正在嘗試開發一個chrome擴展,它可以窺探瀏覽器歷史並將其發送到遠程計算機。我需要建立用於傳輸數據的套接字連接。 但我收到上述錯誤。在線閱讀大量帖子,說明在套接字權限上下文中必須存在清單文件中的錯誤。任何人都可以找出錯誤?請檢查下面的代碼。未捕獲的TypeError:無法讀取鉻擴展中未定義的屬性'tcp'

清單文件:

{ 
    "manifest_version": 2, 
    "name": "Browser History Snooping", 
    "description": "This extension snoops browser history and sends it to a remote machine", 
    "version": "1.0", 
    "browser_action": { 
     "default_icon": "icon.png", 
     "default_popup": "popup.html" 
    }, 
    "permissions": [ 
     "history" 
    ], 
    "sockets": { 
     "tcp": { 
      "connect": "" 
     } 
    } 
} 

的JavaScript

var histories = []; 
var visits = []; 

chrome.history.search({ 
    text: '', 
    maxResults: 0 
}, function (historyItems) { 
    var historiesProcessed = 0; 
    for (var i = 0; i < historyItems.length; i++) { 
     //histories.push(historyItems[i]); 
     console.log(historyItems[i]); 

     chrome.history.getVisits({ 
      url: historyItems[i].url 
     }, function (visitItems) { 
      for (var i = 0; i < visitItems.length; i++) { 
       visits.push(visitItems[i]); 
      } 
      historiesProcessed++; 
      if (historiesProcessed === historyItems.length) { 
       console.log(visits.length + ' visits'); 
      } 
     }); 
    } 

    console.log(histories); 
}); 

chrome.sockets.tcp.create({}, function (createInfo) { 
    chrome.sockets.tcp.connect(createInfo.socketId, '127.0.0.1', 8888, 
     function (result) { 
      if (result >= 0) { 
       console.log('Successfully connected'); 
      } 
     }); 
}); 
+0

另請參閱http://stackoverflow.com/q/283​​93105/632951 – Pacerier

回答

相關問題