Firefox/URL Bar Algorithm
< Firefox
Jump to navigation
Jump to search
This page documents the steps Firefox takes as a user types some text into the URL bar, and when they press "Enter" or "Go".
While The User Is Typing
From the very first character typed, we dynamically search:
- history titles and URLs
- bookmark titles, URLs and tags
- open tabs titles and URLs
with search results limited to some subset of those sources if requested, according to this algorithm.
When Enter Is Pressed
(Adding a Ctrl or Shift modifier changes the behaviour; the below is the unmodified algorithm.)
Before Network
Function getShortCutOrURI in browser.js.
- If the string contains a space, split on the first space and examine the first token.
- If it's a search engine keyword, expand using the relevant search URL.
- If it's a user-defined keyword, expand that.
...
- If it looks like a search according to this algorithm, insert it into the keyword.URL preference value to produce a search URL, since the
keyword.enabledpreference defaults to true in Firefox. - The algorithm says it's a search if it contains a space or a quote before the first dot, colon or question mark, or if it starts with a question mark.
...
- If we're looking at something that does not have a scheme specified, prepend either "ftp://" or "http://" depending on whether
nsDefaultURIFixup::IsLikelyFTPreturns true. - Try to construct an
nsIURI. If that fails, fall back on producing a search url from keyword.URL, since againkeyword.enableddefaults to true. - Start the network load.
Network
- Since the
keyword.enabledpreference is true, if DNS lookup for the hostname failed and the URI scheme contains the string "http" and the hostname does not contain a '.' then plug the hostname (possibly after some decoding from punycode to UTF-8) into keyword.URL. - If the above step did not produce a
nsIURIand either DNS lookup failed or the network access failed withNS_ERROR_NET_RESET(typically means the server did not respond or dropped the connection immediately) and the protocol is "http" and the url does not contain a username or password then because thebrowser.fixup.alternate.enabledpreference defaults to true we try to construct an alternate hostname. The steps for this are innsDefaultURIFixup::MakeAlternateURIand are as follows:- Get the prefix to use from the
browser.fixup.alternate.prefixpreference; default is "www.". Some locales set this preference. - Get the suffix to use from the
browser.fixup.alternate.suffixpreference; default is ".com". Some locales set this preference. - If the hostname includes no '.' characters, prepend the prefix and append the suffix. Else if it has a single '.' and the part ending on the '.' is equal to our prefix, append the suffix. Else if it has a single '.' and tour suffix is nonempty prepend the prefix. For the default pref values, this means the foo will become www.foo.com, as will foo.com and www.foo. foo.org will become www.foo.org. web.foo and x.y.foo won't be changed.
- Get the prefix to use from the
- If either of the two steps above produced a URI different from the URI whose load failed, load that new URI.