fab
fab

Reputation: 53

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.)

Upvotes: 5

Views: 1204

Answers (2)

Makyen
Makyen

Reputation: 33396

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.

Upvotes: 3

Graham Perrin
Graham Perrin

Reputation: 534

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. …

Upvotes: 3

Related Questions