Chrome new autofocus tab

I am making a chrome extension and I am using the following

manifest.json

{
        "name": "Test extension",
        "version": "1.1",
        "description": "Test extension.",
        "icons": {
            "128": "icon_128.png"
        },
        "chrome_url_overrides": {
            "newtab": "cc.html"
        },
        "manifest_version": 2
    }

cc.html

    <style>body,html{padding:0;margin:0}</style>
    <iframe src="theiframe.html" frameborder="0" height="200px" width="200px">
    </iframe>

theiframe.html

<style>body,html{padding:0;margin:0}</style>
<form action="http://www.example.com/search">
    <input autofocus="autofocus" tabindex="1" type="text" />
    <input tabindex="2" value="search" type="submit"/>
</form>

When the user opens a new tab, autofocus will be in the address bar. I want users to be able to change this. Is there a code that automatically autofocuses the input for searching?

+5
source share
3 answers

Perhaps he cannot work using only iframe. But you can create a sample page that will be redirected to the desired page when a new tab opens, so inputc autofocuswill be automatically focused.

Here's how to do it:


manifest.json

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


r.html

<html>
  <head>
    <title>Loading...</title> <!-- user friendly -->
    <noscript>
      <meta http-equiv="refresh" content="0; url=https://www.google.com"> <!-- in case javascript is disabled -->
    </noscript>
    <script src="s.js"></script>
  </head>
  <body></body>
</html>


s.js

window.location="https://www.google.com";


(, , ).

+6

API docs:

. , .

+2

As Eric Kay (director of Chrome engineering) said in this Chromium bug report , the expected behavior for Omnibox has a default focus, and this cannot be changed.

Thus, the error was marked as WontFix.

+2
source

All Articles