Search code examples
javascripthtmlbookmarklet

Removing event listeners to which you do not have a reference


I've written a bookmarklet that creates a Canvas with an event listener tracking mouse clicks that covers the whole page. The problem is that some sites have event listeners on the body of the page that have useCapture set to true. This blocks my Canvas from registering clicks.

I've researched and tried everything I could think of to remove the event listeners on the body element, but it seems that it is impossible to mess with the event listeners of the body. Does anyone have any ideas?

Side note: please don't mark this as a duplicate. None of the other posts on removing event listeners that I have seen are asking the same thing. I am not trying to remove an event listener that I created myself -- I am trying to remove an event listener that was created through code that I cannot modify.


Solution

  • Turns out this isn't possible. Unless somebody suggests another solution, there is no known way to access event listeners attached to the body of a webpage without pointers to those event listeners.