在 Javascript 中寻找捕获关键事件的函数?

发布于 2024-11-19 19:30:15 字数 161 浏览 9 评论 0原文

我正在为一个复杂的网络应用程序编写用户脚本。现有代码正在捕获“j”和“k”keydown 事件。

我希望能够找到这个函数来看看它在做什么。有没有办法列出文档中的所有关键事件处理程序?或者也许有一种方法可以在 Chrome 开发者工具中以某种方式在我按下字母时设置断点?

I'm writing a user script for a complex web app. The existing code is catching the 'j' and 'k' keydown events.

I'd like to be able to find this function to see what it's doing. Is there a way to list all the key event handlers in a document? Or maybe a way to set a breakpoint somehow in Chrome Developer Tools for when I press the letter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我ぃ本無心為│何有愛 2024-11-26 19:30:15

是的,在开发人员工具中,转到“脚本”选项卡,选择页面,转到“事件侦听器断点”、“键盘”、“keydown” 。

在此处输入图像描述

尽管这可能不一定对您有多大帮助,例如,如果脚本被缩小或者他们使用了库。但你可以尝试一下。

Yes, in the developer tools, go to the Scripts tab, select the page, go to Event Listener Breakpoints, Keyboard, keydown.

enter image description here

Though this might not necessarily help you much, e.g. if the script is minified or they use a library. But you can give it a try.

段念尘 2024-11-26 19:30:15

如果您可以先运行脚本的一部分,并且在文档级别处理按键,则可以安装此拦截以查看代码的哪一部分正在设置键盘处理程序:

var oldListener = document.addEventListener;
document.addEventListener = function(type, listener, capture) {
    if (type == "keydown" || type == "keyup" || type == "keypress") {
        console.log("type=" + type + " listener=" + listener.toString().slice(0, 80));
    }
    return (oldListener.apply(this, arguments));
}

If you can get a piece of your script to run first and if the keys are handled at the document level, you can install this intercept to see what part of the code is setting the keyboard handler:

var oldListener = document.addEventListener;
document.addEventListener = function(type, listener, capture) {
    if (type == "keydown" || type == "keyup" || type == "keypress") {
        console.log("type=" + type + " listener=" + listener.toString().slice(0, 80));
    }
    return (oldListener.apply(this, arguments));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文