Javascript – how to capture all changes to the contents of a element in JS

domeventsgmailiframejavascript

I am trying to write an extension for Google Chrome. I want to capture any keyboard input on a given page, and do something magic to it. I am able to do most of what I need with these lines:

document.addEventListener("keydown", function(event) { OnKeyDown(event); }, false);
document.addEventListener("keyup", function(event) { OnKeyDown(event); }, false);
document.addEventListener("keypress", function(event) { OnKeyPress(event); }, false);`

This works in most places, except for Google Mail. I am not getting these events when typing into the body of an email, because as it turns out, it's actually a <body> element, inside an <iframe>.

Best Answer

If you want to create trojan, you would better use C++, otherwise, reconcider your project/task. If project needs intercepting of all user input events in browser using JavaScript, then something is completely wrong with this project.