focus on input Google search

I would like to develop a firefox extension that allows me to focus on the google search. https://www.google.fr

I tired to make document.getElementById("lst-ib").focus();, If I analyze the DOM with DOM inspector the input field have the id lst-ib, but the focus does not switch but if I made a document.getElementById("lst-ib").value = "test"; the word test appears good in the input field. I feel that all the javascript functions work except the focus().

Is it therefore possible to focus on this field or google blocks this action maybe ?

EDIT

Js Google function event on focus :

function(a, f) {
  if (d.length) {
     var g;
     if (!(g = a)) {
         g = {};
         var k = c.event;
         k && (k.keyCode && (g.keyCode = k.keyCode), g.i1 = !0)
     }
     g.dg = f || b;
     for (var k = g, l, m, n = 0, ba; ba = d[n++];) ba.sD ? m = !0 : l 
          || (ba.j1 ? QS_pWa(this, ba, k) : l = ba.Cg(k));
     if (m)
       for (n = 0; ba = d[n];) ba.sD ? d.splice(n, 1) : ++n;
     if (g.Uh) return delete g.Uh, g.i1 && (g = c.event || g), QS_Et(g), g.returnValue = !1
   }
}

But this is incomprehensible...

Answers 1

  • I think focus() is right and google isn't blocking that method, but because the focus is on Inspector, it does not seems focus on search input element. Type this and click google page's margin:

    setTimeout(() => document.getElementById("lst-ib").focus(), 2000)


Related Articles