如何在 Chrome 的所有网站上捕获鼠标和键盘数据

How to capture Mouse and Keyboard data across all websites for Chrome

正如标题所暗示的那样。我将如何跨网站捕获一般事件数据?这应该是一个严格的 client-side 应用程序。 chrome 扩展是否有效?如果是这样,我将如何去做?是否已经存在,或者至少有一种替代方法?

在 chrome 扩展中,Content scripts are scripts that run in the context of web pages. You could listent to specific events (such as MouseEvent and KeyboardEvent ) 就像普通脚本一样。

manifest.json

{
  "manifest_version": 2,
  "name": "Test extension",
  "version": "1.0",
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": [
        "content.js"
      ],
      "all_frames": true
    }
  ]
} 

content.js

document.addEventListener('mousedown', function (e) {
    console.log('mouse down');
}, false);

document.addEventListener('keydown', function (e) {
    console.log('key down');
}, false);