ChromeDevTools / devtools-protocol

Chrome DevTools Protocol
https://chromedevtools.github.io/devtools-protocol/
BSD 3-Clause "New" or "Revised" License
1.15k stars 226 forks source link

Method for Proxy Authentication #234

Closed SwitchGM closed 3 years ago

SwitchGM commented 3 years ago

Hey there, I'm currently using devtools with a proxy and have been very unlucky in finding a way to authenticate with it. I'm very sure that there is a method, as the docs have Network.AuthChallange , and Network.AuthChallangeResponse types. Unfortunatly I have been unable to find any example code using these or any code using devtools to authenticate proxies.

TimvdLippe commented 3 years ago

This repository is related to Chrome DevTools Protocol, but does not track issues regarding its definition or implementation. If you want to file an issue for the Chrome DevTools Protocol, please open an issue on https://crbug.com under component: Platform>DevTools>Platform. Thanks in advance!

ethaniel commented 1 year ago

Here is an example how I did it in PHP (I use https://github.com/chrome-php/chrome/). I hope it will give you some ideas:

// enable request interception (important!!!)
// it allows the browser to inform us that we need to complete a username/password authorization.
$page->getSession()->sendMessageSync(new Message('Network.setRequestInterception', ['patterns' => [['urlPattern' => '*']]]));

// this method allows you to approve or block request (we are only approving here)
$page->getSession()->on('method:Network.requestIntercepted', function (array $params): void {

    // the browser is letting us know that we need to provide proxy (or 401) credentials (normally, happens only once)
    if (isset($params["authChallenge"])) {
        // approving request and sending username/password
        $page->getSession()->sendMessageSync(
            new Message('Network.continueInterceptedRequest', ['interceptionId' => $params["interceptionId"], 'authChallengeResponse' => ['response' => 'ProvideCredentials', 'username' => "proxy_username", 'password' => "proxy_password"]])
        );
    } else {
        // simply approving request
        $page->getSession()->sendMessageSync(
            new Message('Network.continueInterceptedRequest', ['interceptionId' => $params["interceptionId"]])
        );

    }

});