Skip to content

Instantly share code, notes, and snippets.

@Linrstudio
Created July 27, 2015 05:12
Show Gist options
  • Save Linrstudio/7638b26cf1eefe1725dd to your computer and use it in GitHub Desktop.
Save Linrstudio/7638b26cf1eefe1725dd to your computer and use it in GitHub Desktop.
I have the script events_spy.js:
(function(original) {
Element.prototype.addEventListener = function(type, listener,
useCapture) {
if (typeof (this._handlerTypes) == 'undefined') {
this._handlerTypes = {};
}
this._handlerTypes[type] = true;
return original.apply(this, arguments);
}
})(Element.prototype.addEventListener);
// https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/HZ7j11UlPHk
(function(original) {
Element.prototype.removeEventListener = function(type, listener,
useCapture) {
if (typeof (this._handlerTypes) != 'undefined') {
delete this._handlerTypes[type];
}
return original.apply(this, arguments);
}
})(Element.prototype.removeEventListener);
I declare this script in manifest.json as follows:
"content_scripts" : [
{
"matches" : [ "http://*/*", "https://*/*" ],
"js" : [ "content/events_spy.js" ],
"run_at" : "document_start",
"all_frames" : true
},
...
]
Then I test my extension on the following HTML page:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<a id="test" href="#">Click here</a>
<script type="application/javascript">
document.getElementById("test").addEventListener("click", function()
{ alert("clicked"); }, false);
</script>
</body>
</html>
Unfortunately, this doesn't work - I can't see that debugger stops
inside my custom addEventListener() function. What am I doing wrong?
Thanks,
Michael
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment