Search code examples
javascriptfirefoxgoogle-chrome-extensionfirefox-addonfirefox-addon-webextensions

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


Solution

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