admin管理员组

文章数量:1297120

I'm writing a user script for a plex 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?

I'm writing a user script for a plex 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?

Share Improve this question edited Dec 21, 2020 at 7:45 huyz asked Jul 12, 2011 at 16:37 huyzhuyz 2,3713 gold badges26 silver badges37 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

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

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.

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));
}

本文标签: google chrome devtoolsFinding function catching key event in JavascriptStack Overflow