Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: some doubts on my first steps with WWW::Mechanize::Chrome -- further steps and doubts

by Discipulus (Canon)
on May 20, 2020 at 17:38 UTC ( [id://11116993]=note: print w/replies, xml ) Need Help??


in reply to some doubts on my first steps with WWW::Mechanize::Chrome

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.
  • Comment on Re: some doubts on my first steps with WWW::Mechanize::Chrome -- further steps and doubts
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: some doubts on my first steps with WWW::Mechanize::Chrome -- further steps and doubts
by Corion (Patriarch) on May 20, 2020 at 21:30 UTC

    Thank you very much for the report and the test program! This helps me immensively to reproduce the problem.

    The autoclose issue is a bug. The fix for it is simple - the shutdown is always killing Chrome instead of checking whether it should try to do that:

    sub close { ... if( $_[0]->{autoclose} ) { $_[0]->kill_child( $_[0]->{cleanup_signal}, $pid, $_[0]->{wait +_file} ); } }

    But now I have to think about what my test suite tests and how I can test this case better... Then I will release a fixed version :)

Re^2: some doubts on my first steps with WWW::Mechanize::Chrome -- further steps and doubts
by Corion (Patriarch) on May 21, 2020 at 14:24 UTC

    Thanks again - this should now be fixed with 0.56.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116993]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found