EzDevInfo.com

mozrepl

Remotely control Firefox and other Mozilla apps with JavaScript. [Orphaned. Looking for maintainers!] Home · bard/mozrepl Wiki · GitHub mozrepl - remotely control firefox and other mozilla apps with javascript. [orphaned. looking for maintainers!]

mozrepl and document.cookie

I'm using mozrepl with firefox 25 on ubuntu and I want to grab the cookies for the current page.

telnet localhost 4242
 ...
 repl> document.title
 "my test cookie site - Mozilla Firefox"
 repl> document.cookie
 repl>

Doing anything with document.cookie and I'm told it is undefined.

Now I know there are cookies b/c when I go to firefox, open up Scratchpad and run alert(document.cookie), I get the expected 2 cookies.

What do I need to do to get the cookies?

Thanks in advance.


Source: (StackOverflow)

WWW::Mechanize::Firefox; without the support of Mozrepl and Firefox

I am going to run a perl script where i cannot install Mozila firefox browser and MozRepl addon. but in my script i use WWW::Mechanize::Firefox; . I would like to know if there is any way to execute the script which depends on mozrepl without the support of any browser interface and addons.Is there any solution for that.

Please give me some suggestion. Thanks.


Source: (StackOverflow)

Advertisements

Getting rendered HTML with MozRepl and Mechanize::Firefox

