0

I want to build a chrome extension that automatically types into a focused text box (i.e. where the cursor is placed) on a web page. It should use the keyboard automatically and should not try changing the HTML of the web page using dom.

I tried using the library robotjs, but it doesn't work on the browser. I also tried using it with the help of browserify but it doesn't seem to work that way as well.

Here is the code I tried using robotjs.

copy.js:

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}


var robot = require("robotjs");
async function paste(text){
    await sleep(5000);
    robot.typeString(text);
    robot.keyTap("enter");
}

Html snippet:

    <script src = "copy.js"></script>
    <input type="text" id="text-box">
    <input type="button" id="submit-button" value="Paste" onClick="paste(document.getElementById('text-box').value)">

0 Answers0