WWW-Mechanize-Chrome icon indicating copy to clipboard operation
WWW-Mechanize-Chrome copied to clipboard

proxy basic auth

Open arahnale opened this issue 6 years ago • 3 comments

Hello. Please tell me how you can use basic authorization (login , password) when

launch_arg => ['--proxy-server=proxy.com']

arahnale avatar Feb 02 '20 20:02 arahnale

I've never used basic auth with a proxy, but maybe try

launch_arg => ['--proxy-server=http://user:[email protected]']

... or try setting the HTTP_PROXY variable before launching Chrome:

$ENV{HTTP_PROXY} = 'http://user:[email protected]';
$ENV{HTTPS_PROXY} = 'http://user:[email protected]';

my $mech = WWW::Mechanize::Chrome->new(
    ...
    # launch_arg => []
);

Corion avatar Feb 10 '20 21:02 Corion

Thanks, but it didn’t work. I managed to make authorization through:

launch_arg => ['--proxy-server=http://12.43.56.67:1234'],

...

$chrome->driver->send_packet('Fetch.enable' , 'handleAuthRequests' => JSON::true );

 my $asdf = $chrome->add_listener('Fetch.requestPaused', sub {
   my( $info ) = @_;
   my $requestId = $info->{'params'}{'requestId'};
   $chrome->driver->send_message('Fetch.continueRequest' , 'requestId' => $requestId);
 });

 my $asd = $chrome->add_listener('Fetch.authRequired', sub {
   my( $info ) = @_;
   my $requestId = $info->{'params'}{'requestId'};
   print "Fetch auth\n";
   my %auth = (
     'requestId' => $requestId ,
     "authChallengeResponse" => {"response" => "ProvideCredentials" , "username" => "my_user_name" , "password" => "my_password"});
     my $a = $chrome->driver->send_message('Fetch.continueWithAuth' , %auth);
   });

arahnale avatar Feb 11 '20 07:02 arahnale

@arahnale I'm trying your code, and it should work from what I can tell, but the Fetch.authRequired just doesn't seem to trigger. It only triggers the Fetch.requestPaused. "Fetch pause" is all that is outputted with a proxy error in chromium. Any suggestions?

 my $asd = $mechtwo->add_listener('Fetch.authRequired', sub {
   my( $info ) = @_;
   print "Fetch auth\n";
   my $requestId = $info->{'params'}{'requestId'};
   my %auth = (
     'requestId' => $requestId ,
     "authChallengeResponse" => {"response" => "ProvideCredentials" , "username" => "" , "password" => ""});
     my $a = $mechtwo->target->send_message('Fetch.continueWithAuth' , %auth);
   });
 my $asdf = $mechtwo->add_listener('Fetch.requestPaused', sub {
   my( $info ) = @_;
   print "Fetch pause\n";
   my $requestId = $info->{'params'}{'requestId'};
  $mechtwo->target->send_message('Fetch.continueRequest' , 'requestId' => $requestId);
 });

skyhighpn avatar Sep 21 '22 19:09 skyhighpn