Firefox 4 技術文件

2010 年六月起進入 Beta 測試期的 Firefox 4,增進了效能、加強針對 HTML 5 及其他創新網際科技的支援程度,也更加安全。本文為網頁、附加元件、Gecko 平台開發者們提供這一版的簡要技術相關資訊。

Gecko 1.9.3 即將更名為 Gecko 2,但許多文件還沒有針對此點更新,在接下來的幾個星期中才會有所更動。

以下大部分的功能都已經可以在 逐日建置版中試用。

備註: 本文、以及本文所連結的其他文件仍持續編修中,很多文件的名稱只是暫定、有些主題的文件也可能會拆成幾份子文件以方便閱讀。中文團隊的目標將僅翻譯這份概覽,其他子文件則有待大家的幫忙。

Features for web developers

Gecko now uses the HTML5 parser, which fixes bugs, improves interoperability, and improves performance. It also lets content embed SVG and MathML directly in the HTML markup.


Introduction to the HTML5 parser

A look at what the HTML5 parser means to you, and how to embed SVG and MathML into your content inline.

Forms in HTML5

A look at improvements to web forms in HTML5.

HTML5 Sections

Gecko now supports the new HTML5 elements related to sections in a document: <article> (en-US), <section> (en-US), <nav>, <aside> (en-US), <hgroup> (en-US), <header> (en-US) and <footer> (en-US).

Other HTML5 elements

Gecko now also supports the following new HTML5 elements: <mark> (en-US), <figure> (en-US) and <figcaption> (en-US).


A guide to using the new WebSockets API for real-time communication between a web application and a server.

Miscellaneous HTML changes

  • <textarea> (en-US) elements are now resizable by default; you can use the resize (en-US) CSS property to disable this.
  • canvas.getContext and canvas.toDataURL no longer throw an exception when called with unrecognized arguments.
  • canvas2dcontext.globalCompositeOperation, canvas2dcontext.lineCap and canvas2dcontext.lineJoin no longer throw an exception when set to an unrecognized value.


CSS transitions

New CSS transitions support is available in Firefox 4.

Computed values in CSS

Support forcalc()to compute values in CSS is in progress. See Firefox bug 363249.

Selector grouping

Support for :-moz-any (en-US) to group selectors and factorize combinators.

Background image subrectangle support

The -moz-image-rect (en-US) property makes it possible to use subrectangles of images as a background image.

CSS touch properties

Support for touch properties is added. Details, and real article names, to come later.

Privacy and the :visited selector

Changes have been made to what information can be obtained about the style of visited links using CSS selectors. This may affect some web applications.

Miscellaneous CSS changes

Graphics and video


The developing WebGL standard is now supported by Firefox.

Optimizing graphics performance

Tips and tricks for getting the most out of graphics and video performance in Firefox 4.

Support for WebM video

The new open WebM video format is supported by Gecko 1.9.3; support is included in nightlies as of 9 June.

Full screen API

Details coming soon.

SMIL animation

Support for SMIL animation of SVG is now available. See Firefox bug 482402.

Using SVG as images and as CSS backgrounds

You can now use SVG with the <img> (en-US) element, as well as the background image in CSS. See Firefox bug 272288, Firefox bug 276431 and Firefox bug 231179.


Obtaining boundary rectangles for ranges

The Range object now has getClientRects() and getBoundingClientRect() methods. See Firefox bug 396392.

Capturing mouse events on arbitrary elements

Support for the Internet Explorer-originated setCapture() and releaseCapture() APIs has been added. See Firefox bug 503943.

Manipulating the browser history

The existing document history object, available through the window.history object, now supports the new HTML5 pushState() and replaceState() methods.

Touch and multi-touch events

Support has been added for touch and multi-touch events.


The proposed IndexedDB standard, which provides a local database store for web applications, will be supported by Firefox 4.

Miscellaneous DOM changes


Introducing Content Security Policy

Content Security Policy (CSP) is a Mozilla proposal designed to help web designers and server administrators specify how content on their web sites interacts. The goal is to help detect and mitigate attacks including cross-site scripting and data injection attacks.


Details soon.

The Account Manager

Details soon.


For an overview of the changes implemented in JavaScript 1.8.5, see New in JavaScript 1.8.5. JavaScript in Firefox 4 will have additional adherence to the ECMAScript 5 standard.

Changes for Mozilla and add-on developers

For helpful tips on updating existing extensions for Firefox 4, see Updating extensions for Firefox 4.

JavaScript code modules


The Services.jsm code module provides getters that make it easy to obtain references to commonly-used services, such as the preferences service or the window mediator, among others.

JS-ctypes API

The JS-ctypes API makes it possible to call C-compatible foreign library functions without using XPCOM.

Add-ons Manager

The new Add-ons Manager provides information about installed add-ons, support for managing them, and provides ways to install and remove add-ons.

Loading code modules from chrome: URLs

You can now load JavaScript code modules using chrome: URLs, even inside JAR files.

DOM changes


A new type of worker for privileged code; this lets you use things like js-ctypes from workers in extensions and application code.


tabbrowser (gBrowser) changes

Several changes were made to the <xul:tabbrowser> element that impact extensions that interact with tabs.

  • TabClose/TabSelect/TabOpen events no longer bubble up to the <xul:tabbrowser> element (gBrowser). Event listeners for those events should be added to gBrowser.tabContainer rather than to gBrowser directly.
  • The tab context menu is no longer an anonymous child of the <xul:tabbrowser>. It can therefore be overlaid directly with XUL overlays. It can also be accessed more directly in JS via gBrowser.tabContextMenu. See this blog post for more details.

Miscellaneous XUL changes

  • The readonly attribute now correctly works for fields.
  • The <xul:resizer> element now lets you use the element attribute to specify an element to resize, instead of resizing the window.
  • The "active" attribute no longer gets set on active XUL windows. Instead, you can use the new :-moz-window-inactive (en-US) pseudoclass in order to assign different styles to background windows.
  • The emptytext attribute is now deprecated; you should use placeholder instead.
  • The <xul:popup> element is no longer supported; you should use <xul:menupopup> instead.


Miscellaneous storage API changes

  • The mozIStorageBindingParamsArray interface now has a length attribute that indicates the number of mozIStorageBindingParams objects in the array.
  • The mozIStorageStatement.bindParameters() now returns an error if the specified mozIStorageBindingParamsArray is empty.


XPCOM changes in Gecko 1.9.3

Details about changes to XPCOM that impact compatibility in Firefox 4.


This new method returns the global object with which an object is associated; this replaces a common use case of the now-removed __parent__.

Memory management

Infallible memory allocation

Mozilla now provides infallible memory allocators that are guaranteed not to return null. You should read this article to learn how they work and how to explicitly request fallible versus infallible memory allocation.

Other changes

Gopher support removed

The Gopher protocol is no longer supported natively. Continued support is available via the OverbiteFF extension.

Default plugin removed

The default plugin has been removed. The application plugins folder has also been removed by default, however support for installing plugins via this folder still exists. See bug 533891.

Extension Manager replaced with AddonManager

nsIExtensionManager has been replaced by AddonManager. Since there is apparently no way at present to obtain the install location from a given extension ID, the closest workaround is to use the directory service to find the profile directory and append "extensions" to it (though this approach will not catch extensions outside of the profile directory or those which are aliased to another location).