the color of the window buttons doesn't matter, macOS has two different concepts (keyboard focus and windows focus - BTT only cares about keyboard focus for the floating menus).
The problem without the javascript is: webviews support auto focus on load, but after a website is loaded and in memory, auto focus can not trigger again automatically without reloading the site. That's actually a security feature of modern browsers, so websites can not activate a textfield without your knowledge to steal your keyboard input.
Besides the JavaScript, it's important to make the menu have keyboard focus:
Finding the id of the element to use in the focus javascript is usually not complicated. Just right-click the text field and choose "inspect element", then right-click the highlighted HTML and choose "copy selector path".
The selector path can then be used like this:
document.querySelector("HERE GOES THE COPIED SELECTOR PATH").focus()
For Google it's
document.querySelector("#APjFqb").focus()
But this might depend on the country.