Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding search.query and search.search disposition (#24668)
* Adding search.query and search.search disposition * Default behavior correction * Review feedback Co-authored-by: Gregory Pappas <email.greg.email@gmail.com> * Removed bug macros * Advice on use of query versus search * Incorporate suggested change Co-authored-by: Rob Wu <rob@robwu.nl> --------- Co-authored-by: Gregory Pappas <email.greg.email@gmail.com> Co-authored-by: Rob Wu <rob@robwu.nl>
- Loading branch information
1 parent
e6c5ee0
commit ad20678
Showing
4 changed files
with
124 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
files/en-us/mozilla/add-ons/webextensions/api/search/query/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
title: search.query() | ||
slug: Mozilla/Add-ons/WebExtensions/API/search/query | ||
tags: | ||
- API | ||
- Add-ons | ||
- Extensions | ||
- Reference | ||
- Search | ||
- Search Engines | ||
- WebExtensions | ||
browser-compat: webextensions.api.search.query | ||
--- | ||
|
||
{{AddonSidebar()}} | ||
|
||
Perform a search using the browser's default search engine. | ||
|
||
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](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions). | ||
|
||
To get the installed search engines, use {{WebExtAPIRef("search.get()")}}. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
browser.search.query( | ||
queryInfo // object | ||
) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `queryInfo` | ||
|
||
- : `object`. An object with the following properties: | ||
|
||
- `disposition` {{optional_inline}} | ||
- : `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`. | ||
- `tabId` {{optional_inline}} | ||
- : `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`. | ||
- `text` | ||
- : `string`. The search query. | ||
|
||
### Return value | ||
|
||
None. | ||
|
||
## Examples | ||
|
||
A search with the results shown in the current tab (default): | ||
|
||
```js | ||
function search() { | ||
browser.search.query({ | ||
text: "styracosaurus" | ||
}); | ||
} | ||
|
||
browser.browserAction.onClicked.addListener(search); | ||
``` | ||
|
||
A search with the results shown in a new window: | ||
|
||
```js | ||
function search() { | ||
browser.search.query({ | ||
text: "styracosaurus", | ||
disposition: "NEW_WINDOW" | ||
}); | ||
} | ||
|
||
browser.browserAction.onClicked.addListener(search); | ||
``` | ||
|
||
A search with the results shown in the current tab: | ||
|
||
```js | ||
function search(tab) { | ||
browser.search.query({ | ||
query: "styracosaurus", | ||
tabId: tab.id | ||
}); | ||
} | ||
|
||
browser.browserAction.onClicked.addListener(search); | ||
``` | ||
|
||
{{WebExtExamples}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters