282

Is there a way I can add a custom search URL to the Firefox search bar? e.g. I'd like to provide a URL such as https://blahblah.com?search=%s, where Firefox replaces the %s with the content of the search box.

Both IE and Opera can do this, but I can't figure out how to set it up in Firefox.

Andrew Grant
  • 3,224

20 Answers20

248

Actual answer:

@Kleinfrund's answer is valid but Firefox doesn't always recognize sites that support search. If the website doesn't show up using @Kleinfrund's method, continue reading.

  1. Open a new tab and type in the address bar:
    • about:config
  2. In the search box type:
    • browser.urlbar.update2.engineAliasRefresh
  3. Click on the little + symbol on the right. This is what it should look like after you pressed it: boolean true value after pressing plus sign
  4. Go to Firefox Settings → Search. Or enter this in the address bar:
    • about:preferences#search
  5. In the "Search Shortcuts" section you should notice a new "Add" button. search add button
  6. Press the "Add" button and fill in the name, search engine url and a keyword (optional). The engine url should contain a %s in the url; Firefox replaces the %s with your search terms. An example of this is:
    • https://www.google.com/search?q=%s
  7. Go to the "Default Search Engine" section and select the engine you just added.

PS: This does not work for search engines that use POST requests.

Dave M
  • 13,250
BugSquanch
  • 3,053
229

I'd like to provide a URL such as https://blahblah.com?search=%s where Firefox replaces the %s with the content of the search box.

You can do this with Firefox! Add a bookmark with that URL, where %s is the search query, then simply set a keyword for the bookmark. You can then search using <key> <search term> in the address bar. For example, the bookmark https://www.google.com/search?q=%s with keyword g means you can type g stack overflow in the address bar to search Google for "stack overflow".

Alternatively, go to the site you want to search, right click in the search box and click "Add a keyword for this search".

142

The method to do this has changed - this answer is how to do it in 2018. Read further down to see more recent answers


Add keywords to the address bar:

For example, you can set up your browser to search for bread at stackoverflow.com by simply typing so bread into the omnibar.

Do this by right-clicking on the search bar on the website you commonly search. You can do this for the Search field on any website.

Right click on the search bar

