Movatterモバイル変換


[0]ホーム

URL:


  1. Mozilla
  2. Add-ons
  3. Browser extensions
  4. JavaScript APIs
  5. omnibox
  6. omnibox.onInputEntered

omnibox.onInputEntered

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
  • anomnibox.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

js
browser.omnibox.onInputEntered.addListener(listener)browser.omnibox.onInputEntered.removeListener(listener)browser.omnibox.onInputEntered.hasListener(listener)

Events have three functions:

addListener(listener)

Adds a listener to this event.

removeListener(listener)

Stop listening to this event. Thelistener argument is the listener to remove.

hasListener(listener)

Check whetherlistener is registered for this event. Returnstrue if it is listening,false otherwise.

addListener syntax

The listener function will be passed two parameters: a stringtext, and anomnibox.OnInputEnteredDisposition.

Parameters

text

String. This is the value of thecontent property of theomnibox.SuggestResult object that the user selected.

disposition

OnInputEnteredDisposition. Anomnibox.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.

Examples

This example interprets the user's input as a CSS property name and populates the drop-down list with oneomnibox.SuggestResult object for each CSS property matching the input. Thedescription property ofSuggestResult is the full name of the property, and thecontent is the MDN page for that property.

The example also listens toomnibox.onInputEntered, and opens the MDN page corresponding to the selection, according to theomnibox.OnInputEnteredDisposition argument.

js
browser.omnibox.setDefaultSuggestion({  description: "Type the name of a CSS property",});/*Very short list of a few CSS properties.*/const props = [  "animation",  "background",  "border",  "box-shadow",  "color",  "display",  "flex",  "flex",  "float",  "font",  "grid",  "margin",  "opacity",  "overflow",  "padding",  "position",  "transform",  "transition",];const baseURL = "https://developer.mozilla.org/en-US/docs/Web/CSS/";/*Return an array of SuggestResult objects,one for each CSS property that matches the user's input.*/function getMatchingProperties(input) {  const result = [];  for (const prop of props) {    if (prop.startsWith(input)) {      console.log(prop);      const suggestion = {        content: `${baseURL}${prop}`,        description: prop,      };      result.push(suggestion);    } else if (result.length !== 0) {      return result;    }  }  return result;}browser.omnibox.onInputChanged.addListener((input, suggest) => {  suggest(getMatchingProperties(input));});browser.omnibox.onInputEntered.addListener((url, disposition) => {  switch (disposition) {    case "currentTab":      browser.tabs.update({ url });      break;    case "newForegroundTab":      browser.tabs.create({ url });      break;    case "newBackgroundTab":      browser.tabs.create({ url, active: false });      break;  }});

Example extensions

Browser compatibility

Note:This API is based on Chromium'schrome.omnibox API.

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp