Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi guys,

I have created one google chrome extension to get key pressed values from active tab.

HTML
<!DOCTYPE html>

<html>
    <head>
        <script src="popup.js"></script>
    </head>
        <body>
            <h3><center>Key Logger</center></h3>
            <hr>
            <label>Unable/Disable</label><input type="checkbox" name="chk" id="chk">
            <br />
            <textarea name="sdata" id="sdata" cols="30" rows="10"></textarea>       
        </body>
</html>


JavaScript
var x;var y="";var d = new Date();
myFunction();
function myFunction(event) {
    x = event.which || event.keyCode;
    //alert(x);
    y += x == 13 ? "<br />" : String.fromCharCode(x);
    document.getElementById("sdata").innerHTML = d + "<br />" + y;
}


What I have tried:

Manifest.json
{
    "name":"Key Logger",
    "description":"It will store all the keys used during browsing.",
    "version":"1.0.0",
    "manifest_version": 2,
    "browser_action":{
        "default_icon":"icon.png",
        "default_popup":"popup.html"
    },
    "content_scripts": [
        {
          "matches": ["*://*/*"],
          "js": ["popup.js"]
        }
      ],
    "permissions":[
        "tabs",
        "storage",
        "activeTab"
    ]
}


Can anyone please help me. How to get the key pressed value from active tab.

Thanks in advance.
Posted
Updated 18-Feb-22 13:28pm

As far as I know, you can't do that for security reasons: that would trap passwords, bank account details and so forth and would probably count as malicious code.
 
Share this answer
 
Comments
abdul subhan mohammed 24-May-18 6:14am    
How can i change the font-size/color and background of the active tab?
OriginalGriff 24-May-18 6:34am    
You don't - those are controlled by the webpage, not the browser. Changing them will result in websites becoming harder or even impossible to use.
document.addEventListener('keypress', (key)=>{console.log(key)});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900