Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the browser's window title in a WebExtensions based browser add-on

Does the WebExtensions API allow one to change the browser's window title?

Eg. Change "WebExtensions - Stack Overflow - Mozilla Firefox" to "Browser - Window 1" or "Browser - Window 1 - WebExtensions - Stack Overflow"

It was possible for Firefox in old XUL extensions (see the FireTitle extension.)

like image 574
fab Avatar asked Nov 25 '16 09:11

fab


2 Answers

Possible, to an extent, in Desktop Firefox 56 and newer

In Firefox 56, Mozilla added the titlePreface property to what can be passed in the updateInfo parameter in calls to windows.update().

MDN's documentation for the titlePreface property says:

string Use this to add a string to the beginning of the browser window's title. Depending on the underlying operating system, this might not work on browser windows that don't have a title (such as about:blank in Firefox).

Example:

To add the prefix "Current Window: " to the current window's title, you could do the following:

browser.windows.getCurrent()
    .then(winInfo => browser.windows.update(winInfo.id, {titlePreface:'Current Window: '}));

Not possible in Google Chrome, Firefox for Android, Firefox Desktop prior to version 56, or other browsers

The Browser Compatibility section for windows.update() indicates that the only browser in which this feature is available is Desktop Firefox version 56+, so it's not possible in other browsers using WebExtensions.

like image 144
Makyen Avatar answered Oct 07 '22 03:10

Makyen


Mozilla bug 1333376 - Feature request: a WebExtension API to change the window title

RESOLVED FIXED in Firefox 56

From WebExtensions in Firefox 56 | Mozilla Add-ons Blog (2017-08-10):

… The windows API now has the ability to read and preface the title of the window object, by passing titlePreface to the window object. This allows extensions to label different windows so they’re easier to distinguish. …

like image 36
Graham Perrin Avatar answered Oct 07 '22 02:10

Graham Perrin