Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/omnibox/oninputentered/index.md
6581 views
------{{AddonSidebar()}}
Fired when the user has selected one of the suggestions your extension has added to the address bar's drop-down list.
Use this event to handle the user's selection, generally by opening the corresponding page. The event listener is passed:
the user's selection
a {{WebExtAPIRef("omnibox.OnInputEnteredDisposition")}}: use this to determine whether to open the new page in the current tab, in a new foreground tab, or in a new background tab.
Syntax
Events have three functions:
addListener(listener): Adds a listener to this event.
removeListener(listener): Stop listening to this event. The
listenerargument is the listener to remove.
hasListener(listener): Check whether
listeneris registered for this event. Returnstrueif it is listening,falseotherwise.
addListener syntax
The listener function will be passed two parameters: a string text, and an {{WebExtAPIRef("omnibox.OnInputEnteredDisposition")}}.
Parameters
text:
String. This is the value of thecontentproperty of the {{WebExtAPIRef("omnibox.SuggestResult")}} object that the user selected.
disposition: {{WebExtAPIRef("omnibox.OnInputEnteredDisposition", "OnInputEnteredDisposition")}}. A {{WebExtAPIRef("omnibox.OnInputEnteredDisposition")}} enumeration, indicating whether the extension should open the page in the current tab, in a new foreground tab, or in a new background tab.
Browser compatibility
{{Compat}}
Examples
This example interprets the user's input as a CSS property name and populates the drop-down list with one {{WebExtAPIRef("omnibox.SuggestResult")}} object for each CSS property matching the input. The description property of SuggestResult is the full name of the property, and the content is the MDN page for that property.
The example also listens to {{WebExtAPIRef("omnibox.onInputEntered")}}, and opens the MDN page corresponding to the selection, according to the {{WebExtAPIRef("omnibox.OnInputEnteredDisposition")}} argument.
{{WebExtExamples}}
Note: This API is based on Chromium's
chrome.omniboxAPI.