Firefox::Application - inspect and automate the Firefox UI
use Firefox::Application; my $ff = Firefox::Application->new();
This module will let you automate Firefox through the Mozrepl plugin. You need to have installed that plugin in your Firefox.
For more examples see WWW::Mechanize::Firefox::Examples.
Firefox::Application->new( %args )
Creates a new instance and connects it to Firefox.
Note that Firefox must have the mozrepl extension installed and enabled.
mozrepl
The following options are recognized:
launch - name of the program to launch if we can't connect to it on the first try.
launch
log - array reference to log levels, passed through to MozRepl::RemoteObject
log
bufsize - Net::Telnet buffer size, if the default of 1MB is not enough
bufsize
repl - a premade MozRepl::RemoteObject instance or a connection string suitable for initializing one.
repl
use_queue - whether to enable MozRepl::RemoteObject command queueing
use_queue
api - class for the API wrapper
api
You almost never want to use this parameter, as Firefox::Application asks Firefox about its version.
$ff->repl
my ($value,$type) = $ff->repl->expr('2+2');
Gets the MozRepl::RemoteObject instance that is used.
$ff->appinfo
my $info = $ff->appinfo; print 'ID : ', $info->{ID}; print 'name : ', $info->{name}; print 'version : ', $info->{version};
Returns information about Firefox.
$ff->addons( %args )
for my $addon ($ff->addons) { print sprintf "Name: %s\n", $addon->{name}; print sprintf "Version: %s\n", $addon->{version}; print sprintf "GUID: %s\n", $addon->{id}; };
Returns the list of installed addons as nsIUpdateItems (FF 3.5+) or Addons (FF4+). See https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIUpdateItem or https://developer.mozilla.org/en/Addons/Add-on_Manager/Addon, depending on your Firefox version.
nsIUpdateItem
Addon
$ff->locales( %args )
for my $locale ($ff->locales) { print sprintf "Name: %s\n", $locale->{name}; print sprintf "Version: %s\n", $locale->{version}; print sprintf "GUID: %s\n", $locale->{id}; };
Returns the list of installed locales as nsIUpdateItems.
$ff->themes( %args )
for my $theme ($ff->themes) { print sprintf "Name: %s\n", $theme->{name}; print sprintf "Version: %s\n", $theme->{version}; print sprintf "GUID: %s\n", $theme->{id}; };
$ff->updateitems( %args )
for my $item ($ff->updateitems) { print sprintf "Name: %s\n", $item->{name}; print sprintf "Version: %s\n", $item->{version}; print sprintf "GUID: %s\n", $item->{id}; };
Returns the list of updateable items. The type of item can be restricted by the type option.
type
type - type of items to fetch
ANY - fetch any item
ANY
ADDON - fetch add-ons
ADDON
LOCALE - fetch locales
LOCALE
THEME - fetch themes
THEME
$ff->current_profile
print $ff->current_profile->{name}, "\n";
Returns currently selected profile as nsIToolkitProfile.
nsIToolkitProfile
See https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIToolkitProfile.
$ff->find_profile( $name )
print $ff->find_profile("")->{localDir}, "\n";
Returns the profile given its name. Dies if the profile cannot be found.
$ff->profiles
for ($ff->profiles) { print "Profile: ", $_->{name}, "\n"; }
Lists the installed profiles as nsIToolkitProfiles.
$ff->addTab( %options )
my $new = $ff->addTab();
Creates a new tab and returns it. The tab will be automatically closed upon program exit.
If you want the tab to remain open, pass a false value to the the autoclose option.
autoclose
The recognized options are:
repl - the repl to use. By default it will use $ff->repl.
autoclose - whether to automatically close the tab at program exit. Default is to close the tab.
$ff->selectedTab( %options )
my $curr = $ff->selectedTab();
Sets the currently active tab.
$ff->closeTab( $tab [,$repl] )
$ff->closeTab( $tab );
Close the given tab.
$ff->openTabs( [$repl] )
my @tab_info = $ff->openTabs(); print "$_->{title}, $_->{location}, \n" for @tab_info;
Returns a list of information about the currently open tabs.
$ff->activateTab( [ $tab [, $repl ]] )
$ff->activateTab( $mytab ); # bring to foreground
Activates the tab passed in.
$ff->browser( [$repl] )
my $b = $ff->browser();
Returns the current Firefox browser instance, or opens a new browser window if none is available, and returns its browser instance.
If you need to call this as a class method, pass in the MozRepl::RemoteObject bridge to use.
$ff->set_tab_content( $tab, $html [,$repl] )
$ff->set_tab_content('<html><h1>Hello</h1></html>');
This is a more general method that allows you to replace the HTML of an arbitrary tab, and not only the tab that WWW::Mechanize::Firefox is associated with.
It has the flaw of not waiting until the tab has loaded.
$ff->quit( %options )
$ff->quit( restart => 1 ); # restart $ff->quit(); # quit
Quits or restarts the application
Consider how to roll http://kb.mozillazine.org/Command_line_arguments into this module for convenient / versatile launching of Firefox
Max Maischein corion@cpan.org
corion@cpan.org
Copyright 2009-2012 by Max Maischein corion@cpan.org.
This module is released under the same terms as Perl itself.
To install WWW::Mechanize::Firefox, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Mechanize::Firefox
CPAN shell
perl -MCPAN -e shell install WWW::Mechanize::Firefox
For more information on module installation, please visit the detailed CPAN module installation guide.