The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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

$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;
    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. See https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIUpdateItem.

These functions will need fixing for Firefox 4.

$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

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->addTab( %options )

    my $curr = $ff->selectedTab();

Returns 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.

TODO

AUTHOR

Max Maischein corion@cpan.org

COPYRIGHT (c)

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

LICENSE

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