files/en-us/mozilla/firefox/releases/4/index.md
Firefox 4, which shipped on March 22, 2011, enhances performance, adds more support for HTML5 and other evolving Web technologies, and further improves security. This article provides information about this release and what features are available for Web developers, add-on developers, and Gecko platform developers alike.
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.
The following changes were made to the {{domxref("CanvasRenderingContext2D")}} interface to bring our {{HTMLElement("canvas")}} implementation closer to being in line with the specification:
arc() now correctly throws an INDEX_SIZE_ERR exception.createLinearGradient() and createRadialGradient() now throws NOT_SUPPORTED_ERR instead of SYNTAX_ERR.miterLimit to a negative value no longer throws an exception; instead, it properly ignores non-positive values.lineWidth to a negative value no longer throws an exception; instead, it properly ignores non-positive values.putImageData() method now supports the optional parameters dirtyX, dirtyY, dirtyWidth, and dirtyHeight.canvas.getContext and canvas.toDataURL no longer throw an exception when called with unrecognized arguments.mozGetAsFile() method, which lets you obtain a memory-based file containing an image of the canvas's contents. See {{domxref("HTMLCanvasElement")}} for details.Canvas2DContext.lineCap and Canvas2DContext.lineJoin no longer throw an exception when set to an unrecognized value.Canvas2DContext.globalCompositeOperation no longer throws an exception when set to an unrecognized value, and no longer supports the non-standard darker value.<spacer> element, which was absent in all other browsers, has been removed.<isindex> element, when created by calling {{domxref("Document.createElement()")}}, is now created as a simple element with no properties or methods.click() on {{HTMLElement("input")}} elements to open the file picker. See the example in the article Using files from web applications.mozactionhint attribute, which lets you specify the label for the enter key on virtual keyboards.-moz-calc has been added. This lets you specify {{cssxref("length")}} values as mathematical expressions.:-moz-any to group selectors and factorize combinators.-moz-element CSS function and the {{domxref("document.mozSetImageElement()")}} DOM function to use arbitrary HTML elements as backgrounds.| Old Name | New Name | Notes |
|---|---|---|
-moz-background-size | {{cssxref("background-size")}} | The name -moz-background-size is no longer supported. |
-moz-border-radius | {{cssxref("border-radius")}} | The old name is supported for a limited time to allow you time to update your sites. Rendering changes have also been made to match the latest version of the specification. |
-moz-box-shadow | {{cssxref("box-shadow")}} |
<thead>, <tbody>, and <tfoot>).-moz-appearance property now supports the -moz-win-borderless-glass value, which applies a borderless Aero Glass look to an element.-moz-device-pixel-ratio media feature has been added, allowing the use of the device pixels per CSS pixel ratio to be used in Media Queries.buffered attribute support
buffered attribute on {{HTMLElement("video")}} and {{HTMLElement("audio")}} elements is now supported, letting you determine which ranges of a media file have been buffered. The {{domxref("TimeRanges")}} DOM interface has been implemented to support this.preload attribute
preload attribute from the HTML5 specification has been implemented, replacing the previously-implemented (and no longer supported) autobuffer attribute. This affects the {{HTMLElement("video")}} and {{HTMLElement("audio")}} elements, as well as the nsIDOMHTMLMediaElement interface.x, y, dx, and dy properties on SVG {{SVGElement("text")}} and {{SVGElement("tspan")}} elements. This lets you control the positioning of each character in a string individually.setCapture() and releaseCapture() APIs has been added. See Firefox bug 503943.pushState() and replaceState() methods.MozBeforePaint
window.mozRequestAnimationFrame() method and window.mozAnimationStartTime property, provides a way to create animations that are synchronized with one another.Several HTML elements have had their DOM interfaces changed to the ones required by the HTML5 specification, as shown below.
| Interface in Firefox 3.6 | Interface in Firefox 4 | HTML Element |
|---|---|---|
HTMLSpanElement | HTMLElement | {{HTMLElement("abbr")}}, {{HTMLElement("acronym")}}, {{HTMLElement("address")}}, {{HTMLElement("b")}}, {{HTMLElement("bdo")}}, {{HTMLElement("big")}}, <blink>, {{HTMLElement("center")}}, {{HTMLElement("cite")}}, {{HTMLElement("code")}}, {{HTMLElement("dd")}}, {{HTMLElement("dfn")}}, {{HTMLElement("dt")}}, {{HTMLElement("em")}}, {{HTMLElement("i")}}, {{HTMLElement("kbd")}}, <listing>, {{HTMLElement("nobr")}}, {{HTMLElement("plaintext")}}, {{HTMLElement("s")}}, {{HTMLElement("samp")}}, {{HTMLElement("small")}}, {{HTMLElement("strike")}}, {{HTMLElement("strong")}}, {{HTMLElement("sub")}}, {{HTMLElement("sup")}}, {{HTMLElement("tt")}}, {{HTMLElement("u")}}, {{HTMLElement("var")}}, {{HTMLElement("xmp")}} |
HTMLDivElement | HTMLElement | {{HTMLElement("noembed")}}, {{HTMLElement("noframes")}}, {{HTMLElement("noscript")}} |
HTMLWBRElement | HTMLElement | {{HTMLElement("wbr")}} |
wrap DOM attribute. Firefox bug 41464src attribute execute as soon as available (without maintaining ordering) and scripts without the src attribute execute synchronously. To make script-inserted scripts that have the src attribute execute in the insertion order, set .async=false on them.url property.FormData support for XMLHttpRequest.mozSourceNode property to the {{domxref("DataTransfer")}} object.window.directories object and the directories feature for {{domxref("window.open")}}, which are not supported in any other browser, has been removed. Use personalbar instead. Firefox bug 474058< and > around the tag name in quirks mode.mousedown event has occurred.window.mozPaintCount property has been added; it lets you determine how many times a document has been painted. This can be useful when testing performance of your web application.Accept-Language header instead. Firefox bug 572656mozResponseArrayBuffer property.mozPressure property indicating the amount of pressure on supported pressure-sensitive input devices.Node.mozMatchesSelector() now throws a SYNTAX_ERR exception if the specified selector string is invalid, instead of incorrectly returning false.element.style.fill = 'lime'. See {{domxref("HTMLElement/style", "style")}} for details.privatebrowsingmode attribute that describes the state of private browsing mode, including an indication of whether private browsing is temporary or permanent for the session.dom.min_timeout_value.MozAfterPaint event is no longer sent by default, due to a potential security issue. It can be re-enabled by setting a preference.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.
[!NOTE] The Error Console is disabled by default starting in Gecko 2.0. You can re-enable it by changing the
devtools.errorconsole.enabledpreference totrueand restarting the browser.
For helpful tips on updating existing extensions for Firefox 4, see Updating extensions for Firefox 4. There are several key changes that break compatibility with existing add-ons, so be sure to read that article.
If you're a theme developer, you should read Theme changes in Firefox 4 to understand some critical changes you'll need to be aware of.
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.DownloadLastDir.jsm code module provides the gDownloadLastDir global variable, which contains a string you can use to learn the path of the directory into which the last download occurred. This module handles issues related to private browsing for you.PerfMeasurement.jsm code module provides an API to measure CPU-level performance data in JavaScript code.NetUtil.jsm code module now offers the readInputStreamToString() method, which lets you read arbitrary bytes from a stream into a string, even if the stream includes zeroes.ChromeWorker
Several changes were made to the <xul:tabbrowser> element that impact extensions that interact with tabs. In addition to supporting app tabs, these changes also change the tab bar into a standard toolbar, which lets the user drag toolbar buttons into it.
TabClose, TabSelect, and 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.<xul:tabbrowser>. It can therefore be overlaid directly with XUL overlays. It can also be accessed more directly in JavaScript via gBrowser.tabContextMenu. See this blog post for more details.visibleTabs property was added to let you get an array of the currently visible tabs; this lets you determine which tabs are visible in the current tab set. This is used by Firefox Panorama, for example.showOnlyTheseTabs method; this is used by Firefox Panorama.getIcon method, which lets you get a tab's favicon without having to pull up the <xul:browser> element.tabbrowser.tabs property, which lets you easily get a list of the tabs in a <xul:tabbrowser> element.pinTab and unpinTab methods let you pin and unpin tabs (that is, switch them between being app tabs and regular tabs).getTabModalPromptBox method and tabModalPromptShowing attribute to the <xul:tabbrowser> to support tab-modal alerts.<xul:popup> element is no longer supported; you should use <xul:menupopup> instead. (If you continue using popup, you will encounter glitches, since the element has no special meaning anymore. For example, <xul:menuseparator> can appear transparent when used in a <xul:popup>.)<xul:menupopup> XUL element now has a triggerNode property, which indicates the node on which the event occurred that caused the popup to open. This also required the addition of a trigger event parameter to the openPopup method. Also, the anchorNode property has been added; it returns the anchor specified when the popup was created.<xul:panel> element now offers fade and flip attributes, which are used to configure the behavior of new "arrow" style notification panels.Remote XUL is no longer supported; this affects XUL documents being served through HTTP; also, you can no longer load XUL documents using file:// URLs unless you create the preference dom.allow_XUL_XBL_for_file and set it to true. There is, however, a whitelist feature that can be used to allow specific domains to load remote XUL.
readonly attribute now correctly works for XBL fields.<xul:resizer> element now lets you use the element attribute to specify an element to resize, instead of resizing the window.<xul:resizer> element now has a type attribute that lets you specify that the resizer is for a window instead of an element, to prevent the window resizer from being drawn twice."active" attribute no longer gets set on active XUL windows. Instead, you can use the new :-moz-window-inactive pseudoclass in order to assign different styles to background windows.emptytext attribute is now deprecated; you should use placeholder instead.<xul:window> element now offers an accelerated attribute; when true, the hardware layer manager is permitted to accelerate the window.<xul:stack> element now supports the bottom and right attributes.<xul:toolbox> customization, allowing you to detect changes to toolbars.alternatingbackground attribute for <xul:tree> elements is no longer supported; you can use the :-moz-tree-row pseudo-class instead.<xul:tabs> element now has a tabbox property, replacing the old _tabbox property, which has been deprecated (and was never documented).<xul:window> elements now have the drawintitlebar attribute; if this is true, the window's content area includes the title bar, allowing drawing into the title bar.TabPinned and TabUnpinned events are available, allowing you to detect when tabs are pinned and unpinned.TabAttrModified event is sent when a tab's label, crop, busy, image, or selected attributes change.<xul:tab> elements now have a pinned attribute, letting you determine whether or not a tab is currently pinned.setDirectionIndicator class on <xul:tree> elements hasn't done anything for some time now; now it's not used at all anymore.<xul:window> element now has a chromemargin attribute that lets you set the margin between chrome and content on each side of a window; you can use this to draw into the title bar, for example.<xul:window> element now has a disablechrome attribute; this is used to hide most of the chrome in a window when it's being used to display in-browser UI, such as about:addons.<xul:window> element now has a disablefastfind attribute, which lets you disable the find bar in a window when the content doesn't support it. This is used, for example, by the add-ons panel.<xul:toolbox>, by setting the toolboxid property of the <xul:toolbar>. Also, the <xul:toolbox> element now has an externalToolbars property, which lists all the toolbars that are considered members of the toolbox.about:addons does this.mozIStorageBindingParamsArray interface now has a length attribute that indicates the number of mozIStorageBindingParams objects in the array.mozIStorageStatement.bindParameters() method now returns an error if the specified mozIStorageBindingParamsArray is empty.mozIStorageConnection.clone() method, which lets you clone an existing database connection.mozIStorageConnection.asyncClose() method, which lets you close a database connection asynchronously; you specify a callback to be notified when the close operation is complete.mozIStorageConnection.setGrowthIncrement() method, which lets you specify the amount by which a database file is grown at a time, in order to help SQLite reduce fragmentation.SQLITE_CONSTRAINT error is now reported as NS_ERROR_STORAGE_CONSTRAINT instead of as NS_ERROR_FAILURE.In addition to the specific changes referenced below, it's important to note that there are no longer any frozen interfaces. All interfaces are now unfrozen, regardless of what the documentation may say. We'll update the documentation over time.
__parent__.nsINavHistoryResult, nsINavHistoryQueryOptions, and nsINavHistoryContainerResultNode interfaces. More significantly, the nsINavHistoryResultViewer interface has been renamed to nsINavHistoryResultObserver.places-connection-closed notification is available to know when the Places service has completed its shutdown process.<menupopup type="places"> has been removed. Instead, you need to create and populate a menu with Places information manually, instead of having it done for you. See Displaying Places information using views: Menu view for details.nsIDocShell and nsIWebBrowser interfaces now have a new isActive attribute, which is used to allow optimization of code paths for documents that aren't currently visible.nsIMemory method nsIMemory.isLowMemory() has been deprecated. You should use "memory-pressure" notifications to watch for low memory situations instead.nsIChannelEventSink.onChannelRedirect() needs to be updated to use nsIChannelEventSink.asyncOnChannelRedirect() instead. This accepts a callback handler that must be called when a redirect is successfully completed.nsINavHistoryResultObserver.batching() method has been added, providing a way to group Places operations into batches, reducing the number of update notifications delivered, which can improve performance when observers are performing relatively involved tasks (such as refreshing views).nsIPref interface has finally been removed. If you haven't already switched to nsIPrefService, now is the time.nsISessionStore and nsISessionStartup interfaces received changes to support on-demand session restore. See the nsISessionStore.restoreLastSession() method.nsIPrincipal methods nsIPrincipal.subsumes() and nsIPrincipal.checkMayLoad(), as well as its origin, csp, and URI attributes, are now available from script; previously they were only available from native code.nsIPrompt interface now supports tab-modal alerts; see Using tab-modal prompts for details.nsIEffectiveTLDService.getPublicSuffixFromHost() method now correctly rejects host name starting with a period (".").mozIJSSubScriptLoader.loadSubScript() method now has an optional argument allowing you to specify the character set of the script; if one is not provided, ASCII is assumed (as was always assumed previously).nsIAccessProxy interface has been removed. It was an implementation detail that has outlived its usefulness.nsIContentView and nsIContentViewManager interfaces have been added for Firefox Mobile. It represents a scrollable content view whose contents are actually drawn by a separate process.nsIDiskCacheStreamInternal interface has been added.nsIExternalURLHandlerService interface has been added.nsISyncJPAKE interface has been added. See Firefox bug 601645.nsIINIParserWriter interface was added in Gecko 1.9.2.4 to support writing to INI files.omni.jar, which improves startup performance by reducing I/O. For details, read About omni.jar.accessibility.disablecache preference is no longer supported; it was only exposed for debugging purposes and is no longer used.chrome.manifest file is loaded now; if you need secondary manifest files to be loaded, you can use the manifest command in your root chrome.manifest to load them.nsIExtensionManager has been replaced by AddonManager.browser.gesture.swipe.down to cmd_scrollBottom and browser.gesture.swipe.up to cmd_scrollTop.