C# Selenium Proxy Authentication with Chrome Driver

前端 未结 1 2013
梦毁少年i
梦毁少年i 2021-01-23 17:12

I am using the following code for the proxy. however, when chrome starts, pop-up window will pop up and the program will be locked.

public async void StartDriver         


        
相关标签:
1条回答
  • 2021-01-23 17:21

    is there a way to start a secure proxy?

    There's one. You need to create a chrome extension with proxy settings.

    manifest.json

        {
            "version": "0.1.0",
            "manifest_version": 2,
            "name": "%NAME IT AS YOU WANT%",
            "permissions": [
                "proxy",
                "tabs",
                "unlimitedStorage",
                "storage",
                "<all_urls>",
                "webRequest",
                "webRequestBlocking"
            ],
            "background": {
                "scripts": ["background.js"]
            },
            "minimum_chrome_version":"22.0.0"
        }
    

    background.js

    //note that it's a JS code. You can use any additional code to do anything :) 
    var config = {
        mode: "fixed_servers",
        rules: {
          singleProxy: {
            scheme: "http",
            host: "%HOST%",
            port: parseInt(%PORT%)
          },
          bypassList: ["foobar.com"]
        }
      };
    
    chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
    
    function callbackFn(details) {
        return {
            authCredentials: {
                username: "%USERNAME%",
                password: "%PASSWORD%"
            }
        };
    }
    
    chrome.webRequest.onAuthRequired.addListener(
            callbackFn,
            {urls: ["<all_urls>"]},
            ['blocking']
    );
    

    Pack it as an archive. For instance yourExt.dat

    var proxy = "yourExt.dat";
    var options = new ChromeOptions();
    options.AddExtension(proxy);
    var driver = new ChromeDriver(options);
    
    0 讨论(0)
提交回复
热议问题