I have one HTML page with input box and button. I want to have a chrome extension that can focus on the input element.
HTML page -
<html>
    <body>
        <input type="text" name="box" />
        <button type="button" onclick="clicked()">Click</button>
        <script>
            //document.getElementsByName("box")[0].focus(); <--- this works. But I don't want this.
        </script>
    </body>
</html>
My injected script -
chrome.runtime.onMessage.addListener(function(message, sender, response){
    if(message.action==="start"){
            document.getElementsByName("box")[0].focus(); //<---want this to work. Currently unable to :(
            console.log("started");
    }
});
I get the started log but my element is not focused.
Rest files (i.e. popup.html and popup.js) not shown because they are working fine and irrelevant to this.
I tried simulating mouse click event on the input element (from here) but that method also failed.
Any help regarding this is appreciated. Open to jquery based solutions.
Thanks.
 
    