++ed by:

10 PAUSE users
10 non-PAUSE users.

Max Maischein


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 )

  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::RemoteObject

  • bufsize - Net::Telnet buffer size, if the default of 1MB is not enough

  • repl - a premade MozRepl::RemoteObject instance or a connection string suitable for initializing one.

  • use_queue - whether to enable MozRepl::RemoteObject command queueing

  • api - class for the API wrapper

    You almost never want to use this parameter, as Firefox::Application asks Firefox about its version.


  my ($value,$type) = $ff->repl->expr('2+2');

Gets the MozRepl::RemoteObject instance that is used.



    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.

$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};

Returns the list of installed locales as nsIUpdateItems.

$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 of items to fetch

    ANY - fetch any item

    ADDON - fetch add-ons

    LOCALE - fetch locales

    THEME - fetch themes


    print $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 )

    print $ff->find_profile("")->{localDir}, "\n";

Returns the profile given its name. Dies if the profile cannot be found.


    for ($ff->profiles) {
        print "Profile: ", $_->{name}, "\n";

Lists the installed profiles as nsIToolkitProfiles.

See https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIToolkitProfile.


$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();
    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] )


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



Max Maischein corion@cpan.org


Copyright 2009-2011 by Max Maischein corion@cpan.org.


This module is released under the same terms as Perl itself.