NAME
Firefox::Application - inspect and automate the Firefox UI
SYNOPSIS
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.
METHODS
Firefox::Application->new( %args )
use
Firefox::Application;
my
$ff
= Firefox::Application->new();
Creates a new instance and connects it to Firefox.
Note that Firefox must have the mozrepl
extension installed and enabled.
The following options are recognized:
launch
- name of the program to launch if we can't connect to it on the first try.log
- array reference to log levels, passed through to MozRepl::RemoteObjectbufsize
- Net::Telnet buffer size, if the default of 1MB is not enoughrepl
- a premade MozRepl::RemoteObject instance or a connection string suitable for initializing one.use_queue
- whether to enable MozRepl::RemoteObject command queueingapi
- class for the API wrapperYou 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.
APPLICATION INFORMATION
$ff->appinfo
my
$info
=
$ff
->appinfo;
'ID : '
,
$info
->{ID};
'name : '
,
$info
->{name};
'version : '
,
$info
->{version};
Returns information about Firefox.
$ff->addons( %args )
for
my
$addon
(
$ff
->addons) {
sprintf
"Name: %s\n"
,
$addon
->{name};
sprintf
"Version: %s\n"
,
$addon
->{version};
sprintf
"GUID: %s\n"
,
$addon
->{id};
};
Returns the list of installed addons as nsIUpdateItem
s (FF 3.5+) or Addon
s (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.
$ff->locales( %args )
for
my
$locale
(
$ff
->locales) {
sprintf
"Name: %s\n"
,
$locale
->{name};
sprintf
"Version: %s\n"
,
$locale
->{version};
sprintf
"GUID: %s\n"
,
$locale
->{id};
};
Returns the list of installed locales as nsIUpdateItem
s.
$ff->themes( %args )
for
my
$theme
(
$ff
->themes) {
sprintf
"Name: %s\n"
,
$theme
->{name};
sprintf
"Version: %s\n"
,
$theme
->{version};
sprintf
"GUID: %s\n"
,
$theme
->{id};
};
Returns the list of installed locales as nsIUpdateItem
s.
$ff->updateitems( %args )
for
my
$item
(
$ff
->updateitems) {
sprintf
"Name: %s\n"
,
$item
->{name};
sprintf
"Version: %s\n"
,
$item
->{version};
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 of items to fetchANY
- fetch any itemADDON
- fetch add-onsLOCALE
- fetch localesTHEME
- fetch themes
$ff->current_profile
$ff
->current_profile->{name},
"\n"
;
Returns currently selected profile as nsIToolkitProfile
.
See https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIToolkitProfile.
$ff->find_profile( $name )
$ff
->find_profile(
""
)->{localDir},
"\n"
;
Returns the profile given its name. Dies if the profile cannot be found.
$ff->profiles
for
(
$ff
->profiles) {
"Profile: "
,
$_
->{name},
"\n"
;
}
Lists the installed profiles as nsIToolkitProfile
s.
See https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIToolkitProfile.
UI METHODS
$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.
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();
"$_->{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->getMostRecentWindow
Returns the most recently used Firefox window.
$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
$ff->bool_ff_to_perl $val
Normalizes the (checkbox) truth value $val
to 1 or 0.
Different Firefox versions return true
or false
as the checkbox values. This function converts a Firefox checkbox value to 1 or 0.
$ff->bool_perl_to_ff $val
Normalizes the truth value $val
to 1 or 0.
Different Firefox versions want true
or false
as the checkbox values. This function converts a Perl truth value to 1 or 0 respectively true
or false
, depending on what Firefox wants.
TODO
Consider how to roll http://kb.mozillazine.org/Command_line_arguments into this module for convenient / versatile launching of Firefox
AUTHOR
Max Maischein corion@cpan.org
COPYRIGHT (c)
Copyright 2009-2013 by Max Maischein corion@cpan.org
.
LICENSE
This module is released under the same terms as Perl itself.