Skip to main content

Search

This namespace allows you to interact with Gmail's default search behaviour. It allows for two use cases: 1) To provide autocomplete suggestions as the user types in their query and 2) To rewrite sarch queries.

Namespace methods

registerSearchSuggestionsProvider(handler)

Registers a search autocomplete suggestion provider. This allows you to add results to Gmails autocomplete results when a user types into a search box. Each providers results are visually seperated from each other in the UI.

ParametersTypeDescription
handlerfunctionA handler that takes in a string query and returns an Array (or Promise for one) of AutocompleteSearchResults.

registerSearchQueryRewriter(rewriter)

Allows you to rewrite certain queries that may be typed in or programatically set. If a user types in a search, their search term will still be visible but the search that is actually executed by Gmails servers will be what you rewrite the query to.

ParametersTypeDescription
rewriterSearchQueryRewriterA rewriter object that specifies the term to rewrite and a function to get the new query.

--

AutocompleteSearchResult

This type is returned by the function you pass into the Search.registerSearchSuggestionsProvider() method as a way to add autocomplete suggestions to the Gmail search box.

PropertyTypeDescriptionRequired?Default
namestringThe name of the result to display. This property or nameHTML must be set.Nonull
nameHTMLstringHTML to display in the name area of the result. This property or name must be set.Nonull
descriptionstringThe name of the result to display. This property or descriptionHTML must be set.Nonull
descriptionHTMLstringHTML to display in the name area of the result. This property or description must be set.Nonull
iconUrlstringURL for the icon to show in the result. Should be a local extension file URL or a HTTPS url.Nonull
iconHTMLstringHTML to display in the icon area of the result. This property can not be used with iconUrl.Nonull
routeNamestringThe name of the route to navigate to when the autocomplete search result is selected.Nonull
routeParamsArray<string>The parameters of the route being navigated to when the autocomplete search result is selected.No[]
externalURLstringAn external URL to navigate to when the autocomplete search result is selected.Nonull
onClickfunc()A function to call when the autocomplete search result is selected.Nonull

--

SearchQueryRewriter

This type is passed into the Search.registerSearchQueryRewriter() method as a way to add rewrite search queries.

PropertyTypeDescriptionRequired?Default
termstringThe query term that you'd like to rewrite/replace. No wildcards are currently supported. Currently it must begin with "app:" or "has:".Yes
termReplacerfunctionA function which returns a String (or Promise for a string) to replace the specified term in the search query.Yes