This is an archived page. It's not actively maintained.

Browser API

This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

See bug 1318532 for exposing this API to WebExtensions in Firefox.

The HTML Browser API is an extension of the HTML <iframe> element that allows web apps to implement browsers or browser-like applications. It currently works in (privileged) chrome code on Firefox desktop (version 47 and above).

Browser API concepts and usage

The Browser API consists of two major parts:

  • Custom <iframe> attributes: By adding a mozbrowser attribute to the <iframe> element we can make it appear like a top-level browser window to the embedded content. This means that, window.parent, window.frameElement, etc. should not reflect the frame hierarchy.
  • API extensions: The API includes several new methods and events to manipulate and listen for changes to the embedded content's state, interited by the HTMLIFrameElement interface.

Browser API interfaces

To support the requirement of a browser <iframe>, the HTMLIFrameElement DOM interface has been extended with new methods that give the <iframe> some super powers.

The following navigation methods allow navigation through the browsing history of the <iframe>. They are necessary to be able to implement back, forward, stop, and reload buttons.

Allows reloading of the <iframe> element content.
Allows stopping of the <iframe>'s content loading.
Indicates whether it's possible to navigate backwards.
Changes the location of the <iframe> for the previous location in its browsing history.
Indicates whether it's possible to navigate forward.
Changes the location of the <iframe> for the next location in its browsing history.

Management methods

The next set of methods manage the resources used by a browser <iframe>. These are especially useful for implementing tabbed browser application.

Changes the visibility state of a browser <iframe>. This can influence resource allocation and some function usage such as requestAnimationFrame.
Indicates the current visibility state of the browser <iframe>.
Sets the current <iframe> as the active frame, which has an effect on how it is prioritized by the process manager.
Indicates whether the current browser <iframe> is the currently active frame.

The following methods allow direct control of sound in the browser element.

Gets the current volume of the browser <iframe>.
Sets the current volume of the browser <iframe>.
Mutes any audio playing in the browser <iframe>.
Unmutes any audio playing in the browser <iframe>.
Indicates whether the browser <iframe> is currently muted.

In order to manage the browser <iframe>'s content, many new events were added (see below). The following methods are used to deal with those events:

The <iframe> gains support for the methods of the EventTarget interface
addEventListener(), removeEventListener(), and dispatchEvent().
Sends a MouseEvent to the <iframe>'s content.

Utility methods

Last, there are some utility methods, useful for apps that host a browser <iframe>.

Retrieves any structured microdata (and hCard and hCalendar microformat data) contained in the HTML loaded in the browser <iframe> and returns it as JSON.

Browser API methods removed in Firefox 65

In Firefox 65, several of the Mozilla Browser API methods were removed in an effort to cut down on DOMRequest usage in the browser, and remove the parts of the Browser API that are no longer needed (it is used only by the Firefox DevTools at this point). See bug 1503070 for more details.

The methods removed in Firefox 65 are:

Defines a handler to listen for the next MozAfterPaint event in the browser <iframe>.
Clears any content highlighted by findAll() or findNext().
Downloads a specified URL, storing it at the specified filename/path.
Allows a specified script to be executed against a page loaded in the browser <iframe>.
Searches for a string in a browser <iframe>'s content; if found, the first instance of the string relative to the caret position will be highlighted.
Highlights the next or previous instance of a search result after a findAll() search has been carried out.
Retrieves the X and Y dimensions of the content window.
Retrieves the manifest of an app loaded in the browser <iframe> and returns it as JSON.
Takes a screenshot of the browser <iframe>'s content. This is particularly useful to get thumbnails of tabs in a tabbed browser app.
Clears all the resources (cookies, localStorage, cache, etc.) associated with the browser <iframe>.
Sends a TouchEvent to the <iframe>'s content. Note that this method is available for touch enabled devices only.
Removes a handler previously set with addNextPaintListener().
Changes the zoom factor of the browser <iframe>'s content. This is particularly useful for zooming in/out on non-touch-enabled devices.


In order to allow an application to manage the browser <iframe>, the application can listen for new events about what's happening within the browser <iframe>. The following new events can be listened for:

Sent when something inside the browser <iframe> triggers a web activity, and that web activity's message is consumed by the receiving app.
Sent when the browser <iframe> content scrolls (the APCZ version.) See also mozbrowserscroll. Note that this is obsolete.
Sent when audio starts or stops playing within the browser <iframe> content.
Sent when the text selected inside the browser <iframe> content changes.
Sent when window.close() is called within a browser <iframe>.
Sent when a browser <iframe> tries to open a context menu. This allows  handling of the <menuitem> element available within the browser <iframe>'s content.
Sent when a new paint occurs on any document in the browser <iframe>.
Sent when an error occurs while trying to load content within a browser <iframe>.
Sent when a search operation is performed on the browser <iframe> content (see HTMLIFrameElement search methods.)
Sent when the <iframe> paints content for the first time (this doesn't include the initial paint from about:blank.)
Sent when a new icon (e.g. <link rel="icon"> or <link rel="apple-touch-icon">) is available in the browser <iframe>'s content.
Sent when the browser <iframe> has finished loading all its assets.
Sent when the browser <iframe> starts to load a new page.
Sent when a browser <iframe>'s location changes.
Sent when a the path to the app manifest changes, in the case of a browser <iframe> with an open web app embedded in it.
Sent when a <meta> elelment is added to, removed from or changed in the browser <iframe>'s content.
Sent when is called within a browser <iframe>.
Sent when a new tab is opened within a browser <iframe> as a result of the user issuing a command to open a link target in a new tab (for example ctrl/cmd + click.)
Sent when the browser <iframe>'s window size has changed.
Sent when the browser <iframe> content scrolls.
Sent when the available scrolling area in the browser <iframe> changes. This can occur on resize and when the page size changes (while loading for example.)
Sent when asynchronous scrolling (i.e. APCZ) starts or stops.
Sent when the SSL state changes within a browser <iframe>.
Sent when the text selected inside the browser <iframe> content changes. Note that this is obsolete, and newer implementations use mozbrowsercaretstatechanged instead.
Sent when alert(), confirm(), or prompt() are called within a browser <iframe>.
Sent when the document title changes within a browser <iframe>.
Sent when an HTTP authentification is requested.
Sent when a link to a search engine is found.
Sent when the visibility state of the current browser iframe <iframe> changes, for example due to a call to setVisible().


This API isn't part of any official specification.

Browser compatibility

Supported Firefox 47 in chrome (privileged) code only.

See also