1

I am creating a chrome extension that sets the new tab page to my website (which is a replacement new tab page).

Once the redirect has occurred, I'd like the cursor to automatically be focused on the omnibox or address bar, so that the user can immediately start writing a URL or search query.

I'm sure this is possible because I have had chrome extensions in the past that allow this.

Anyone have any ideas how to go about it?

Mark
  • 2,041
  • 2
  • 18
  • 35
Splycd
  • 161
  • 2
  • 3
  • 15
  • The cursor should be automatically focus on address bar, it's default behavior. So what do you want to do? – Haibara Ai Mar 10 '16 at 07:31
  • @HaibaraAi Because my extension redirects the user to a website, the address bar has that web address in it and is not focused. – Splycd Mar 10 '16 at 07:33
  • Possible duplicate of [Highlight URL bar using Chrome and Safari extension](http://stackoverflow.com/questions/10492399/highlight-url-bar-using-chrome-and-safari-extension) – Haibara Ai Mar 10 '16 at 07:46

1 Answers1

2

You're probably doing the new tab page replacement in a crude way - by intercepting a tab opening and redirecting it. In this scenario, as Haibara Ai mentions in a comment, it's not possible to focus on the omnibar.

Instead, you should create an override page in the manifest:

  "chrome_url_overrides" : {
    "newtab": "newtab.html"
  },

This should be a local page, but you can embed your remote content using an iframe.

What's important is that override page will function the same as the normal one - the URL bar will be clear and the focus will be there by default.


Finally, think of the user experience when making a new tab reliant on remote content. You want the page to stay functional in case of a bad connection or offline browsing. Think of using offline techniques to remedy this, or having a local webapp that just pulls information off your site but renders independently.

Xan
  • 74,770
  • 16
  • 179
  • 206