Hey my friends and I new to javascript and are encountering problems with some code. Currently we're trying to make a chrome extension that detects when and how much a user works on a particular google document, by detecting keystrokes.
Our current method involves creating a 'keypress' event listener. We put it into a content.js file that runs on any docs.google webpage. The thing is, it works when you're on the page editing the title/anything else, but for some reason it doesnt register when the user is actually editing the document. We tried it on other websites and it works, and adding it to background.js doesn't work.
var handler = function (e) {
handler.data.push(e);
console.log("success");
console.log(handler.data);
}
handler.data = [];
window.addEventListener("keydown", handler);
document.addEventListener("keydown", handler);
So we tried to change the permissions on the 'iframe' of the google docs document so that we could use content scripts but it still didn't work (here's the code)
var divs = document.getElementsByTagName("iframe");
for(var i = 0; i < divs.length; i++){
divs[i].sandbox = 'allow-scripts'
divs[i].addEventListener('keydown', handler, true);
Any help appreciated