I've just been introduced to the wonders of MozRepl used in conjunction with Perl's WWW::Mechanize::Firefox, and was trying to figure out how to use it to crawl GWT pages (e.g.,: https://www.google.com/offers/home#!details/4bc7fd6bd3feb311/XYW81TXGLA88TR42)

What I really want is the rendered html, not the actual html. Would really appreciate an example of how I would get this.


Source: (StackOverflow)

Setting up headless Firefox with MozRepl

I would like to run a crawler that can handle javascript created html in an environment without an X server. I know I can run Firefox in a headless state under xvfb, and I know how to install MozRepl on Firefox and interact with it using WWW::Mechanize when I have the actual browser and can download and setup the module.

What I don't know how to do is setup MozRepl on Firefox in an environment where I don't have an X server to make it easy for me to install the module. Any help is appreciated.


Source: (StackOverflow)

MozRepl gives ReferenceError sometimes (BrowserReload())

I'm using MozRepl with Vim to reload the browser. This is the command I run:

echo "BrowserReload(); repl.quit()" | nc -w 1 localhost 4242

Sometimes it works, other times it gives ReferenceError: BrowserReload is not defined. Anybody in the know?

EDIT: OK, the problem is when the developer window is focused instead of the main window of Firefox.


Source: (StackOverflow)

How to install firefox addon mozrepl on Web hosting server [closed]

I have perl script for scrapping which uses WWW::Mechanize::Firefox and firefox addon MozRepl.

Now, i need to deploy it on a web hosting server. The problem is that the they don't provide any interface or UI terminal so that i can launch firefox and launch it from there .

Can anyone tell me a way to install MozRepl addon in Firefox from the shell or by any other means


Source: (StackOverflow)

create thumbnails with WWW::Mechanize::FireFox using Mozrepl - some debug attempts

well i run this script , which is written to do some screenshots of websites i have also up and running mozrepl

here we have the file with some of the requested urls ... note this is only a short snippet of the real list - the real list is much much longer. it contains more than 3500 lines and URLs

http://www.unifr.ch/sfm
http://www.zug.phz.ch
http://www.schwyz.phz.ch
http://www.luzern.phz.ch
http://www.schwyz.phz.ch
http://www.phvs.ch
http://www.phtg.ch
http://www.phsg.ch
http://www.phsh.ch
http://www.phr.ch
http://www.hepfr.ch/
http://www.phbern.ch
http://www.ph-solothurn.ch
http://www.pfh-gr.ch
http://www.ma-shp.luzern.phz.ch
http://www.heilpaedagogik.phbern.ch/

whats strange is the output - see below... question: should i do change the script

why do i ge the output with the following little script:

#!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize::Firefox;

my $mech = new WWW::Mechanize::Firefox();

open(INPUT, "<urls.txt") or die $!;

while (<INPUT>) {
        chomp;
        print "$_\n";
        $mech->get($_);
        my $png = $mech->content_as_png();
        my $name = "$_";
        $name =~s/^www\.//;
        $name .= ".png";
        open(OUTPUT, ">$name");
        print OUTPUT $png;
        sleep (5);
}

see here the well overwhelming output - to be frank i never have thught to get such a funny output .. i have to debug the whole code.... see below,

http://www.unifr.ch/sfm
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 2.
http://www.zug.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 3.
http://www.schwyz.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 4.
http://www.luzern.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 5.
http://www.schwyz.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 6.
http://www.phvs.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 7.
http://www.phtg.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 8.
http://www.phsg.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 9.
http://www.phsh.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 10.
http://www.phr.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 11.
http://www.hepfr.ch/
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 12.
http://www.phbern.ch                                                                                                                                                                  

Some musings: well -firstly, i think this is not a very serious error - i think i have to debug it and then it will work better. Second, i firstly thought that the script seemed "to overload the machine"? Now i am not very sure about that: the symptoms do look strange but i guess that it is not neecessary to conclude an "overloading of the machine"

Third, well i think of certain steps that have to be taken to ensure that the problem is at all related to WWW::Mechanize::Firefox at all? This leads me to the point to what Perl warning means and to the idea to use the diagnostics pragma to get more explanation: what do you think?

print() on unopened filehandle FH at -e line 1 (#2) (W unopened) An I/O operation was attempted on a filehandle that w +as never initialized. 

firstly - we need to do an open(), a sysopen(), or a so +cket() call, or call a constructor from the FileHandle package besides that - alternatively, print() on closed filehandle OUTPUT also gives lots of answers that will tell us that we did not use autodie and also did not check the return value of open. Above all i have to debug it and make sure to find where the error comes into play[/QUOTE]

But after some musings i think that it is worth to have a closer look at all test things-, what do you think about the idea always test to make sure the file is open before using it.That means that we should also get in the habit of using the three

arg open():

open my $fh, '>', $name or die "Can't open file $name : $!";
print $fh $stuff;

well - i guess that we can or should work around this without using die(), but we d have to manually have some method to let us know which files couldn't be created. In our case, it looks like all of them....that are shown above...

update in choosing a good file name you mean that i need to have a file name to store the images.. Note: i want to store all of them locally. But if i have a huge list of urls then i get a huge list of output files. Therefore i need to have good file names. Can we reflect those things and needs in the programme!?

the very latest update; there seem to be some errors with mechanize.... i guess so!!!


Source: (StackOverflow)

How can i use Unicode string key In Javascript Object?

I want to use unicode string in Object as key, something as:

var t = {"姓名": "naitong"};

it's ok , t["姓名"] return "naitong"

but

Object.keys({"姓名": "naitong"})

I got " ", a blank string

Anyone knowes why?

Editting:

I install firebug and try it in the console, it works. Acctually i use mozrepl, so that i can editing and run javascript in emacs. So This have something to do with mozrepl

I have confirm that mozrepl support only "7bit safe ASCII", to tranform unicode ,i have to json-encode it in emacs, as:

alert(Object.keys(JSON.parse("{\"\\u59d3\\u540d\":\"naitong\"}")))

This is my first question asked on stackoverflow, and i got quick resp. Thank you all.


Source: (StackOverflow)

WWW::Mechanize::Firefox troubleshooting

I have MozRepl installed in my browser and set to start on startup and accept outside connections.

So my questions are as follows 1) will simply running the code my $mech = WWW::Mechanize::Firefox->new(); launch the firefox browser?

2) I have set MozRepl to accept outside connections however, while firefox is not launched, when my script reaches the code in 1), it tells me unable to connect, problem connecting to localhost, on port 4242. I tried to debug by doing telnet localhost 4242 with firefox browser not launched. It also gives me this error Could not open connection to the host, on port 4242: Connect failed.

