Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Problem with WWW::Mechanize::Chrome

by ivartr (Novice)
on Nov 09, 2017 at 20:27 UTC ( #1203079=perlquestion: print w/replies, xml ) Need Help??
ivartr has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I have problem with WWW::Mechanize::Chrome

Running included examples ends up with infinite waiting or ...

e.g using included example dump-links.pl
https://metacpan.org/pod/WWW::Mechanize::Chrome::Examples#Example:-dump-links.pl
  generates error:
Could not connect to '127.0.0.1:9222': Connection refused

After starting headless chrome in background:
google-chrome --headless --hide-scrollbars --remote-debugging-port=9222 --disable-gpu  &

  response from dump_links.pl:
Could not connect to '127.0.0.1:9223': Connection refused

Changed the code -  port to connect added:
my $mech = WWW::Mechanize::Chrome->new( port => 9222, );
 .. waits initialisation for ever ...
 
I have experimented with  Chrome options, WWW::Mechanize::Chrome->new %options etc etc - no results.

Command line variant works well:
google-chrome --headless --disable-gpu --print-to-pdf https://www.chromestatus.com/

(just for background - I was successful with similar demos from WWW::Mechanize::PhantomJS)
All searches form PerlMonks, StackOverflow -- also no results.

Installed environment:
Ubuntu 16.04.3 LTS
perl v5.22.1
Google Chrome 62.0.3202.89
also tried  Chromium 64.0.3240.0 ( this was bundled with Puppeteer - all demos working fine)

Any comments, suggestions ....?


Thank you in advance 
Ivar

Replies are listed 'Best First'.
Re: Problem with WWW::Mechanize::Chrome
by Corion (Pope) on Nov 09, 2017 at 20:31 UTC

    You need to shut down all Chrome processes on your machine or use a separate Chrome installation from the one you use yourself.

    You can see more debugging information by initializing the logger with $TRACE instead of $ERROR. If WWW::Mechanize::Chrome can't connect to the Chrome port, then maybe you have a firewall or something blocking the access to Chrome? Maybe localhost is something else on your machine, like an IPv6 address?

      I include the trace:

      2017/11/10 12:51:40 Spawning $VAR1 = [ 'google-chrome', '--remote-debugging-port=9222', '--disable-gpu', 'about:blank' ]; 2017/11/10 12:51:40 Spawned child as 6609 2017/11/10 12:51:42 Created new tab $VAR1 = { 'devtoolsFrontendUrl' => '/devtools/inspector.html?ws=127.0. +0.1:9222/devtools/page/882884f3-27b2-42f3-81b1-a80cad81d727', 'type' => 'page', 'id' => '882884f3-27b2-42f3-81b1-a80cad81d727', 'title' => '', 'webSocketDebuggerUrl' => 'ws://127.0.0.1:9222/devtools/page +/882884f3-27b2-42f3-81b1-a80cad81d727', 'description' => '', 'url' => 'about:blank' }; 2017/11/10 12:51:42 Connecting to ws://127.0.0.1:9222/devtools/page/88 +2884f3-27b2-42f3-81b1-a80cad81d727 2017/11/10 12:51:42 Connected 2017/11/10 12:51:42 Sent message $VAR1 = '{"method":"Page.enable","id" +:0,"params":{}}'; 2017/11/10 12:51:42 Sent message $VAR1 = '{"method":"Network.enable"," +id":1,"params":{}}'; 2017/11/10 12:51:42 Sent message $VAR1 = '{"method":"Runtime.enable"," +id":2,"params":{}}';

      After accessing devtools link trace sent:

      [1110/125428.096505:ERROR:devtools_http_handler.cc(365)] GetMimeType d +oesn't know mime type for: page/882884f3-27b2-42f3-81b1-a80cad81d727 +text/plain will be returned [1110/125428.111263:ERROR:devtools_http_handler.cc(365)] GetMimeType d +oesn't know mime type for: page/882884f3-27b2-42f3-81b1-a80cad81d727 +text/plain will be returned

      Ivar

        [1110/125428.096505:ERROR:devtools_http_handler.cc(365)] GetMimeType d +oesn't know mime type for: page/882884f3-27b2-42f3-81b1-a80cad81d727 +text/plain will be returned

        I've never seen this error message from Chrome, but it seems that something really weird is happening with your setup and/or your machine.

        Note that you can only access the devtools from one location, either from Perl or from within Chrome. It does not allow access from two things at once. If you open the devtools in Chrome after launching Perl, Perl will lose the access to the devtools.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1203079]
Approved by 1nickt
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2018-08-15 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (165 votes). Check out past polls.

    Notices?