Trigger actions from the omnibox

You can allow users to interact with your extension through the Chrome omnibox (usually called the address bar). When a user enters extension-defined keywords in the omnibox, your extension controls what the user sees in the omnibox. The Omnibox New Tab Search sample extension uses "nt" as the keyword. When the user types "nt" into the omnibox, it activates the extension. To signal this to the user, it grayscales the provided 16 by 16 icon and displays it in the omnibox next to the extension name.

An example of using the ominibox to trigger an action.

The entered text causes Chrome to send an event to the omnibox.onInputEntered event handler. In the handler, the extension opens a new tab containing a Google Search for the user's entry.

chrome.omnibox.onInputEntered.addListener((text)=>{
// Encode user input for special characters , / ? : @ & = + $ #
constnewURL=`https://www.google.com/search?q=${encodeURIComponent(text)}`;
chrome.tabs.create({url:newURL});
});

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024年01月22日 UTC.