Specifically:

  1. Go to the site you want to use to search
  2. Right-Click on the search box you fill out on their page (not Firefox's)
  3. Select "Add a keyword"
  4. Enter the keyword to use when you want to search in that site (eg: "so")
Greenonline
  • 2,390
Javier
  • 3,935
49

The actual, no-bookmark solution for this task:

  1. Open a web page that has a search on it (e.g. SuperUser: superuser.com).

  2. In the address bar, expand the address bar by clicking on it.

  3. If the website supports searching, it will show up in the bottom area of the expanded address bar. Click the plus icon that is enclosed in a green circle. This adds the web page’s search to the search engines in your preferences.

Screenshot of the bottom of Firefox's expanded address bar when on superuser.com

Alternatively:

  1. Open a web page that has a search on it (e.g. SuperUser: superuser.com).
  2. Right-click on the address bar.
  3. If the website supports searching, where will be an option to add it.

Screenshot of the Firefox's context menu for the address bar when on superuser.com

If you want to set a keyword (e.g. su) for this search, follow these steps:

  1. Open the search preferences (or type the following URI in your address bar: about:preferences#search)
  2. In the table under the column for “Keyword”, double-click in order to set your own keyword.
33

The Add custom search engine extension lets you create a new search engine and customize it.

Synetech
  • 69,547
spaetzel
  • 579
23

Your best bet is to go to the Mycroft Project and search for an already made search engine plugin.

If you can't find one you can create your own on the submissions page. Full instructions are available.

geekley
  • 236
Dalvenjia
  • 231
  • 2
  • 2
8

Ready2Search is also an available free service that helps you do this for any site. It makes search plug-in for Internet Explorer, Firefox, Chrome, and Google Toolbar with great customization options (icons, query parameters, etc.).

Screenshot of Ready2Search

warmth
  • 1,014
8

Alternative way for custom search

For an example Google Translate string: https://translate.google.com/m/translate#auto/en/%s so top answer here doesn't work. So I found a workaround with the plugin: add-custom-search-engine

And here we go:

enter image description here

Goes to :

enter image description here

skywinder
  • 343
6

New solution (since the previous one does not work anymore):

Now if you visit a website like Twitter, Firefox will let you add the Twitter search easily (https://support.mozilla.org/en-US/kb/add-or-remove-search-engine-firefox). But in case you want to add another website that is not supported, you will need a web server like Apache. Below would be the solution for Twitter in case they don't use the search engine file opensearch.xml anymore.

Create a file, for example twitter_search.htm (this HTML source code is used on twitter.com, I just removed the / before opensearch.xml):

<link rel="search" type="application/opensearchdescription+xml" href="opensearch.xml" title="Twitter">

Then create another file, with the same name used in the href parameter of the previous HTML code, for example opensearch.xml with this content (this XML source code is used at https://twitter.com/opensearch.xml):

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
  <ShortName>Twitter</ShortName>
  <Description>Twitter Search</Description>
  <Url type="text/html" method="get" template="https://twitter.com/search?q={searchTerms}"/>
  <Image width="16" height="16">https://abs.twimg.com/favicons/favicon.ico</Image>
  <InputEncoding>UTF-8</InputEncoding>
  <moz:SearchForm>https://twitter.com/search-home</moz:SearchForm>
</OpenSearchDescription>

If needed, customize these files to replace the search URL, search form URL, name, description and icon. Put these 2 files in a folder of your web server and open the HTML file that you can find by visiting http://localhost in your web browser. You will be able to add your custom search engine to Firefox.

Previous solution (not working anymore):

Here is how I restored the Twitter search engine for Firefox, which seems to have been removed in Firefox 78 (you could create a search for other websites also based on this answer):

I tested with the Linux version of Firefox (Ubuntu package) but it should work with any operating system by creating the distribution folder / subfolders and search plugin file (https://wiki.mozilla.org/Mobile/Distribution_Files).

In my profile folder .mozilla/firefox/xxx.default/, there was a file search-metadata.json that contained a link to a non-existing file /usr/lib/firefox/distribution/searchplugins/locale/en-US/twitter.xml.

So I created this file with the following content (based on the documentation https://developer.mozilla.org/en-US/docs/Mozilla/Creating_MozSearch_plugins and search plugins already present https://packages.ubuntu.com/focal/amd64/firefox/filelist):

<?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
  <ShortName>Twitter</ShortName>
  <Description>Twitter Search</Description>
  <InputEncoding>UTF-8</InputEncoding>
  <Image height="16" width="16">data:image/x-icon;base64,
AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAA
AAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A
////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD/
//8A////AP///wD///8A////AP///wD///8A////AP///wz///8f////H////x////8Y////B///
/wD///8A////AP///wD///8A////AP///wD///8A////A////yj7789g9tV+ofbVfqH21X6h+N+e
ifz03lf///8o////A////wD///8A////AP///wD///8A////APr37g/PsGCftogQ7r2JAP/bnwD/
7qwA/+6sAP/urAD/9Mtftv357z////8D////AP///wD///8A////AP///wD///8A////AP///w/5
7c5a88VQwu6sAP/urAD/7qwA/+6sAP/xvDDb/fnvP////wD///8A////AP///wD///8A////AP//
/wDz5L5X7bgv2+6sAP/urAD/7qwA/+6sAP/urAD/7qwA//G8MNv///8Y////AP///wD///8A////
AP///wD///8M9NN+n+6wD/PurAD/7qwA/+6sAP/urAD/7qwA/+6sAP/urAD/9Nyegf///wD///8A
////AP///wD///8A+O3PVu6wD/PurAD/7qwA/+6sAP/urAD/7qwA/+6sAP/urAD/7qwA//G8MNv/
//8A////AP///wD///8A////ANasQMXurAD/7qwA/+qpAP/YnAD/1JkA/+6sAP/urAD/7qwA/+6s
AP/urAD/////FP///wD///8A////AP///wDz255+7qwA/9icAP+6ixDuz7Bgn9m8b5TurAD/7qwA
/+6sAP/urAD/7qwA//jkr3j///8M////AP///wD///8A47Y/ysmRAP/PsGCf+vfuD////wDw584w
46QA/+6sAP/urAD/7qwA/9+hAP/orA/z9OrPQv///wD///8A////AMypT7Hhz55g////AP///wD/
//8A////AMOaL9DMlAD/0JYA/8mRAP/FoEC/vpIf4OPQnmL///8A////AP///wD69+4P////AP//
/wD///8A////AP///wD69+4P3ceOcNi/foHhz55g////APr37g/69+4P////AP///wD///8A////
AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A
////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD/
//8A//8AAP//AAD//wAA8P8AAMA/AAD4HwAA8A8AAOAHAADgBwAAwAcAAOAHAADHAwAA3wMAAP/f
AAD//wAA//8AAA==</Image>
  <Url type="text/html" method="get" template="https://twitter.com/search?q={searchTerms}"/>
</OpenSearchDescription>

To get the Base64 of the latest Twitter icon that you can see above, I downloaded https://twitter.com/favicon.ico and used the Linux command base64 favicon.ico.

The following files were present in my profile folder but were not needed anymore so I removed them to avoid potential conflicts (you can backup files in case you want to reuse them): search-metadata.json, search.json, search.json.mozlz4.

The following answers did not work for me but contained useful information:

https://stackoverflow.com/questions/9963256/adding-a-custom-search-engine-to-firefox/10034461#10034461

https://stackoverflow.com/questions/9963256/adding-a-custom-search-engine-to-firefox/40651019#40651019

baptx
  • 264
5

You can also make complex searches with multiple parameters, and here’s how.

For instance, imagine you have a two field search like this fictitious example:

http:// mymusic.com/search?artist=david+bowie&album=ziggy+stardust

You can make a new mm search like:

javascript:q="%s";if(q.indexOf(",")>0){q=q.split(",");location.href="http://mymusic.com/search?artist="+q[0]+"&album="+q[1]}

(in Firefox it would be a bookmark with keyword mm)

Then you can directly search for: mm david bowie,ziggy startdust (directly in the address bar)

I choose “,” as the separator, but it’s just an example. It’s perfectible, but you get the idea, and anything is possible.

※ Notice that some browsers (including Opera 12) may not execute your JavaScript in a new tab with no preloaded page.

4

For ESR, you can add (and set default) a new search engine using policies.json. E.g. use the following:

{
  "policies": {
    "SearchEngines": {
      "Default": "DuckDuckGo",
      "Add": [
        {
          "Name": "DuckDuckGo",
          "URLTemplate": "https://duckduckgo.com/?q={searchTerms}&t=h_&kp=1&ia=web",
          "Method": "GET",
          "IconURL": "https://duckduckgo.com/favicon.ico",
          "Alias": "Ducky",
          "Description": "Duck Duck Goose"
        }
      ]
    }
  }
}

The location of the policies file is described e.g. in this post.

serv-inc
  • 538
  • 1
  • 4
  • 18
4

Update 2022: Now you can just right-click the URL on the address bar and click Add <name of the site>. It will show up in about:preferences > Search Shortcuts, from where you can assign a keyword.

enter image description here

Ron
  • 149
3

As of FF100, for the website searches that cannot be added with Green plus, a solution is to use the mozlz4-edit plugin.

FF stores all the search engines within a file search.json.mozlz4 that cannot be edited in a regular text editor.

With that plugin, one can directly (but guided) add search engines.

E.g. Adding "AllMusic" as search engine: enter image description here

If you want a icon, you can dowload an icon from the website and add it too.

Rem: you have first to locate that search.json.mozlz4 file. On Win10 it is in %appdata%\Mozilla\Firefox\Profiles\xx_profile_id_xx.default-release\

lvr123
  • 253
3

This can be done using the browser console (hamburger menu/more tools/browser console, or ctrl+shift+j).

Services.search.addUserEngine(
    "Google Verbatim",
    "https://www.google.com/search?q={searchTerms}&tbs=li:1",
    "gv"
);

To remove,

Services.search.getEngineByAlias("gv").then(engine => Services.search.removeEngine(engine));

This service is documented here (appears to be slightly out of date, eg removeEngine isn't listed; you might look in the implementation source file for more complete info.)

0

A bit late to the party, but for those finding this thread now you can click the search icon in the search bar when on the site you want if it has a green + icon on it.

0

To mimic chrome's "site search" feature: https://www.reddit.com/r/firefox/comments/ob8ffw/question_custom_url_for_duckduckgo_search_when/h3mcfh7/

worked exactly as expected and super easy to config

Jason
  • 1
0

[As of August 2022]

If you happen to have Duck Duck Go set as your search engine, !Bangs are another option.

Drazisil
  • 227
0

I've created an online web app that lets you add custom search engines to Firefox, simply enter the info then click add and corner click in the URL bar:

https://svelte.dev/repl/8b4c3b768f4041888bd64cbaffbb8135?version=4.1.1

Svelte Code

<script>
    let searchUrl = '';
    let name = "";
    let image = "";
    let encoding = "UTF-8";
    let description = "";
    $: error = searchUrl ? (!searchUrl.startsWith('https://') ? 'URL invalid' : '') : 'Search URL must be present';
    function getXML({
  name,
  url,
  image,
  suggestUrl,
  encoding,
  description,
  usePost,
  postParams,
}) {
  const XML_TEMPLATE = `<?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>####REPLACE####</ShortName>
<Description></Description>
<InputEncoding>UTF-8</InputEncoding>
<Image height="16" width="16"></Image>
<Url type="text/html" method="get" template=""></Url>
<Url type="application/x-suggestions+json" method="get" template=""></Url>
</OpenSearchDescription>`;
  const parser = new DOMParser();
  const doc = parser.parseFromString(XML_TEMPLATE, "application/xml");

  // Name
  const shortName = doc.getElementsByTagName("ShortName")[0];
  shortName.textContent = name;

  // Search URL
  const searchUrl = doc.querySelector('Url[type="text/html"]');
  searchUrl.setAttribute("template", url.replace(/\%s/g, '{searchTerms}'));
  if (usePost) {
    searchUrl.setAttribute("method", "POST");
    for (const [name, value] of Object.entries(postParams)) {
      const param = doc.createElementNS(
        "http://a9.com/-/spec/opensearch/1.1/",
        "Param",
      );
      param.setAttribute("name", name);
      param.setAttribute("value", value);
      searchUrl.append(param);
    }
  } else {
    searchUrl.setAttribute("method", "GET");
  }

  // Icon
  const img = doc.getElementsByTagName("Image")[0];
  if (image) {
    img.textContent = image;
  } else {
    img.remove();
  }

  // Suggest URL
  const suggestSearchUrl = doc.querySelector(
    'Url[type="application/x-suggestions+json"]',
  );
  if (suggestUrl) {
    suggestSearchUrl.setAttribute("template", suggestUrl);
  } else {
    suggestSearchUrl.remove();
  }

  // Input Encoding
  const inputEncoding = doc.getElementsByTagName("InputEncoding")[0];
  if (encoding) {
    inputEncoding.textContent = encoding;
  }

  // Description
  const desc = doc.getElementsByTagName("Description")[0];
  if (description) {
    desc.textContent = description;
  } else {
    desc.remove();
  }

  const serializer = new XMLSerializer();
  return serializer.serializeToString(doc);
}

    async function addSearchEngine(xml){
        if (document.querySelector("button")?.disabled){return}
        let url = await fetch("https://cors.explosion.workers.dev?https://paste.mozilla.org/api/", {
            "credentials": "omit",
            "headers": {
                "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0",
                "Accept": "*/*",
                "Accept-Language": "en-US,en;q=0.5",
                "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
                "Sec-Fetch-Dest": "empty",
                "Sec-Fetch-Mode": "cors",
                "Sec-Fetch-Site": "same-origin"
            },
            "body": `content=${encodeURIComponent(xml)}&format=url&lexer=xml`,
            "method": "POST",
            "mode": "cors"
        }).then(r => r.text()).then(t => t.trim());
        console.log(url)
        window.open(URL.createObjectURL(new Blob([
            `
         <head><link rel="search" type="application/opensearchdescription+xml" title=${JSON.stringify(name)} href="${url}/raw"></head>
         <h1>Corner click the URL bar and click "Add ${name.replace(/[^a-z0-9 ]+/gi, ' ')}"</h1>
        <style>body {display: grid; place-items: center; height: 100vh;} h1 {font-family: sans-serif; font-size: 2rem; font-weight: 100; width: 100%; display: block; text-align: center}</style>
        `
        ], {type: 'text/html'})), '_blank')
    }
</script>
<div class='container'>
    <h1>Add search engine</h1>
    <input bind:value={name} placeholder="Name"/>
    <input bind:value={searchUrl} placeholder="Search engine URL (use %s for search term)"/>
    <input bind:value={description} placeholder="Description"/>
    <input bind:value={image} placeholder="Image URL (data urls work)"/>
    <input bind:value={encoding} placeholder="Encoding"/>
    {#if error}<span>{error}</span>{/if}
    <button disabled={!!error} on:click={() => addSearchEngine(getXML({name, url: searchUrl, image, encoding: encoding || "UTF-8", description}))}>Add</button>
</div>

<style>
    span {
        font-style: italic;
        font-weight: 200;
        color: #777;
    }
    .container {
        display: flex;
        flex-direction: column;
        gap: 10px;
        width: 80vw;
        max-width: 600px;
        margin: 0 auto;
    }

    input {
        padding: 8px 15px;
        border-radius: 3px;
        border: 1px solid #eee;
    }
    button {
        padding: 8px;
        cursor: pointer;
    }
    h1 {
        font-weight: 100;
        text-align: center;
        width: 100%;
        display: block;
    }

</style>
Explosion
  • 121
0

It's as simple as right clicking in a search field.

The other advantage is that this process creates a bookmark for you. If you use something like XMarks to synchronize your bookmarks, you can access the same search functionality across all synchronised computers.

brack
  • 262
-2

I believe he's referring to keyword.URL in Firefox's about:config page.

In Firefox's address bar type about:config, then search for keyword.URL and replace its contents with "https://blahblah.com/search?q=", for example.

Sam P
  • 1