Should i be expecting this result?

3) Given the difficulties I'm experiencing above, I decided to use system() to launch the browser before creating mechanize::firefox instance. The browser is able to start, however it never reaches the code where mechanize::firefox instance is to be created.

#where i manually fire up firefox.
system('"C:\Program Files\Mozilla Firefox\firefox.exe"'); 

my $mech = WWW::Mechanize::Firefox->new(ssl_opts => { verify_hostname => 0});
$mech->get( 'https://192.168.1.23' );   

What can i do to make sure firefox browser can be launched yet it will not affect the sequence of the code, such that mechanize::firefox instance can be created to manipulate the browser?


Source: (StackOverflow)

Emacs: what is the conventional way of receiving output from a process?

My aim is to get the output from a process in Emacs.

For example, M-x run-python gives me a python shell *Python* that I can send python code to. If I send print "hello world" to *Python*, I hope Emacs can know the result once the execution is finished and echo it in the mini-buffer.

Is it possible to add something like a callback?


Source: (StackOverflow)

mozrepl: loop through all tabs in all windows of firefox

I know that when I enter a mozrepl session I'm in the context of one particular browser window. In that window I can do

var tabContainer = window.getBrowser().tabContainer;
var tabs = tabContainer.childNodes;

which will give me an array of tabs in that window. I need to get an array of all the tabs in all open Firefox windows, how do I do that?


Source: (StackOverflow)

WWW:Mechanize:Firefox fails connection

I am creating a short Perl Script. I am using the WWW::Mechanize::Firefox module. When I instantiate the object, I believe the module fails to establish a connection with the MozRepl component in Firefox.

My code is as follows:

use WWW::Mechanize::Firefox;

my $mech = WWW::Mechanize::Firefox->new();

When I run the code, I get the following error message

Failed to connect to , problem connecting to "localhost", port 4242: Connection refused at /usr/local/share/perl/5.12.4/MoxRepl/Client.pm line 144'

I just installed and updated all relevant software I can think of

  1. Perl 5.12.4
  2. MozRepl Extension for Firefox
  3. CPAN
  4. MozRepl
  5. WWW::Mechanize
  6. WWW::Mechanize::Firefox

I tried adjusting the firewall to open port 4242. Nothing is working. Any ideas?

A similar error code appears in this Stack Overflow question


Update

Ok, Borodin's answer actually fixed 2 problems.

WWW::Mechanize::Firefox->new() only works when

  1. The Firefox browser is already open, and
  2. After starting Firefox, you follow Borodin's instructions and also start MozRepl

I had expected the Perl script to act like a shell script, and start Firefox for me. This is not the case.

Also, if you hide the menu bar in Firefox, the "Tools" menu is the only menu that is not accessible in the drop-down list that appears on the top left. You have to show the menu bar to access the "Tools" menu.


Source: (StackOverflow)

How can we tell WWW::Mechanize::Firefox to not wait for a response or a postback?

Hi I am using a loop to get various pages.

The code:

