Firefox 57 has reached Beta, and a bevy of new APIs and improvements have landed that will put us in a good place for the Firefox Quantum launch in November.

Legacy add-ons no longer load in Firefox 57, but there is still time to migrate (almost 5,000 have migrated so far!), and you can do so even after it lands in release. Just update your listing with the new code and your users will automatically update to the compatible version. When you do, be sure to tell them about it.

Documentation for the APIs discussed here can be found on MDN Web Docs.

API changes

Tabs and Sessions APIs

Tabs now have a discarded state added to the Tab object. It will be set to true if the tab is not loaded with content, for example when restored from a previous session. This is part of getting ready for a tabs.discard API.

The tabs.opener API has now been implemented which means that openerTabId is available to the update and create methods and on the Tab object. This allows extensions to track the opener of tabs.

Also, the tabs API can now open URLs that are view-source: links and do a “load replace” which changes the page and replaces the current history so that the back button is unaffected.

The session API now has some APIs for setting, getting and removing data on a per tab or per window basis. This allows information about tabs or windows to survive session restores without the data needing to be stored by individual extensions.

webRequest API

The webRequest details object now includes proxy information. This proxy information will let webRequest listeners determine how the request interacted with a proxy.

A major new API for webRequest is now available which allows an extension to filter the HTTP response bodies as they come in. The code below alters the text on example.com. You could do this through a content script, but being able to alter the HTTP response body gives a whole new set of possibilities:

function listener(details) { let filter = browser.webRequest.filterResponseData(details.requestId); let decoder = new TextDecoder("utf-8"); let encoder = new TextEncoder(); filter.ondata = event => { let str = decoder.decode(event.data, {stream: true}); str = str.replace(/Example/g, 'WebExtension Example'); filter.write(encoder.encode(str)); filter.disconnect(); } return {}; } browser.webRequest.onBeforeRequest.addListener( listener, {urls: ["https://example.com/*"], types: ["main_frame"]}, ["blocking"] );

Storage API

A basic implementation of chrome.storage.managed has landed. This allows administrators or other applications to configure extensions for users. In Firefox you can place a JSON file in a directory, just like for native messaging. For example, a file called favourite-colour-examples@mozilla.org.json could be placed in the appropriate place:

{ "name": "favourite-colour-examples@mozilla.org", "description": "ignored", "type": "storage", "data": { "colour": "blue!" } }

Then in the favourite-colour-examples@mozilla.org extension:

browser.storage.managed.get('colour').then((colour) => { console.log(colour); });

Would output “blue!”.

Clipboard API

A new clipboard API has been added to allow the copying of images to the clipboard. The clipboard.setImageData allows you to populate the clipboard with image data. This API is compatible with the Chrome apps API, but at this point it should be considered experimental. This API requires the clipboardWrite permission.

Developer Tools API

The developer tools gained the panels.elements.createSidebarPane API and a panels.elements sidebar.setExpression method. This lets extensions create sidebars in the developer tools. Here’s an example extension that parses jQuery variables:

Find API

A find API has landed in Firefox. This allows extensions to call the Firefox find API on a tab and get information about the results. It can then add or remove syntax highlighting from that tab, based on the previous search.

This example extension uses the API to search across multiple tabs and highlights them:

Miscellaneous changes

Android

There have been multiple bugs fixed to ensure that pageActions and browserActions work well on Android. There has been multiple options_ui fixes and some additions. The runtime.openOptionsPage API has been added, and for those pages the activeTab permission takes effect. The browser_action.default_popup manifest property along with setPopup and getPopup has been added.

Firefox for Android now has support for installation permission prompts from the user, closely matching Desktop. When a user installs an add-on, they will be given a permission prompt.

Here’s an example when installing uBlock Origin:

If an extension chooses not to use installation permissions, the optional permission prompts have also been implemented which enable permission prompts at runtime.

Startup check

Firefox has had a brief compatibility check that occurs each time Firefox upgrades a major release. Because there are some extension that might update from legacy extensions sometime after Firefox 57 is released, we wanted to ensure that we could update users to new WebExtensions version when we can.

We took the opportunity to streamline this. The new check is quick and will only occur each time you upgrade to a major version (for example 56 to 57) and have legacy extensions:

User notification

There’s an ongoing project to show Firefox users what changes extensions make to their browser. Often it’s not clear to a user what an extension has done. It can be especially confusing if a user forgets what extensions are installed and finds changes they don’t understand later on.

An API was added that allows extensions to read the home page and new page values so extensions can tell if a user or another extension has changed the values. Along with this API, we’re now surfacing changes through to the about:preferences pages. If an extension uses the provided APIs to change: the home page, the new tab or contextual identities in Firefox 57, then a message will displayed to the user.

Here’s an example where an extension changes the home page:

An example where an extension enables contextual identities:

Long running scripts in an extension will now generate a warning that mentions the extension name, so users can choose what to do with extensions that might be taking a long time.

If an extension changes the new tab through the API, the URL bar will be empty when the new tab page is opened. This allows keyboard users to quickly navigate to new URLs. We’ve also fixed a bug where the identity was not shown in the URL bar for new tabs.

Over the coming releases we plan to add in more information into about:preferences for more and more APIs.

Contributors

Thank you once again to our many contributors for this release, especially our volunteers including: Adam Hillier, angelsl, dw-dev, Jan Henning, Kevin Jones, Lee Bousfield, Tomislav Jovanovic and Tushar Saini. This release marked a record 171 bugs fixed.