Question

I am working on a Chrome extension to makes it possible for people to, without a proxy, surf .bit domains which are not available via any standard DNS servers (as .bit is managed by the peer-to-peer Namecoin network with no central authority).

By using the chrome.proxy API (developer.chrome.com/extensions/proxy) I have been able to make an extension that works pretty ok for http (port 80) by using ajax to get the IP of the .bit domain from an app server (app.dotbit.me/domain.bit) and then making a proxy request to that IP thereby keeping the .bit domain name intact in the address field.

The Chrome extension works ok but I am not very happy with the solution. It seems to not load the correct .bit site at times requiring a page reload to work and it does not work for https sites at all.

Is there a better way for a Chrome extension to make a host->IP lookup from a non-default DNS server or app server and then redirect the browser to that domain? Preferably something that would work for https sites as well.

I know it can be achieved by having the user change the computer DNS server to one that supports the .bit domain but that is too complex for most - it would be great if there was a way to do this in a browser extension.

The current Chrome extension is available at https://github.com/Tagide/chrome-bit-domain-extension

The relevant code is as follows:

chrome.webRequest.onBeforeRequest.addListener(function (details) {
  var parser = document.createElement('a');
  parser.href = details.url;
  var tld = parser.hostname.slice(-3);
    if (tld != 'bit') {
        return;
    } else {
      // alert('Getting request for '+details.url);
      var xhr = new XMLHttpRequest();
      var url = "http://app.dotbit.me/"+parser.hostname;

      if (parser.protocol == "https:") {
    var port = "443";
    var access = "HTTPS";
      } else {
        var port = "80";
        var access = "PROXY";
      }
      xhr.open("GET", url, false);
      xhr.onreadystatechange = function() {
      if (xhr.readyState == 4) {
    var bitip = xhr.responseText;
    console.log('Access via '+access+' IP: '+bitip+', port '+port+' and server url '+url);
    var config = {
          mode: "pac_script",
          pacScript: {
          data: "function FindProxyForURL(url, host) {\n" +
                "  if (dnsDomainIs(host, '"+parser.hostname+"'))\n" +
                "    return '"+access+" "+bitip+":"+port+"';\n" +
                "  return 'DIRECT';\n" +
                "}"
          }
        };
    console.log('Config is: '+JSON.stringify(config));
    chrome.proxy.settings.set({value: config, scope: 'regular'},function() {});
        }
      }
      xhr.send();
   }
}, {
    urls: ['*://*/*']
}, ['blocking']);

If you would like to test the extension it's available on the Chrome web store, you can find all .bit sites that's currently running a http server at dotbit.me/proxy/

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top