Firefox Quantum continues to make news as Mozilla incorporates even more innovative technology into the platform. The development team behind the WebExtensions architecture is no exception, landing a slew of new API and improvements that can now be found in Firefox 59 (just released to the Beta channel).
As always, documentation for the API discussed here can be found on MDN Web Docs (some of the features below are just hitting the main branch as of this post, so if you don’t find the documentation on MDN, check back in a few days).
Tab hiding is back! Since the deprecation of the legacy extension architecture, one of the most requested features has been the ability to hide tabs with the WebExtensions API. It was a key element of some very popular legacy add-ons that provided the ability to manage tab groups. Firefox 59 brings this capability back in an initial, experimental form.
The API is very straightforward:
- Include the “tabHide” permission in your manifest file.
- Use tabs.hide() with the tab ID (or list of tab IDs) to hide tabs.
- Use tabs.show() with the tab ID (or list of tab IDs) to show hidden tabs.
- Examine the tabs.Tab.hidden field to determine if a tab is currently hidden.
Note that the visible state of a tab is completely independent from its discarded state. While it may make sense to keep certain tabs active and loaded in memory while hidden, we encourage you to use tabs.discard() in combination with tabs.hide() to help manage memory and resource usage.
There are certain restrictions when hiding tabs:
- Tabs that are pinned cannot be hidden
- Tabs that are sharing their screen, microphone or camera cannot be hidden
- The current active tab cannot be hidden
- Tabs that are in the process of being closed cannot be hidden
The reintroduction of hidden tabs to Firefox does not come without some concern. A primary motivation for moving to the WebExtensions framework is to offer users a safer extension ecosystem that can be trusted to protect their security and privacy. Obviously, tab hiding opens the door for malicious extensions to hide tabs, doing things in the background without a user’s knowledge.
To make sure we get things right, tab hiding is disabled by default. To enable the API, you must manually go to the about:config page and set extensions.webextensions.tabhide.enabled to true. This restriction will remain in place until:
- Additional user interface features are added to Firefox that allow users to see all of their hidden tabs and/or show those tabs independent of any extension. This user interface work is currently active and on-going.
- Developers (internal and external) have had some time to try the API and understand its strengths and weaknesses. In particular, we want some time to gather input on the potential for abuse.
To be clear, this API is currently experimental. It could change, or even go away entirely if we can’t provide it in a secure manner. Nevertheless, Firefox has a long, proud history of customization and the team is committed to upholding that tradition with tab hiding. So please give the API a try and see what you think. With your help, we will work to make tab hiding as fully functional as possible while still maintaining the security of the WebExtensions architecture.
Want to jump right in a see what it’s like? Give the Tab Hider extension a try.
Additional Tab Features
While tab hiding is the big feature to land in Firefox 59, it isn’t the only thing related to tabs.
- The new browserSettings.openBookmarksInNewTabs() API was added for controlling the options to open bookmarks in new tabs.
- The new browserSettings.openSearchResultsInNewTabs() API was added so extensions can open search results in new tabs.
- Added tabs.captureTab(). This is very similar to tabs.captureVisibleTab(), but allows you to capture any tab (specified by ID) instead of just the active tab.
- Calling tabs.create() without a windowId will now target only non-popup windows.
- Tabs.query() now does pattern matching on the title.
Even More Theme API
Continuing the “theme” of previous releases, Firefox 59 includes a number of additions to the Theme API that allow you to customize even more of the browser’s appearance, including:
- Set the border color of the URL bar and search bar via the “toolbar_field_border” property.
- A slight change in “tab_text” and the addition of “background_tab_text” to better control tab colors.
- Specify the color for a theme property as either a Chrome color array or in standard CSS format.
Improvements to the webRequest API
The webRequest API now merges multiple headers with the same name rather than using only the last one. In addition, a couple of mechanisms were added to the webRequest API to allow for requests to be upgraded from HTTP to HTTPS.
Finally, to make debugging a lot easier, exceptions raised from a webRequest blocking listener now report the original error message and filename. Below is an example:
Register Content Scripts at Runtime
Another big feature landing with Firefox 59 is the ability to register content scripts at runtime. This is an important feature for extensions that want to support user scripting.
Using the contentScripts.register() API, extensions can dynamically associate content scripts with different URLs, lifting the previous limitation that all content scripts had to be listed statically in the manifest file.
Support for Decentralization Protocols
Mozilla has always been a proponent of decentralization, recognizing that it is a key ingredient of a healthy Internet. Starting with Firefox 59, several protocols that support decentralized architectures are approved for use by extensions. The newly approved protocols are:
Firefox itself does not implement these protocols, but having them on the approved list means the browser recognizes them as valid protocols and extensions are free to provide implementations.
browserAction and pageAction Improvements
Browser Actions and Page Actions are two of the most popular types of extensions that we see submitted to the Firefox Add-Ons website. Accordingly, the team behind WebExtensions continues to expand and improve the API for those types of extensions.
- pageActions can now be shown and/or hidden automatically for specific pages via pattern matching using the “hide_matches” and “show_matches” manifest properties. This is a nice performance win for users.
- browserAction set* methods can now accept a null value which removes the property from the browserAction.
- Invalid badge background colors are now rejected (provides more Chrome compatibility).
- An extension can now determine if its browserAction is enabled or disabled (browserAction.isEnabled), a pageAction is currently shown for a tab ( pageActions.isShown), and if its sidebarAction is currently open (sidebarAction.isOpen).
Enhancement to Cookies
The ability for extensions to control cookies in the browser expanded in Firefox 59, including:
- The cookies API now supports first party isolate (FPI) mode and FPI cookies.
- Extensions can now control cookie behaviour by using a new setting in the privacy API, browser.privacy.websites.cookieConfig, which can control which types of cookies are accepted as well as the expiration date of cookies.
Extensions can now override the proxy settings in the browser which has been another highly requested feature. Using the browserSettings.proxyConfig.set() API, the following proxy settings can be controlled:
- proxyType: The type of proxy to use.
- http: The address of the http proxy, can include a port.
- httpProxyAll: Use the http proxy server for all protocols.
- ftp: The address of the ftp proxy, can include a port.
- ssl: The address of the ssl proxy, can include a port.
- socks: The address of the socks proxy, can include a port.
- socksVersion: The version of the socks proxy.
- passthrough: A list of hosts which should not be proxied.
- autoConfigUrl: A URL to use to configure the proxy.
- autoLogin: Do not prompt for authentication if password is saved.
- proxyDNS: Proxy DNS when using SOCKS v5.
User Notification of Extensions Overrides
As with previous releases, when functionality is provided via WebExtensions that allows extensions to control some aspect of the browser, Firefox will inform the user which extension controls that aspect and provide a way for them to regain control.
The ability for an extension to control the browser’s tracking protection setting was added back in Firefox 57 via the websites.trackingProtectionMode API. Firefox 59 now shows when an extension controls tracking protection.
In the above image, notice that a message is now displayed after a user disables an extension reminding them how to re-enable it, also a new feature of Firefox 59.
One of the most popular browser defaults to override is the new tab page. Firefox already shows the user when an extension has overridden that page, but starting with Firefox 59 it also informs the user of the override on the first appearance of the new tab page itself. Plus, it is smart enough to revert back to the previous new tab if the new override is declined.
Additional Browser Controls
To better support mouse gestures, browserSettings.contextMenuShowEvent() has been added in this version. This new API can be set to “mouseup” or “mousedown” by extensions to determine when context menus should be shown. Note that this is not supported on Android, and also calling it with a value of “mousedown” on Windows is a no-op.
Also in Firefox 59, read-only browserSettings now return false when calling set or clear and also report an accurate levelofControl.
Context Menus for Bookmarks
Speaking of context menus, you can now set custom context menus for bookmarks. This will work on the bookmarks toolbar, the library menu, the bookmarks subview, and the bookmarks menu.
Development and Debugging
One of the best ways to suggest a new WebExtension API is to prototype it via an official experiment. Two major changes landed for WebExtension experiments that makes this significantly easier:
Also in Firefox 59, more detail has been added to sandbox names to aid in debugging.
Miscellaneous Changes and Fixes
A number of smaller items were also landed in the new Firefox 59 Beta, including:
- Monitors with different DPI resolutions now work correctly.
- The use of indexDB is no longer impacted by the cookies setting.
- A homepage or search engine override can now be undone.
- The use of ellipses in context menus was fixed.
- Extensions no longer hang when downloading blob URLs.
- Fixed a regression with browser.identity.launchWebAuthFlow.
- Installing a theme with an RGBA accent color no longer locks up the browser.
More to Come
Firefox 59 landed a total of 69 items for WebExtensions, the most important of which are discussed above. Thank you to everyone who had a part in getting it to Beta, especially volunteer contributors Andre Garzia, Tim Nguyen, Oriol Brufau, Javier Serrano Polo, Kevin Jones, Tushar Arora, Martin Giger, Peter Snyder, Lukas Jung. Additional changes and improvements to the WebExtensions API are already in progress for Firefox 60, so please continue to send us your feedback. And as always, thank you for using Firefox and helping ensure that individuals have the ability to shape the Internet and their own experiences on it.