So I'm trying to build a simple Omnibox extension for Chrome for personal use. It works like any other Omnibox extension: you enter the extension keyword and press tab, which gives the extension control of the omnibox. Then you type in a phrase or whatnot and a list of suggestions pop up below the omnibox. Then you can use the arrow keys or mouse to select a suggestion and then the browser navigates to the page associated with that suggestion. All of that works perfectly fine.
However, what I'd like it to do is that when I press enter in without having selected a suggestion, I'd like the browser to go to the first suggestion from the suggestion list. Instead what happens right now, I get this error page:
I couldn't find any answers in the documentation on this. This is what my code looks like right now (in background.js
):
chrome.omnibox.onInputChanged.addListener(
function(text, suggest)
{
text = text.replace(" ", "");
suggest([
{ content: "http://reddit.com/r/" + text, description: "reddit.com/r/" + text },
{ content: "http://imgur.com/r/" + text, description: "imgur.com/r/" + text }
]);
}
);
chrome.omnibox.onInputEntered.addListener(
function(text)
{
chrome.tabs.getSelected(null, function(tab)
{
chrome.tabs.update(tab.id, {url: text});
});
}
);
chrome.omnibox.setDefaultSuggestion({ description: "visit /r/%s" });
So is there a way of setting the default action when the enter is pressed without a suggestion being selected? Sort of like the custom search functionality works by default in the Chrome omnibox?