Skip to content

Instantly share code, notes, and snippets.

@past
Created January 28, 2014 09:38
Show Gist options
  • Save past/8664697 to your computer and use it in GitHub Desktop.
Save past/8664697 to your computer and use it in GitHub Desktop.
// -sp-context:browser
// Dumps the event listeners defined in the content window of the current tab.
var Ci = Components.interfaces;
var Cc = Components.classes;
let eventListenerService = Cc["@mozilla.org/eventlistenerservice;1"]
.getService(Ci.nsIEventListenerService);
Cu.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this);
let dbg = new Debugger();
let DOwindow = dbg.addDebuggee(content.window);
let nodes = content.window.document.querySelectorAll("*");
nodes = [content.window].concat(Array.prototype.slice.call(nodes));
for (let node of nodes) {
let handlers = eventListenerService.getListenerInfoFor(node);
for (let handler of handlers) {
let listener = handler.listenerObject;
let fName = handler.type;
let dom0 = !!node["on" + fName];
let nodeName = getNodeName(node);
log("Node: " + nodeName);
log("Type: " + fName);
log("DOM0: " + dom0);
log("Capturing: " + handler.capturing);
log("Allows Untrusted: " + handler.allowsUntrusted);
log("System Event: " + handler.inSystemEventGroup);
if (listener) {
let listenerDO = DOwindow.makeDebuggeeValue(listener);
let script = listenerDO.script;
let url, line;
if (script) {
url = script.url;
line = script.startLine;
}
log("Origin: " + url + ":" + line);
}
log("---------------------------------------------------------");
}
}
function getNodeName(node) {
let nodeName = (node.nodeName + "").toLowerCase();
if (node.id) {
nodeName += "#" + node.id;
}
if (node.className) {
nodeName += "." + node.className;
}
if (nodeName == "undefined") {
nodeName = "window " + node.document.location.href;
}
return nodeName;
}
dbg.removeDebuggee(DOwindow);
function log(msg) {
dump(msg + "\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment