0Pricing
Browser Extensions Development (Chrome & Edge) · Lesson

Responding to Omnibox Input

Process user input from the omnibox, provide suggestions, and execute custom logic based on the entered text.

Responding to Omnibox Input is a free Browser Extensions Development (Chrome & Edge) lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Browser Extensions Development (Chrome & Edge) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Responding to Omnibox Input

Welcome to the lesson on making your extension smart! We've learned how to set up an omnibox keyword. Now, let's make it respond to user input.

The omnibox (address bar) is a powerful place. Your extension can listen for what users type after your keyword and react in two main ways:

  • Provide suggestions: Guide the user as they type.
  • Execute actions: Perform tasks when they press Enter.

The Omnibox API

To interact with the omnibox, we use the chrome.omnibox API. This API lives in your extension's background script (service worker).

Remember to declare the "omnibox" permission in your manifest.json file for your extension to use this API.

Listening for Input Changes

As a user types after your omnibox keyword, your extension can provide dynamic suggestions. This is handled by the chrome.omnibox.onInputChanged event.

  • It fires every time the user's input changes.
  • You receive the current text the user has typed.
  • You get a suggest callback function to send suggestions back to the omnibox.

Structuring Your Suggestions

The suggest callback expects an array of suggestion objects. Each object needs an "content" field, which is the actual text that will be inserted if the user selects the suggestion.

You can also add a "description" field for richer suggestions:

  • content: The text to use if the suggestion is selected.
  • description: (Optional) Rich HTML text displayed next to the suggestion.

Code: Dynamic Suggestions

Let's create a background script that suggests a prefix based on the user's input. Make sure your manifest.json has "omnibox": { "keyword": "go" } and the "omnibox" permission.

chrome.omnibox.onInputChanged.addListener(
  (text, suggest) => {
    const suggestions = [
      { content: text + " search", description: "Search for: " + text },
      { content: text + " docs", description: "Docs for: " + text }
    ];
    suggest(suggestions);
  }
);

Executing Actions on Enter

Once the user types their input and presses the Enter key, the chrome.omnibox.onInputEntered event is triggered. This is where you perform the main action of your extension.

  • It provides the final text entered by the user.
  • It also gives a disposition, indicating how the user wants the action to be handled (e.g., new tab, current tab).

Code: Opening a New Tab

Here's how to open a new tab with a search query based on the user's input. This code would typically be in the same background script as onInputChanged.

chrome.omnibox.onInputEntered.addListener(
  (text, disposition) => {
    const searchUrl = `https://www.google.com/search?q=${encodeURIComponent(text)}`;

    if (disposition === 'newForegroundTab') {
      chrome.tabs.create({ url: searchUrl });
    } else if (disposition === 'newBackgroundTab') {
      chrome.tabs.create({ url: searchUrl, active: false });
    } else {
      // currentTab
      chrome.tabs.update({ url: searchUrl });
    }
  }
);

Setting a Default Suggestion

You can provide a default suggestion that appears even before the user types anything. This is useful for guiding users or showing a common action.

Use chrome.omnibox.setDefaultSuggestion() with a description to set this initial hint.

chrome.omnibox.setDefaultSuggestion({
  description: 'Type a query to search Google'
});

Rich Suggestions with Descriptions

For even more helpful suggestions, you can use HTML within the description field. This allows you to highlight parts of the text, use different colors, or make it more readable.

  • Use <match> tags to highlight matching text.
  • Use <dim> tags for less important text.
  • Remember to escape special characters like < and > if they are part of your literal text.

Quick Check: Omnibox Events

Consider an extension that uses the omnibox keyword 'wiki'. Which event listener is primarily responsible for updating suggestions as the user types 'wiki cats'?

Recap: Responding to Omnibox Input

You've learned how to make your extension truly interactive with the omnibox!

  • We use chrome.omnibox.onInputChanged to provide dynamic suggestions as the user types.
  • Suggestions are an array of objects with content and optional description fields.
  • chrome.omnibox.onInputEntered allows your extension to execute a specific action when the user presses Enter.
  • You can also set a setDefaultSuggestion for initial guidance.

This powerful API lets users interact with your extension directly from the browser's address bar, making common tasks quicker and more efficient.

Frequently asked questions

Is the “Responding to Omnibox Input” lesson free?

Yes — the full text of “Responding to Omnibox Input” is free to read here on the web, and the Browser Extensions Development (Chrome & Edge) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Browser Extensions Development (Chrome & Edge) course, upgrade to CoddyKit PRO.

What will I learn in “Responding to Omnibox Input”?

Process user input from the omnibox, provide suggestions, and execute custom logic based on the entered text. You practise Browser Extensions Development (Chrome & Edge) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Browser Extensions Development (Chrome & Edge)?

No prior experience is required. Browser Extensions Development (Chrome & Edge) on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Responding to Omnibox Input” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Browser Extensions Development (Chrome & Edge) lesson?

Yes. Every Browser Extensions Development (Chrome & Edge) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Adding Context Menu Items
  2. Omnibox Keyword Integration
  3. Responding to Omnibox Input
  4. Keyboard Shortcuts with the Commands API
← Back to Browser Extensions Development (Chrome & Edge)