Use Chrome's webkit inspector to remove an event listener

I know you can see the event listeners in the Chrome Inspector but i'm doing some debugging work and there are so many event listeners lying around I'd like to disable some without editing the code

Is there a way to disable an event listener quickly from the Webkit inspector?

Perhaps have a look and type some code into the console to removeEventListener the listener? How would I do this? For instance how would i remove the 'click' listener above

Answers


Sorry, you are out of luck (at least for the time being.) removeEventListener requires the exact listener Function object as an argument, and DevTools do not let you get a grip of the listener function in any way.

If you definitely need this feature, please file a bug at http://new.crbug.com (against Chrome) or http://bugs.webkit.org (against WebKit, the preferred way).


You can use getEventListeners(element).click[index].listener to get a reference to a listener (in a WebKit console).

So, to remove the first listener, you could do:

document.removeEventListener('click', getEventListeners(document).click[0].listener)

Similarly, to remove all listeners, you could use this function:

function removeEventListeners(element, listenerMap) {
    Object.keys(listenerMap).forEach(function (name) {
        var listeners = listenerMap[name];
        listeners.forEach(function (object) {
            element.removeEventListener(name, object.listener);
        });
    });
}

removeEventListeners(document, getEventListeners(document))

You can remove an event listener in the javascript console. First find the element to which this event listener is attached. Let's call it e. Then you execute: e.onclick=null. For example, many event listeners are attached to "body", then the above code becomes´╝Ü document.body.onclick=null. After that the event listener is removed.


Simply:

getEventListeners(document).click[0].remove()

This works with other elements, too:

getEventListeners($('#submit-button')[0]).click[0].remove()

And other types of events:

getEventListeners($('#login-form')[0]).submit[0].remove()

Maybe late but.

In chrome there is a specific button to remove the method call of a specific event.

Right click on the html input (boutton in my example) inspect element, chrome opens the element viewer tab (in html mode) with another panel composed of subtabs in this panel click on the "event listener" tab and unfold the event you're intersted in (onclick in my example) put the mouse point over the name of the button you inspected and a button "remove" will apear and one clicked the event listener is deleted for the current page loaded.


Need Your Help

Modify scroll speed, treeview drag&drop in C#

c# winforms treeview

i have a treview control with drag&drop functionality that response to draw the node outside the visible limits scrolling in the apropiate direction. The problem is that it scroll at light spee...

Limit attempts for inputting in form

php html mysql

how do I set a number of attempts for a user to enter the one time password?