Corion / WWW-Mechanize-Chrome

automate the Chrome browser
https://metacpan.org/release/WWW-Mechanize-Chrome
Artistic License 2.0
30 stars 12 forks source link

proxy basic auth #50

Open arahnale opened 4 years ago

arahnale commented 4 years ago

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

launch_arg => ['--proxy-server=proxy.com']
Corion commented 4 years ago

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

launch_arg => ['--proxy-server=http://user:password@proxy.com']

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

$ENV{HTTP_PROXY} = 'http://user:password@proxy.com';
$ENV{HTTPS_PROXY} = 'http://user:password@proxy.com';

my $mech = WWW::Mechanize::Chrome->new(
    ...
    # launch_arg => []
);
arahnale commented 4 years ago

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);
   });
skyhighpn commented 2 years ago

@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);
 });