OpenSearch description format lets a website describe a search engine for itself, so that a browser or other client application can use that search engine. OpenSearch is supported by (at least) Firefox, Edge, Internet Explorer, Safari, and Chrome. (See Reference Material for links to other browsers' documentation.)

Firefox also supports additional features not in the OpenSearch standard, such as search suggestions and the <SearchForm> element. This article focuses on creating OpenSearch-compatible search plugins that support these additional Firefox features.

OpenSearch description files can be advertised as described in Autodiscovery of search plugins , and can be installed programmatically as described in Adding search engines from web pages .

OpenSearch description file

The XML file that describes a search engine follows the basic template below. Sections in [square brackets] should be customized for the specific plugin you're writing.

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
  <ShortName>[SNK]</ShortName>
  <Description>[Search engine full name and summary]</Description>
  <InputEncoding>[UTF-8]</InputEncoding>
  <Image width="16" height="16" type="image/x-icon">[https://example.com/favicon.ico]</Image>
  <Url type="text/html" template="[searchURL]">
    <Param name="[key name]" value="{searchTerms}"/>
    <!-- other Params if you need them… -->
    <Param name="[other key name]" value="[parameter value]"/>
  </Url>
  <Url type="application/x-suggestions+json" template="[suggestionURL]"/>
  <moz:SearchForm>[https://example.com/search]</moz:SearchForm>
</OpenSearchDescription>
					
ShortName
A short name for the search engine. It must be 16 or fewer character s of plain text, with no HTML or other markup.
描述
A brief description of the search engine. It must be 1024 or fewer characters of plain text, with no HTML or other markup.
InputEncoding
character encoding to use when submitting input to the search engine.
图像

URI of an icon for the search engine. When possible, include a 16×16 image of type image/x-icon (譬如 /favicon.ico ) and a 64×64 image of type image/jpeg or image/png .

The URI may also use the data: URI scheme . (You can generate a data: URI from an icon file at data: URI kitchen )。

<Image height="16" width="16" type="image/x-icon">https://example.com/favicon.ico</Image>
  <!-- or -->
<Image height="16" width="16">data:image/x-icon;base64,AAABAAEAEBAAA … DAAA=</Image>
						

Firefox caches the icon as a base64 data: URI (search plug-ins are stored in the profile 's searchplugins/ folder). http: and https: URLs are converted to data: URIs when this is done.

注意: For icons loaded remotely (that is, from https:// URIs as opposed to data: URIs), Firefox will reject icons larger than 10 kilobytes .

Search suggestions from Google displayed in Firefox's search box

Url
Describes the URL or URLs to use for the search. The template attribute indicates the base URL for the search query.
Firefox supports three URL types:
  • type="text/html" specifies the URL for the actual search query.
  • type="application/x-suggestions+json" specifies the URL for fetching search suggestions. In Firefox 63 onwards, type="application/json" is accepted as an alias of this.
  • type="application/x-moz-keywordsearch" specifies the URL used when a keyword search is entered in the location bar. This is supported only in Firefox.

For these URL types, you can use {searchTerms} to substitute the search terms entered by the user in the search bar or location bar. Other supported dynamic search parameters are described in OpenSearch 1.1 parameters .

For search suggestions, the application/x-suggestions+json URL template is used to fetch a suggestion list in JSON format. For details on how to implement search suggestion support on a server, see Supporting search suggestions in search plugins .

Param
The parameters that must be passed in along with the search query as key/value pairs. When specifying values, you can use {searchTerms} to insert the search terms entered by the user in the search bar.
moz:SearchForm

The URL for the site's search page for which the plugin. This lets Firefox users visit the web site directly.

注意: Since this element is Firefox-specific, and not part of the OpenSearch specification, we use the moz: XML namespace prefix in the example above to ensure that other user agents that don't support this element can safely ignore it.

Autodiscovery of search plugins

Web sites with search plugins can advertise them so Firefox users can easily install the plugins.

To support autodiscovery, add a <link> element for each plugin to the <head> of your web page:

<link rel="search"
      type="application/opensearchdescription+xml"
      title="searchTitle"
      href="pluginURL">
						

Replace the bolded items as explained below:

searchTitle
The name of the search to perform, such as "Search MDC" or "Yahoo! Search". This must match your plugin file's <ShortName> .
pluginURL

The URL to the XML search plugin, so the browser can download it.

If your site offers multiple search plugins, you can support autodiscovery for them all. For example:

<link rel="search" type="application/opensearchdescription+xml"
      title="MySite: By Author" href="http://example.com/mysiteauthor.xml">
<link rel="search" type="application/opensearchdescription+xml"
      title="MySite: By Title" href="http://example.com/mysitetitle.xml">
					

This way, your site can offer plugins to search by author, or by title.

In Firefox, an icon change in the search box indicates there's a provided search plugin. (See image, the green plus sign.) Thus if a search box is not shown in the user's UI, they will receive no indication. In general, behavior varies among browsers .

How search plugin availabitity is shown in Firefox

Supporting automatic updates for OpenSearch plugins

OpenSearch plugins can automatically update. To support this, include an extra Url element with type="application/opensearchdescription+xml" and rel="self" template attribute should be the URL of the OpenSearch document to automatically update to.

例如:

<Url type="application/opensearchdescription+xml"
     rel="self"
     template="https://example.com/mysearchdescription.xml" />
					
注意: At this time, addons.mozilla.org (AMO) doesn't support automatic updating of OpenSearch plugins. If you want to put your search plugin on AMO, remove the auto-updating feature before submitting it.

Troubleshooting Tips

If there is a mistake in your Search Plugin XML, you could run into errors when adding a discovered plugin. If the error message isn't be helpful, the following tips could help you find the problem.

  • Your server should serve OpenSearch plugins using Content-Type: application/opensearchdescription+xml .
  • Be sure that your Search Plugin XML is well formed. You can check by loading the file directly into Firefox. Ampersands (&) in the template URL must be escaped as & , and tags must be closed with a trailing slash or matching end tag.
  • xmlns attribute is important — without it you could get the error message "Firefox could not download the search plugin".
  • must include a text/html URL — search plugins including only Atom or RSS URL types (which is valid, but Firefox doesn't support) will also generate the "could not download the search plugin" error.
  • Remotely fetched favicons must not be larger than 10KB (see bug 361923 ).

In addition, the search plugin service provides a logging mechanism that may be useful to plugin developers. Use about:config to set the pref ' browser.search.log ' to true . Then, logging information will appear in Firefox's Error Console (Tools 〉 Error Console) when search plugins are added.

Reference Material

元数据

  • 最后修改:
  1. Browser extensions
  2. 快速入门
    1. What are extensions?
    2. Your first extension
    3. Your second extension
    4. Anatomy of an extension
    5. Example extensions
    6. What next?
  3. 概念
    1. Using the JavaScript APIs
    2. Content scripts
    3. Match patterns
    4. Working with files
    5. 国际化
    6. Security best practices
    7. Content Security Policy
    8. Native messaging
  4. User interface
    1. 用户界面
    2. Accessibility guidelines
    3. Toolbar button
    4. Address bar button
    5. Sidebars
    6. Context menu items
    7. Options page
    8. Extension pages
    9. Notifications
    10. Address bar suggestions
    11. Developer tools panels
  5. How to
    1. Intercept HTTP requests
    2. Modify a web page
    3. Insert external content
    4. Add a button to the toolbar
    5. Implement a settings page
    6. Work with the Tabs API
    7. Work with the Bookmarks API
    8. Work with the Cookies API
    9. Work with contextual identities
    10. Build a cross-browser extension
    11. Onboard, upboard, and offboard users
  6. 移植
    1. Firefox differentiators
    2. Porting a Google Chrome extension
    3. Porting a legacy Firefox extension
    4. Comparison with the Add-on SDK
    5. Comparison with XUL/XPCOM extensions
    6. Differences between API implementations
    7. Chrome incompatibilities
    8. Differences between desktop and Android
  7. Firefox workflow
    1. 开发者工具
    2. Choose a Firefox version
    3. User Experience
    4. Prompt users for data and privacy consents
    5. Temporary Installation in Firefox
    6. 调试
    7. Testing persistent and restart features
    8. Test permission requests
    9. Developing for Firefox for Android
    10. Getting started with web-ext
    11. web-ext command reference
    12. Extensions and the Add-on ID
    13. Request the right permissions
    14. Best practices for updating your extension
  8. JavaScript APIs
    1. Browser support for JavaScript APIs
    2. alarms
    3. bookmarks
    4. browserAction
    5. browserSettings
    6. browsingData
    7. clipboard
    8. 命令
    9. contentScripts
    10. contextualIdentities
    11. Cookie
    12. devtools.inspectedWindow
    13. devtools.network
    14. devtools.panels
    15. dns
    16. downloads
    17. events
    18. extension
    19. extensionTypes
    20. find
    21. history
    22. i18n
    23. identity
    24. idle
    25. management
    26. menus
    27. notifications
    28. omnibox
    29. pageAction
    30. permissions
    31. pkcs11
    32. privacy
    33. proxy
    34. runtime
    35. search
    36. sessions
    37. sidebarAction
    38. storage
    39. tabs
    40. theme
    41. topSites
    42. 类型
    43. userScripts
    44. webNavigation
    45. webRequest
    46. windows
  9. Manifest keys
    1. 作者
    2. background
    3. browser_action
    4. browser_specific_settings
    5. chrome_settings_overrides
    6. chrome_url_overrides
    7. 命令
    8. content_scripts
    9. content_security_policy
    10. default_locale
    11. description
    12. developer
    13. devtools_page
    14. dictionaries
    15. externally_connectable
    16. homepage_url
    17. icons
    18. incognito
    19. manifest_version
    20. 名称
    21. offline_enabled
    22. omnibox
    23. optional_permissions
    24. options_page
    25. options_ui
    26. page_action
    27. permissions
    28. protocol_handlers
    29. short_name
    30. sidebar_action
    31. theme
    32. theme_experiment
    33. user_scripts
    34. version
    35. version_name
    36. web_accessible_resources
  10. Distribution Options
  11. 主题
  12. Browser themes
    1. Browser theme concepts
    2. Using the AMO theme generator
  13. Publishing and Distribution
  14. Publishing add-ons
    1. Developer accounts
    2. Signing and distribution overview
    3. Package your extension
    4. Submit an add-on
    5. Source code submission
    6. Resources for publishers
    7. Creating an appealing listing
    8. Make money from browser extensions
    9. Promoting your extension or theme
    10. Add-on policies
    11. Developer agreement
    12. Featured add-ons
    13. Retiring your extension
  15. Distributing add-ons
    1. For sideloading
    2. For desktop apps
    3. For an enterprise
  16. Community and Support
  17. Channels
    1. Add-ons blog
    2. Add-on forums
    3. 堆栈溢出
    4. Contact us