Get OmniBox value with a BrowserAction on Chrome

263 views Asked by At

I need to write down an extension to do the following:

  1. Whenever i use a keyword, it searches on my personal database (working)
  2. If i type something in the OmniBox and press my button created from a BrowserAction, i want to go to the same place.

My problem so far is to get the content of the omni box into a variable so i can attach to the end of my url and perform the search.

Anybody can help? Here is what i made so far:

manifest.json

"name": "My Search",
"version": "1.0",
"description": "My Search",
"manifest_version": 2,
"omnibox": { 
    "keyword": "MyKeyword" 
},
"browser_action": {
    "default_icon": "icon.png"
},
"background": {
    "scripts": ["background.js"]
},
"permissions": [
    "tabs"
]

background.js

chrome.omnibox.onInputEntered.addListener(function(text) {
    chrome.tabs.create({'url': "http://mywebsite/search/" + text});
});
chrome.browserAction.onClicked.addListener(function(tab) {
    var action_url = "http://mywebsite/search/";
    var omni = "";
    chrome.tabs.update(tab.id, {url: action_url + omni});
});
chrome.browserAction.setBadgeText({text: "MyBadge"})

So, i just need to sabe the current value of the omni bar into the variable "omni". But how?

I appreciate any help.

0

There are 0 answers