Created
July 27, 2015 05:12
-
-
Save Linrstudio/7638b26cf1eefe1725dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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