Thanks Corion and all,
I still have some, stupid, question about the web in general and some issue with, anyway woderful, WWW::Mechanize::Chrome module.
Stupid question: if I use $mech->eval_in_page ( qq( xajax_viewWindow(container.open({saveName: 'profiles', title: ''}) ) )); with an empty title while the orginal code of the page was title: 'TITLE' this action is just local to my browser or can be catched on the server side spotting the missing title? Sorry for my limited understanding of the whole web mechanisms.
More on WMC: in addition to the incognito param (the author will fix it soon ;) I also have problem with the autoclose one. The following not so short example will demonstrate it. In brief if the browser was started by the perl program autoclose => 0 has no effect. This happens with both chrome and chromium. By other hand if the browser was started before the perl program with --remote-debugging-port=9222 as arg then autoclose => 0 will work.
The opposite setting, autoclose => 1 will work as expected closing the browser at the end of the perl program if the browser was started before perl and also if launched by perl.
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;
my( $chrome, $diagnosis ) = WWW::Mechanize::Chrome->find_executable();
print "error: [$diagnosis]\n" if $diagnosis;
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 = $chrome_path ? $chrome_path : $chrome;
print "I have to use an existing chrome tab ( for example PerlMonks )?
+ leave it blank to open a new browser instance\n";
my $tab_title = <STDIN>;
chomp $tab_title;
if ( $tab_title ){
$mech = WWW::Mechanize::Chrome->new(
autoclose => 0, # has no effect
autodie => 0,
incognito => 0, # has no effect
tab => qr/$tab_title/,
);
}
else{
print "Give me the full url to connect ( for example https://www.p
+erlmonks.org )\n";
my $url = <STDIN>;
chomp $url;
$mech = WWW::Mechanize::Chrome->new(
autoclose => 0, # has no effect
autodie => 0,
incognito => 0, # has no effect
launch_exe => $chrome_path,
launch_arg => [ "--remote-debugging-port=9222" ]
);
$mech->get( $url );
}
sleep 5;
# go from Monastery Gates to Newest Nodes
$mech->click ( { selector => '#titlebar-top tbody tr td.monktitleb
+ar ul li:nth-child(15) a'} );
print "Press ENTER to continue... (if the browser was open by $0 will
+be closed despite of autoclose => 0)";
my $ready = <STDIN>;
Thanks in advance
L*
PS I'd also like to know if the current running chrome instance was started with the correct parameter --remote-debugging-port=9222 and, shooting in the dark I tried $mech->target() but I'm a bit confused: if i use use Data::Dump; dd $mech->target(); it dies with:
Cannot use IO::Async::Stream::Writer as an ARRAY reference at C:/uliss
+e/perl5.24-64b/perl/vendor/lib/Data/Dump.pm line 2
75.
and now I rembember i forced installation of IO::Async with no testing..
With good old Data::Dumper I get a whole mess of lines containing 'port' => 9222,'is_connected' => 1 that sounds promising, but sincerely I dunno how to access it: after the first level becomes difficult to parse:
print $_.$/ for keys %{ $mech->target() };
sessionId
listener
have_target_info
sequence_number
json
receivers
transport
tab
_one_shot
targetId
on_message
browserContextId
PPS
after some brute forcing I got something useful:
print "\n\nPORT: ", ${$mech->target()}{transport}{port},"\n",
"IS CONNECTED: ",${$mech->target()}{transport}{is_connected},"\n",
"LISTENER: ",${$mech->target()}{transport}{listener},"\n",
"TAB: ",${$mech->target()}{transport}{tab},"\n";
# gives
PORT: 9222
IS CONNECTED: 1
LISTENER: HASH(0x498a420)
TAB: HASH(0x4bfbe78)
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.
|