Corion / WWW-Mechanize-Chrome

automate the Chrome browser

Home Page:https://metacpan.org/release/WWW-Mechanize-Chrome

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

proxy basic auth

arahnale opened this issue · comments

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

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

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 => []
);

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