Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Headless (Xvfb) WWW::Mechanize::Firefox

by onelesd (Pilgrim)
on Mar 27, 2012 at 20:02 UTC ( [id://962011]=perlquestion: print w/replies, xml ) Need Help??

onelesd has asked for the wisdom of the Perl Monks concerning the following question:

I am working on a multi-page form filler to login to Yahoo Mail, but have run into a problem.

The code works when I run firefox in X11 with a display, but fails when I run firefox in Xvfb. Xvfb is setuid. I can watch it run in X11 with a display (which happens to be running on my mac - the server where fillform.pl runs is Debian Squeeze).

This is where the code fails in fillform.pl when I try to use Xvfb. I can see it connect to firefox from the MOZREPL log:

my $mech = WWW::Mechanize::Firefox->new() ; print "debug: going to mech->get()\n" ; $mech->get('http://mail.yahoo.com') ;

And here is the console session:

$ Xvfb :99 & $ DISPLAY=:99 firefox --display=:99 & I, MOZREPL : Listening : 127.0.0.1:4242 $ DISPLAY=:99 xdotool search --onlyvisible --title firefox 4194416 $ DISPLAY=:99 xdotool windowfocus 4194416 $ DISPLAY=:99 ~/fillform.pl I, MOZREPL : Client connected : 127.0.0.1:46357 : chrome://browser/con +tent/browser.xul I, MOZREPL : Client connected : 127.0.0.1:46358 : chrome://browser/con +tent/browser.xul debug: going to mech->get() Can't call method "addProgressListener" on an undefined value at /usr/ +local/share/perl/5.10.1/WWW/Mechanize/Firefox.pm line 574, <DATA> lin +e 1. I, MOZREPL : Client closed connection : 127.0.0.1:46358 I, MOZREPL : Client closed connection : 127.0.0.1:46357

This is line 574:

$source->addProgressListener($lsn,$NOTIFY_STATE_DOCUMENT);

Replies are listed 'Best First'.
Re: Headless (Xvfb) WWW::Mechanize::Firefox
by Corion (Patriarch) on Mar 27, 2012 at 20:40 UTC

    Are you sure that the X11 browser version, cookies etc. are identical to the Xvfb version?

    From the error location, it seems to me that in the Xvfb version, $mech->tab->{linkedBrowser} is undef, which "should never happen". Is there maybe some easily spotted visual difference between the two browsers? Like a tab bar, which is only in the X11 version, or something like that?

      Corion,

      I use the same firefox binary for X11 and Xvfb. I start it up over ssh (ssh -tXY server firefox) and it runs on the X11 server on my mac. When I run it in Xvfb on the Debian server I can send firefox xdotool key sequences and it works fine (ctrl+l, ctrl+q, etc.). The only difference when I run firefox in Xvfb is I set the DISPLAY variable.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found