Get Local IP of a device in chrome extension

前端 未结 4 742
半阙折子戏
半阙折子戏 2020-12-24 03:21

I am working on a chrome extension which is supposed to discover and then communicate with other devices in a local network. To discover them it needs to find out its own IP

4条回答
  •  臣服心动
    2020-12-24 03:43

    see http://developer.chrome.com/extensions/webRequest.html for detail, my code example:

    // get IP using webRequest
    var currentIPList = {};
    chrome.webRequest.onCompleted.addListener(
      function(info) {
        currentIPList[info.url] = info.ip;
        currentIPList[info.tabId] = currentIPList[info.tabId] || [];
        currentIPList[info.tabId].push(info);
        return;
      },
      {
        urls: [],
        types: []
      },
      []
    );
    

提交回复
热议问题