Devin Gibson
Devin Gibson

Reputation: 121

Browser Extension - How do I stop autofocus from going to the address bar?

I have a browser extension which replaces the new tab page with a page that has a nice background and a search bar. Using the search bar takes the user to google and searches for the query (in the same tab). For some reason, when using the extension version, the autofocus doesn't go into my search form and instead goes into the address bar. I can't for the life of me figure out why. Did I muck this up someplace? This is my search form:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
<link rel="stylesheet" type="text/css" href="popup.css" />
</head>

<body>

<div id="searchContainer">
<form action="http://google.ca/search" method="GET" >
<input id="field" type="search" name="q" size="20" placeholder="Google Search" autofocus />&nbsp;
<input id="submit" name="submit" type="submit" value="Search" />
</form>
</div>

</body>

</html>
  

Thank you!

Upvotes: 4

Views: 2603

Answers (1)

woxxom
woxxom

Reputation: 73866

This is hard-coded in Chrome to match behavior of the built-in newtab.

It can't be changed but an official workaround is to redirect via location to another URL. The address bar will show a full chrome-extension:// URL though.

manifest.json:

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

focus.html:

<script src=focus.js></script>

focus.js:

location = 'start-focused.html';

start-focused.html will have the actual contents of your newtab UI.

Upvotes: 6

Related Questions