2

Right now Firefox shows the full URL in the title bar for visited sites. There is a browser.urlbar.trimURLs preference in about:config which hides the http:// prefix but not https://. Other browsers like Safari and Chrome hide the https:// prefix as well as www.. Is it possible to replicate this behavior in Firefox?

1 Answers1

2

You can add support for this in Firefox by including the following in a firefox.cfg (or equivalent) AutoConfig file:

// -*- mode: javascript; -*- vim: set ft=javascript:
// See https://support.mozilla.org/en-US/kb/customizing-firefox-using-autoconfig
"use strict";

(() => { if (Services.appinfo.inSafeMode) { return; }

const addressPattern = new RegExp( "^(chrome:(?!//(global/content/commonDialog)\.xhtml)|about:(?!blank))" ); const hostnameStripPattern = new RegExp("^www\.");

Services.obs.addObserver(subject => { subject.addEventListener( "DOMContentLoaded", event => { const document = event.originalTarget; const window = document.defaultView; if (!addressPattern.test(window.location.href)) { return; }

    // Hide URL scheme once editing in URL bar is finished.
    const urlbarInput = document.getElementById("urlbar-input");
    const updateURLHandler = () => {
      if (!window.gURLBar.focused) {
        const untrimmedValue = urlbarInput.value;
        let url;
        try {
          url = new window.URL(untrimmedValue);
        } catch (error) {
          // Catch TypeError: URL constructor errors for invalid/partial URLs.
          if (error instanceof window.TypeError) {
            return;
          }
          throw error;
        }

        // Preserve existing behavior for built-in prefixes like "view-source:".
        if (url.protocol !== "https:" && url.protocol !== "http:") {
          return;
        }

        const suffix = url.pathname + url.search + url.hash;
        const displayValue =
          url.hostname.replace(hostnameStripPattern, "") +
            (suffix === "/" ? "" : suffix);

        if (displayValue !== urlbarInput.value) {
          window.gURLBar.value = displayValue;
          window.gURLBar._untrimmedValue = untrimmedValue;
        }
      }
    };

    urlbarInput?.addEventListener("SetURI", updateURLHandler);
    urlbarInput?.addEventListener("blur", updateURLHandler);
  },
  { once: true }
);

}, "chrome-document-global-created"); })();

See this answer for additional context and installation instructions.

This will recreate Chrome's behavior, where the https://[www.] prefix is removed but the suffix is retained unless it's only a /. To use Safari's behavior (which removes the suffix entirely and only shows the domain), change displayValue to url.hostname.replace(hostnameStripPattern, "").

You may also want to turn on the security.insecure_connection_text.enabled preference in about:config or user.js to show a "Not Secure" indicator in the URL bar for HTTP sites.

user_pref("security.insecure_connection_text.enabled", true);

There's an open issue for this on Bugzilla here.

Update: This is now officially supported in version 119 and above via the browser.urlbar.trimHttps preference.

user_pref("browser.urlbar.trimHttps", true);