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

I have the following simple simple test script:
use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new( launch => '/Applications/Firefox.app/Contents/MacOS/firefox', ); $mech->get('http://google.com');
I'm on Mac. The above script works fine when the FF app is completely closed or when an existing instance of FF exists. However, on a Mac, it's possible for the application can be running without having any windowed instance of FF displaying. And when I run the above code without an windowed instance of FF, I get the following error:
I, MOZREPL : Client connected : 127.0.0.1:57788 : chrome://browser/con +tent/hiddenWindow.xul Can't call method "addTab" on an undefined value at /Library/Perl/5.12 +/Firefox/Application/API40.pm line 131.
I was told this was the place to go for support for this module. Let me know if SOPW isn't the right place.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
$nysus = $PM . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: WWW::Mechanize::Firefox throwing error when launching a new Firefox instance on Mac
by Corion (Patriarch) on Feb 28, 2013 at 13:14 UTC

    This is most likely a bug in WWW::Mechanize::Firefox. I guess that it finds an existing navigator window but that this window is hidden on the Mac and does not allow new tabs to be created in it.

    I'm not sure how to debug this as I don't have a Mac, so in the meantime the workaround will have to be that you launch Firefox separately and ensure that at least one window is open.

      Thanks for your help. After some trial and error, I found the following workaround to the bug:
      $ff = Firefox::Application->new( launch => '/Applications/Firefox.app/Contents/MacOS/firefox', ); $ff->quit( restart => 1 ); # restart sleep 2;

      This launches a new FF application no matter what, then restarts it. Then I found you have to sleep for a bit before you can call WWW::Mechanize::Firefox->new and go to work browsing in the tab.

      If there is a way I can help you troubleshoot this, let me know. I've got a spare mac and I can give you control over it in a guest account via vnc. Maybe that would work.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
      $nysus = $PM . $MCF;
      Click here if you love Perl Monks