Hello
tuneroaster and weclome to the monastery!
incognito => 0 option has be proven to be currently broken as Corion said (he is the author an, yes! he will fix it ;) also in a very recent post by me: some doubts on my first steps with WWW::Mechanize::Chrome and remember Super Search is our friend!
> please elaborate
If the chrome browser was started without options atm incognito will be always be the mode. But if you start chrome with the option --remote-debugging-port=9222 or manually or in your perl program, then you'll be able to connect to an existing instance and to an existing tab. I was prepaering the following example that shows what I mean:
use strict;
use warnings;
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ER
+ROR
my $mech = connect_to_an_existing_tab();
unless ( $mech ){
my $chrome_exe = choose_chrome_executable();
start_new_instance( $chrome_exe )
}
print "broswer started or connected succesfully, listening on remote-d
+ebugging-port ".
${$mech->target()}{transport}{port}, " status ",
${$mech->target()}{transport}{is_connected} ? "connected" :
+ "not connected","\n";
sleep 3;
# go from Monastery Gates to Super Search
$mech->click ( { selector => '#titlebar-top tbody tr td.monktitleb
+ar ul li:nth-child(16) a'} );
# the super search form
$mech->form_number( 2 );
# titles containing text field
$mech->field( 'HIT' => 'WWW::Mechanize::Chrome');
# not working: SUPPORT NEEDED HERE ;)
#
# $mech->untick( 're', 'S' );
# $mech->tick( 're', 'N' );
# submit
$mech->click( { selector => '#id-3989 center table tbody tr td.main_co
+ntent form p:nth-child(17) input[type=submit]'} );
# ATTENTION: autoclose was fixed recently:
#
if ( $WWW::Mechanize::Chrome::VERSION < 0.56){
print "Press ENTER to terminte ( autoclose => 0 fixed in version 0
+.56 of the module)".."\n";
<STDIN>;
}
sub choose_chrome_executable{
my( $chrome, $diagnosis ) = WWW::Mechanize::Chrome->find_executabl
+e();
if ( $diagnosis ){
print "problem finding chrome executable: $diagnosis\n";
}
print "Should I use ",( $chrome ? "[$chrome]" : "-NOT FOUND-" ), "
+ or another executable (put full path or leave blank for default)\n";
my $chrome_path = <STDIN>;
chomp $chrome_path;
$chrome_path = -e $chrome_path ? $chrome_path : $chrome;
return $chrome_path;
}
sub connect_to_an_existing_tab{
print "I have to use an existing chrome tab by title( for example
+PerlMonks )? leave it blank to open a new browser instance\n";
my $tab_title = <STDIN>;
chomp $tab_title;
if ( $tab_title ){
my $mech;
{
local $@;
eval{
$mech = WWW::Mechanize::Chrome->new(
mute_audio => 0,
autoclose => 0,
autodie => 0,
incognito => 0,
tab => qr/$tab_title/,
);
};
if ( $@ ){
print "problem connecting to an already open tab in a
+running instance of chrome:\n$@\n\n".
"close your running chrome instance and anothe
+r one will be started with right configuration\n".
"Press ENTER to continue..\n";
<STDIN>;
return 0;
}
return $mech;
}
}
else { return 0 }
}
sub start_new_instance{
my $chrome_exe = shift;
print "I'll now open https://www.perlmonks.org (will be in incogn
+ito mode despite incognito => 0)\n";
my $url = 'https://www.perlmonks.org';
$mech = WWW::Mechanize::Chrome->new(
mute_audio => 0,
autoclose => 0,
autodie => 0,
incognito => 0,
launch_exe => $chrome_exe,
launch_arg => [ "--remote-debugging-port=9222" ]
);
$mech->get( $url );
}
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.