while($stm->fetch()) {
    $mech->get(**#TheURL**);

            $mech->select( 'this', 'that' );
            $mech->tick( 'this' => undef );
            $mech->tick( 'this' => undef  );
            $mech->tick( 'this' => undef  );
            $mech->tick( 'this' => undef  );
            my $button = $mech->selector('input.button', single => 1);
            $mech->click($csvbutton);
} 

The code above downloads the file after clicking the button. However it stops after the first iteration.

I have changed the configuration of Firefox to disable the download manager popup.

I received this error once:

MozRepl::RemoteObject::Object has no function addProgressListener at `$mech->get(**#TheURL**);`

Any assistance would be appreciated. Thanks.

UPDATE:

I have found that it gets stuck on the first download because WWW::Mechanize::Firefox is waiting for a response or postback which it does not get. A file is just downloaded.

$mech->click($csvbutton);

This is the place where it stop. If i manually manipulate the page (ie. go back or go to the homepage or a new URL), it will continue on the loop. So it is waiting for a new page load.

How do i tell WWW::Mechanize::Firefox to not wait for a response or new page load?

Thanks


Source: (StackOverflow)

Simplest way to launch Firefox, drive 3rd party site using privileged nsI* APIs

What's the simplest way to launch Firefox, load a 3rd party website (which I'm authorised to "automate"), and run some "privileged" APIs against that site? (e.g: nsIProgressListener, nsIWindowMediator, etc).

I've tried a two approaches:

  1. Create a tabbed browser using XULrunner, "plumbing" all the appropriate APIs required for the 3rd party site to open new windows, follow 302 redirects, etc. Doing it this way, it's an aweful lot of code, and requires (afaict) that the user installs the app, or runs Firefox with -app. It's also extremely fragile. :-/

  2. Launch Firefox passing URL of the 3rd party site, with MozRepl already listening. Then shortly after startup, telnet from the "launch" script to MozRepl, use mozIJSSubScriptLoader::loadSubScript to load my code, then execute my code from MozRepl in the context of the 3rd party site -- this is the way I'm currently doing it.

With the first approach, I'm getting lots of security issues (obviously) to work around, and it seems like I'm writing 10x more browser "plumbing" code then automation code.

With the second approach, I'm seeing lots of "timing issues", i.e:

  • the 3rd party site is somehow prevented from loading by MozRepl (or the execution of the privileged code I supply)???, or
  • the 3rd party site loads, but code executed by MozRepl doesn't see it load, or
  • the 3rd party site loads, and MozRepl isn't ready to take requests (despite other JavaScript running in the page, and port 4242 being bound by the Firefox process),
  • etc.

I thought about maybe doing something like this:

Modify the MozRepl source in some way to load privileged JavaScript from a predictable place in the filesystem at start-up (or interact with Firefox command-line arguments) and execute it in the context of the 3rd party website.

... or even write another similar add-on which is more dedicated to the task.

Any simpler ideas?


Update:

After a lot of trial-and-error, answered my own question (below).


Source: (StackOverflow)

trouble installing MozRepl

I've been trying to install WWW::Mechanize::Firefox through CPAN and I am having trouble installing the dependency MozRepl. The installation goes through but the tests all fail, and when I force install it and run my perl script, I run into an error

Failed to connect to ,  at /Library/Perl/5.12/MozRepl/RemoteObject.pm line 467.

SO I uninstalled MozRepl and looked at the tests I get the following errors in the log:

#   Failed test at t/10-plugin-repl-enter.t line 11.
Can't locate object method "repl_enter" via package "MozRepl" at t/10-plugin-repl-enter.t line 12.

...

#   Failed test at t/20-plugin-json.t line 16.
Can't locate object method "json" via package "MozRepl" at t/20-plugin-json.t line 17.

#   Failed test at t/19-plugin-repl-util-doc_for.t line 14.
Can't locate object method "repl_doc_for" via package "MozRepl" at t/19-plugin-repl-util-doc_for.t line 16.

#   Failed test at t/18-plugin-repl-util-help_url_for.t line 14.
Can't locate object method "repl_help_url" via package "MozRepl" at t/18-plugin-repl-util-help_url_for.t line 16.

etc..

I am running on Mac OSX 10.8.4, 4 GB Ram 2.5 Ghz, Perl version 5.12. Does anybody have any idea what is causing these errors?

UPDATE: i reinstalled mozrepl, and now I get this error when i run my script:

Failed to connect to , problem connecting to "localhost", port 4242: Connection refused at /Users/thui/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/MozRepl/Client.pm line 144

Source: (StackOverflow)