1

Trying to set up WWW::Mechanize::Firefox and access Firefox using Perl.

I've installed the module and its dependencies. I'm not sure if I've understood this module properly but I'm running it on a unix (shared) server to access and drive Firefox running on a pc client.

I'm getting an error:

Failed to connect to ,  at MozRepl/RemoteObject.pm at line...

I've read various posts about setting up remote access in RemoteObject.pm and tried all approaches. Still get the error. Right now I have a little test program (http://kamasiri.com/kohkood/cgi-bin/testMechanize.cgi), which is basically as follows:

#!/usr/bin/perl

use CGI;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 
use WWW::Mechanize::Firefox;

print "Content-type: text/html\n\n";

my $mech = WWW::Mechanize::Firefox->new();
$mech->get('http://kamasiri.com');

$mech->eval_in_page('alert("Hello Firefox")');
print "<html><body><p>yeehah!</p></body></html>";

exit;

And in RemoteObject.pm I have edited near the top as follows:

# use $ENV{MOZREPL} or localhost:4242
my $remote_machine = $ENV{REMOTE_ADDR};
$ENV{REMOTE_ADDR} = "$remote_machine:4242";
my $repl = MozRepl::RemoteObject->install_bridge(
  repl => "$ENV{REMOTE_ADDR}"
);

Am i doing something wrong here?

I've also tried hard coding the IP address of the PC client into the code. Still the same error.

Firefox is running and the MozRepl add-on is loaded and running (that's the normal source of this error, I've read).

I wondered if it's a firewall issue so I've tried on various machines including a mobile. Still the same. The fact it's not printing out the ip address and port in the error message suggest to me it's not taking these as options into the program properly.

I also wondered if its a telnet privilege issue because I'm on a shared server?

Any ideas what I can try next?

Scotsman
  • 177
  • 1
  • 9

1 Answers1

1

From your code your initial problem seems to be that you are not initializing your WWW::Mechanize::Firefox with the server you want to use. You have created another file called RemoteObject.pm, but it doesn't seems like you are using it.

To initialize the object you should do something like this, in your main perl file:

my $remote_machine = $ENV{REMOTE_ADDR};
my $mech = WWW::Mechanize::Firefox->new( repl => "$remote_machine:4242" );

Note that this will try to connect to the machine you are using to browse with. You said that you tried with your mobile. Do you have Firefox running with MozRepl add-on on your mobile?

In RemoteObjects.pm there is no need to set the value back to REMOTE_ADDR environment variable.

Still there can be issues with firewalls and socket privileges, but now you can at least try to connect to the correct machine.

bolav
  • 6,938
  • 2
  • 18
  • 42
  • Thank you very much for the input. The RemoteObjects.pm file was part of the package and like an idiot I was merrily editing it to try to achieve the connection. Your answer helped me see that I just direct the connection from the main program. Thank you. Hmmm....now I still have the same error but at least its showing the correct IP address of my client machine and the right port. Still not sure why its not connecting. I configured port 4242 to not be filtered. I tried turning the firewall off completely. Still no joy. Not sure what to try next! – Scotsman Jan 03 '16 at 11:33
  • There could be a firewall anyway between your server and your machine. Depending on the access you have on your server you could log in there, or write scripts to troubleshoot firewall issues. Try connecting to other services on different ports. Also try connecting to your machine on port 4242 from inside your network, and from other machines. Are your machine behind NAT? You can check if you have a private ip address. – bolav Jan 03 '16 at 11:54
  • Thanks I will dig about. The strange thing is if I use telnet locally on my laptop here I can use telnet ipaddress 4242 and it connects fine to MozRepl. So its really close but just wont connect over the net. It must be a firewall issue (even though I tried with the firewall off). Weird. I'm also seeing some posts saying its tricky to set up at the server end and should use an older 1.1.2 MozRepl .xpi file. Hostgator refused to install the module so I did it manually and worked through all the dependencies because I don't have root access, so maybe its screwed up. Oh well, I will keep at it :) – Scotsman Jan 03 '16 at 12:19