19 Browser Module

This chapter provides a complete listing and reference for the methods in the OpenScript BrowserService Class of Browser Utility Module Application Programming Interface (API).

19.1 BrowserService API Reference

The following section provides an alphabetical listing of the methods in the OpenScript BrowserService API.

19.1.1 Alphabetical Command Listing

The following table lists the BrowserService API methods in alphabetical order.

Table 19-1 List of BrowserService Methods

Method Description

browser.clearBrowser

Clear the browser.

browser.close

Closes the Browser.

browser.closeAllBrowsers

Closes all instances of the browser created by the current user including browser instances created outside of OpenScript.

browser.getBrowser

Gets the current browser.

browser.getBrowserProcessID

Gets the browser launch process id.

browser.getFirefoxUtility

Get the Firefox Utility to retrieve information about the Firefox browser.

browser.getSettings

Gets the browser settings.

browser.launch

Launch the browser specified in BrowserSettings.getBrowserType().

browser.setBrowserType

Sets the browser type.


The following sections provide detailed reference information for each method and enum in the BrowserService Class of Browser Utility Module Application Programming Interface.

browser.clearBrowser

Clear the browser. Sets Browser to null when the user makes the BHO to close the browser.

Format

The browser.clearBrowser method has the following command format(s):

browser.clearBrowser( );

Example

Clear the browser.

browser.clearBrowser();

browser.close

Closes the Browser.

Format

The browser.close method has the following command format(s):

browser.close( );

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Close the browser.

browser.close();

browser.closeAllBrowsers

Closes all instances of the browser created by the current user including browser instances created outside of OpenScript.

This API will always try to terminate the browser process directly, so if you only need to close the browser launched by OpenScript, use browser.close() instead.

Format

The browser.closeAllBrowsers method has the following command format(s):

browser.closeAllBrowsers( );

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Close all browser instances created by the current user.

browser.closeAllBrowsers();

browser.getBrowser

Gets the current browser.

Format

The browser.getBrowser method has the following command format(s):

browser.getBrowser( );

Returns

Current browser. Returns null if no browser has been launched yet.

Example

Get the current browser and print its path.

IBrowser browser1 = browser.getBrowser();
info(browser1.getBrowserPath());

browser.getBrowserProcessID

Gets the browser launch process id.

Format

The browser.getBrowserProcessID method has the following command format(s):

browser.getBrowserProcessID( );

Returns

the browser launch process id.

Example

Gets the current browser process id and print it.

long pid = browser.getBrowserProcessID();
info("Browser PID:"+pid);

browser.getFirefoxUtility

Get the Firefox Utility to retrieve information about the Firefox browser.

This utility is used to retrieve information, set Firefox preferences during playback, (for example, get a list of all installed extensions), or to disable popup windows during playback.

Format

The browser.getFirefoxUtility method has the following command format(s):

browser.getFirefoxUtility( );

Returns

FirefoxUtility an instance of the FirefoxUtility.

Example

Get the Firefox Utility and then get all installed extensions.

FirefoxUtility firefoxUtility = browser.getFirefoxUtility();
List<String> extensions = firefoxUtility.getAllInstalledExtensions();

browser.getSettings

Gets the browser settings.

Format

The browser.getSettings method has the following command format(s):

browser.getSettings( );

Returns

All settings pertaining to the Browser Service.

Example

Get the browser settings and then get the browser type.

BrowserSettings settings = browser.getSettings();
info(settings.getBrowserType().toString());  

browser.launch

Launch the browser specified in BrowserSettings.getBrowserType().

The Browser will use any additional parameters specified in the BrowserSettings.getExtraParams() setting. BrowserService will automatically determine the appropriate path for the specified browser type. If specified, BrowserSettings.getBrowserPathOverride() will be used for the browser path instead of the automatically determined path. If the BrowserService's browser is already running, launch() will do nothing.

Format

The browser.launch method has the following command format(s):

browser.launch( );

Throws

AbstractScriptException

represents an exception that may be thrown during the execution of a script where the exception should be reported to an end user through the controller.

Example

Launch the browser.

browser.launch();

browser.setBrowserType

Sets the browser type.

Format

The browser.setBrowserType method has the following command format(s):

browser.setBrowserType(browserType);

Command Parameters

browserType

BrowserType enum specifying the supported browser types. For example, BrowserType.InternetExplorer.

Throws

BrowserException

if browser type cannot be changed.

Example

Sets the browser type.

//Specify Browser as Mozilla Firefox.
browser.setBrowserType(BrowserType.Firefox);
//Specify Browser as Internet Explorer.
browser.setBrowserType(BrowserType.InternetExplorer);
//Specify Browser as Chrome.
browser.setBrowserType(BrowserType.Chrome);