A K
A K

Reputation: 97

Google Chrome Extension: Omnibox Keyword How To?

My Chrome 'search extension' has a keyword and I want to take the user's input to trigger a search query. In my extension's manifest file I have declared:

"omnibox": { "keyword" : "i" },

When I type 'i' into the Omnibox and hit TAB/SPACE, I see my extension take effect... however, when I then type a search query and press ENTER (or select the suggested command), nothing happens.

Here is the sample I am using, found at Google Code > Omnibox:

// This event is fired each time the user updates the text in the omnibox,
// as long as the extension's keyword mode is still active.

chrome.omnibox.onInputEntered.addListener(function(text) {
  var serviceCall2 = 'http://www.google.com/search?q=' + text;
});

// This event is fired with the user accepts the input in the omnibox.

chrome.omnibox.onInputEntered.addListener(function(text) {  
  chrome.windows.create({"url": serviceCall2});
});

Is there any other code that I'm missing or is my above code wrong?

Upvotes: 0

Views: 2508

Answers (1)

Xan
Xan

Reputation: 77601

  1. Your two events are identical. I assume it's a copy-paste error.

    The correct event to fire each time the text changes is chrome.omnibox.onInputChanged

  2. Your code cannot work anyway, since serviceCall2 is local to the first message listener. It is undefined in the second.

  3. You don't need two listeners to begin with, this should work:

    chrome.omnibox.onInputEntered.addListener(function(text) { 
      var serviceCall2 = 'http://www.google.com/search?q=' + text;
      chrome.windows.create({"url": serviceCall2});
    });
    

Upvotes: 4

Related Questions