Chrome 键盘记录器(用于教育目的)
我正在尝试开发一个用于教育目的的 Chrome 键盘记录器。我面临的问题是我不确定如何从不同的选项卡捕获按键。我已经为带有图标的键盘记录器创建了扩展。当按下图标时;后台页面应该运行并在按下按键字符串时发出警报。
后台页面的代码为:
<script>
chrome.browserAction.onClicked.addListener(currWin);
document.onmousedown = currWin;
function getCurrWin()
{
chrome.tabs.getCurrent(currWin);
}
function currWin(tab)
{
chrome.tabs.getSelected(null,function(tab){
alert(tab.title + " : " + tab.id);
document.onkeypress = keylogger;
})
}
function keylogger(e)
{ if(e.keyCode==27)
{
alert('A');
}
else{
logged_keys+=String.fromCharCode(e.charCode);
alert(logged_keys);
}}
</script>
I am trying to develop a Chrome keylogger for educational purposes. The problem I am facing is that I am not sure how to capture the keys from different tabs. I have created a extension for the keylogger with a icon. When the icon is pressed; the background page is supposed to run and just alert the key string as they are pressed.
The code of the background page is:
<script>
chrome.browserAction.onClicked.addListener(currWin);
document.onmousedown = currWin;
function getCurrWin()
{
chrome.tabs.getCurrent(currWin);
}
function currWin(tab)
{
chrome.tabs.getSelected(null,function(tab){
alert(tab.title + " : " + tab.id);
document.onkeypress = keylogger;
})
}
function keylogger(e)
{ if(e.keyCode==27)
{
alert('A');
}
else{
logged_keys+=String.fromCharCode(e.charCode);
alert(logged_keys);
}}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
currWin(tab)
中,document
指的是背景页面,而不是您选择的选项卡。因此,你并没有真正关注正确的事件。您必须使用内容脚本才能访问选项卡中的事件。
In your
currWin(tab)
,document
refers to the background page, and not the tab you selected. Therefore, you don't really attach to the right event.You will have to use Content Scripts to get to the events in a tab.