search.search()

Perform a search using the search engine specified or the default search engine if no search engine is specified.

The results are displayed in the current tab, a new tab, or a new window according to the disposition property or in the tab specified in the tabId property. If neither is specified, the results display in a new tab.

To use this function, your extension must have the "search" manifest permission.

To get the installed search engines, use search.get().

Syntax

js
browser.search.search(
  searchProperties       // object
)

Parameters

searchProperties

object. An object with the following properties:

disposition Optional

string. The location where the search results are displayed. Valid values are CURRENT_TAB, NEW_TAB, and NEW_WINDOW. Defaults to NEW_TAB. Cannot be specified with tabId.

engine Optional

string. The name of the search engine. If the search engine name doesn't exist, the function rejects the call with an error. If this property is omitted, the default search engine is used.

query

string. The search query.

tabId Optional

integer. An optional identifier for the tab you want to execute the search in. If this property is omitted, the search results are displayed in a new tab. Cannot be specified with disposition.

Return value

None.

Examples

A search using the default search engine with the results shown in the current tab (default):

js
function search() {
  browser.search.search({
    query: "styracosaurus",
  });
}

browser.browserAction.onClicked.addListener(search);

A search using Wikipedia with the results shown in a new window:

js
async function search() {
  try {
    // try to search using the `Wikipedia (en)` search engine
    await browser.search.search({
      query: "styracosaurus",
      engine: "Wikipedia (en)",
      disposition: "NEW_WINDOW",
    });
  } catch (ex) {
    // if the search fails, e.g., because the search engine isn't defined to the browser, initiate the search using a url
    await browser.windows.create({
      url: "https://en.wikipedia.org/w/index.php?title=Special:Search&search=styracosaurus",
    });
  }
}

browser.browserAction.onClicked.addListener(search);

A search using Wikipedia with the results shown in the current tab:

js
async function search(tab) {
  try {
    // try to search using the `Wikipedia (en)` search engine
    await browser.search.search({
      query: "styracosaurus",
      engine: "Wikipedia (en)",
      tabId: tab.id,
    });
  } catch (ex) {
    // if the search fails, e.g., because the search engine isn't defined to the browser, initiate the search using a url
    await browser.tabs.update(tab.id, {
      url: "https://en.wikipedia.org/w/index.php?title=Special:Search&search=styracosaurus",
    });
  }
}

browser.browserAction.onClicked.addListener(search);

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
search
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
searchProperties
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
searchProperties.disposition
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 111 (Release date: 2023-03-14)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
searchProperties.engine
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
searchProperties.query
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
searchProperties.tabId
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support