3

I learnt how to invoke my extension's background js by typing a specific keyword in the omnibox. But I need to enable my extension to listen to the text typed in the omnibox without the help of any keyword.

Example: If user types, abc or abcd or abcd.com, my extension should get triggered. Here I cant rely on any keyword, cause user would directly type the target site name.

When I tried using the keyword as the possible target name (say abcd.com) the triggering doesnt work since the moment user types abc, chrome autosuggests abcd.com and user selects it directly and keyword triggering doesnt work.

I googled but all the tutorials I found were around using keywords. I want something like an eventlistener which would listen to every tab's omnibox all the time.

Any tutorials, or sources would be great help to me.

Ivin
  • 4,435
  • 8
  • 46
  • 65

1 Answers1

4

This is impossible. The API does not allow you to "spy" on the Omnibox.

That's the point of the keyword - only after you've typed it the extension is informed.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • Thank you. Is there any other way for the extension to know which URL is being opened in the browser (on any existing tab or a new tab). Basically, what I want is, to know if a particular website or URL containing that website is being opened and act on it. – Ivin Dec 24 '14 at 13:28
  • 2
    Look at [`webNavigation`](https://developer.chrome.com/extensions/webNavigation) and [`webRequest`](https://developer.chrome.com/extensions/webRequest) APIs. Or even just plain old [`tabs` API events](https://developer.chrome.com/extensions/tabs#events). But `webNavigation` is probably your best bet. – Xan Dec 24 '14 at 13:31
  • It's not spying if the user hits enter after they've entered their text because you can see it through chrome.tabs.onUpdated too anyway. But I needed to get this from the omnibox in order to be able to recognize when a url is entered manually and when it's opened through other means such as links on webpages. **Edit:** I used `document.referrer` as a workaround and it worked for my usecase. – aderchox Jul 16 '22 at 11:09