0Pricing
Browser Extensions Development (Chrome & Edge) · Leçon

Intégrer des mots-clés à l’omnibox

Intégrez votre extension à l’omnibox du navigateur pour permettre aux utilisateurs de déclencher des actions ou des recherches directement depuis la barre d’adresse.

Intégrer des mots-clés à l’omnibox est une leçon Browser Extensions Development (Chrome & Edge) gratuite sur CoddyKit. Ceci est la leçon 2 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Browser Extensions Development (Chrome & Edge), et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Browser Extensions Development (Chrome & Edge) comprend 4 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

What is the Omnibox?

The omnibox is the URL bar at the top of your browser. It's not just for typing website addresses; it also handles searches and can be a powerful entry point for browser extensions!

Integrating with the omnibox allows users to quickly interact with your extension directly from the address bar, without needing to click an icon or open a popup.

Power Up Your Address Bar

Why integrate your extension with the omnibox?

  • Quick Access: Users can trigger extension actions with just a few keystrokes.
  • Custom Searches: Create shortcuts for specific searches within your extension's data.
  • Streamlined Workflow: Perform tasks without interrupting their browsing flow.

Setting Your Omnibox Keyword

To enable omnibox integration, you need to declare it in your extension's manifest.json file.

You'll specify a unique keyword. When a user types this keyword into the omnibox, followed by a space, your extension takes over the input.

Manifest Keyword Example

Here's how to declare an omnibox keyword, for example, 'myext':

{  "manifest_version": 3,
  "name": "My Omnibox Extension",
  "version": "1.0",
  "omnibox": {
    "keyword": "myext"
  },
  "background": {
    "service_worker": "background.js"
  }
}

Capturing User Input

Once your keyword is set, your background service worker needs to listen for user input. The main event for this is chrome.omnibox.onInputChanged.

This event fires every time the user types a character after your keyword, allowing you to provide real-time suggestions.

Displaying Live Suggestions

The onInputChanged listener provides a suggest callback function. You use this to send an array of suggestion objects back to the omnibox.

Each suggestion object needs a content (what gets inserted if selected) and a description (what the user sees in the dropdown).

Dynamic Suggestions in Action

This background.js snippet shows how to listen for input and offer basic suggestions. Try typing 'myext hello' in your browser's omnibox after loading this extension.

// background.js
chrome.omnibox.onInputChanged.addListener(
  function(text, suggest) {
    let suggestions = [];
    if (text.startsWith("hello")) {
      suggestions.push({content: "hello world", description: "Says Hello World"});
      suggestions.push({content: "hello there", description: "Greets you"});
    } else {
      suggestions.push({content: "type 'hello'", description: "Try typing 'hello'"});
    }
    suggest(suggestions);
  }
);

Acting on User Selection

After the user types their input and optionally selects a suggestion, they press Enter. This triggers the chrome.omnibox.onInputEntered event.

This is where your extension performs the final action based on the user's input, like opening a new tab or executing a script.

Executing Actions

Inside onInputEntered, the text parameter contains the final string the user entered or selected.

A common action is to open a new tab with a specific URL using chrome.tabs.create({url: '...' }), or perform a search based on the input.

Full Omnibox Integration

Here's a more complete example combining both input handling and action execution. This example allows users to search Google directly from the omnibox using 'myext go [query]'.

// background.js
chrome.omnibox.onInputChanged.addListener(
  function(text, suggest) {
    let suggestions = [];
    if (text.startsWith("go ")) {
      const query = text.substring(3);
      suggestions.push({
        content: `https://www.google.com/search?q=${query}`,
        description: `Search Google for "${query}"`
      });
    } else {
      suggestions.push({
        content: "go [search_term]",
        description: "Type 'go' to search Google"
      });
    }
    suggest(suggestions);
  }
);

chrome.omnibox.onInputEntered.addListener(
  function(text, disposition) {
    if (text.startsWith("http://") || text.startsWith("https://")) {
      chrome.tabs.create({url: text});
    } else if (text.startsWith("go ")) {
      const query = text.substring(3);
      chrome.tabs.create({url: `https://www.google.com/search?q=${query}`});
    } else {
      console.log("Omnibox entered:", text);
      chrome.tabs.create({url: `https://www.google.com/search?q=${text}`});
    }
  }
);

Omnibox Quick Check

You've learned how to integrate your extension with the browser's omnibox. Let's test your knowledge!

Omnibox Power-Up Recap

Great job! You've learned how to integrate your extension with the browser's omnibox.

  • We defined a keyword in manifest.json.
  • We used chrome.omnibox.onInputChanged to provide dynamic suggestions as the user types.
  • We handled the final action using chrome.omnibox.onInputEntered, for example, opening a new tab.

This powerful feature allows users to interact with your extension quickly and efficiently right from their address bar!

Questions Fréquemment Posées

La leçon « Intégrer des mots-clés à l’omnibox » est-elle gratuite ?

Oui — le texte complet de « Intégrer des mots-clés à l’omnibox » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Browser Extensions Development (Chrome & Edge), passe à CoddyKit PRO. Le cours Browser Extensions Development (Chrome & Edge) comprend 4 leçons au total.

Qu'est-ce que j'apprendrai dans « Intégrer des mots-clés à l’omnibox » ?

Intégrez votre extension à l’omnibox du navigateur pour permettre aux utilisateurs de déclencher des actions ou des recherches directement depuis la barre d’adresse. Tu pratiques Browser Extensions Development (Chrome & Edge) avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer Browser Extensions Development (Chrome & Edge) ?

Aucune expérience préalable n'est requise. Browser Extensions Development (Chrome & Edge) sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 2 sur 4.

Combien de temps prend la leçon « Intégrer des mots-clés à l’omnibox » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon Browser Extensions Development (Chrome & Edge) ?

Oui. Chaque leçon Browser Extensions Development (Chrome & Edge) inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. Ajouter des éléments au menu contextuel
  2. Intégrer des mots-clés à l’omnibox
  3. Répondre aux saisies dans l’omnibox
  4. Raccourcis clavier avec l’API Commands
← Retour à Browser Extensions Development (Chrome & Edge)