Search code examples
javascriptjsongoogle-chrome-extension

Connection to private proxy socks5 with "chrome.webRequest.onAuthRequired" and "webRequestAuthProvider" permission


I'm developing a Chrome extension to connect to a private proxy server. In version 3 of the manifest, the webRequestAuthProvider permission was added to provide a username and password for authorization. I am sure that my code should work, but it does not work, but the connection is made to the open servers.

My current code Please help me figure out why the connection to the private server is not happening

My manifest v3

{
  "name": "Proxy",
  "version": "1.0",
  "minimum_chrome_version": "22.0.0",
  "manifest_version": 3,
  "description": "Proxy",
  "permissions": [
    "proxy",
    "tabs",
    "unlimitedStorage",
    "storage",
    "webRequest",
    "webRequestAuthProvider"
  ],
  "host_permissions": [
    "<all_urls>"
  ],
  "background": {
    "service_worker": "js/background.js"
  },
  "action": {
    "default_title": "Proxy",
    "default_popup": "popup.html"
  }
}

my background.js file

var config = {
        mode: "fixed_servers",
        rules: {
        singleProxy: {
            scheme: "socks5",
            host: host,
            port: parseInt(port)
        }
        }
    };
function setProxy(){ //on click
chrome.proxy.settings.set({value: config, scope: "regular"}, function () {
    console.log("Connection established");
  });
}
function callbackFn(details) {
    return {
        authCredentials: {
            username: username,
            password: password
        }
    };
}

chrome.webRequest.onAuthRequired.addListener(
            callbackFn,
            {urls: ["<all_urls>"]},
            ['asyncBlocking']
);

function clearProxy() { // on click
  chrome.proxy.settings.clear({ scope: "regular" }, function () {
    console.log("Disconnected");
  });
}

Solution

  • Unfortunately, socks5 authentication is not currently implemented in Chrome, and there are no plans to support it. For more details, see https://crbug.com/1309413.

    It's worth noting that socks5 authentication is sent in plain text, which means it may be undesirable. You may want to consider using an HTTP(s) proxy instead. These are supported by the onAuthRequired API and provide some additional flexibility in terms of security.