Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get all event listeners on the page in Google Chrome
var items =
).map(function(element) {
var listeners = getEventListeners(element);
return {
element: element,
listeners: Object.keys(listeners).map(function(k) {
return { event: k, listeners: listeners[k] };
}).filter(function(item) {
return item.listeners.length;
// See below for things you can do with the items
// Things you can do with the items
// 1. log them to the console
// 2. Put a red border around the elements
items.forEach(function(item) { = '1px solid red';
// 3. generate a summary
var summary = .map(function(item) {
var el = item.element,
id =,
className = el.className;
if (className instanceof SVGAnimatedString) {
className = className.baseVal;
var str = el.tagName.toLowerCase() + (id ? '#' + id : '') + (className ? '.' + className.replace(/\s+/g, '.') : '');
str += ' ' + {
return l.event + ': ' + l.listeners.length;
}).join(' ');
return str;
Copy link

julienetie commented Oct 4, 2016

Useful script, quick typo: .map(function(item) Should be

Copy link

marcobiedermann commented Dec 9, 2016

Nice script, you could use the new ES2015 syntax and make use of the Array.from methode to make it a bit cleaner:

const items = Array.From(document.querySelectorAll('*')).map(element => {
  const listeners = getEventListeners(element);

  return {
    element: element,
    listeners: Object.keys(listeners).map(key => {

      return {
        event: key,
        listeners: listeners[key]


}).filter(item => item.listeners.length);

Copy link

ilyazub commented Jul 14, 2017

@marcobiedermann it will work if you replace Array.From with Array.from.

Copy link

nmaxcom commented Nov 28, 2017

I'd also suggest, for sanity's sake, to add a little .sort() right before map, like so: listeners: Object.keys(listeners).sort().map(key => {

Haven't tested with that ES6 mod but with OP's worked fine.

Copy link

ORESoftware commented Jan 2, 2018


how to get all events on window itself? Right now I have:

['click', 'keyup', 'dragstart', 'dragend'].forEach(function (name) {
  window.addEventListener(name, function (ev) {
    console.log(name + ' event captured by content script:', ev);

but it would be nice to access a complete list of events programmatically (not hardcoded)

Copy link

ndvbd commented Jun 9, 2018

Very cool!

Copy link

xxammuxx commented Jan 1, 2019

Just to mention, this js script works in the console and not in script tag or script file in an html page.

Copy link

samarpanda commented Feb 6, 2019

@xxammuxx - Do you have any example where it doesn't seem to be working? Would be great if you can share a jsfiddle snippet.

Copy link

alex2844 commented Sep 29, 2019

Copy link

preflight commented Oct 16, 2019

From the codepen author:

"...all of the major browsers have decided against supporting getEventListeners. Only Chrome supports it from the command line"

Copy link

ochen1 commented Apr 25, 2020

👍 Thank you! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment