I am writing a browser extension that needs to bind handlers to events with the keyboard and keydown on all pages. I can make it work very well with the following script code.
document.addEventListener("keydown",keyDown, true); document.addEventListener("keyup", keyUp, true);
I can't get this to work in Gmail. In particular, I cannot get it to work when creating the body of a new letter. It will work wherever I tested. I think the problem is that Gmail calls stopPropagation on all keyboard events, but it's hard to debug their minimized code. I thought setting the third parameter to true would cause the event to be committed during CAPTURE_PHASE , but this does not work.
How can I capture keyup and keydown when creating a new organ in Gmail with Google Chrome script content?
Edit:
I made sure that my content scripts are injected into all iframes of the DOM by adding "all_frames": true, to my manifest. I even tried using the following code:
document.addEventListener("DOMNodeInserted", function (event) { if(event.type === "DOMNodeInserted") { if(event.srcElement.nodeName === "IFRAME") { console.log(event.srcElement.nodeName + " iframe detected"); event.srcElement.addEventListener("keydown", function(kevent) { document.dispatchEvent(kevent); }, true); event.srcElement.addEventListener("keyup", function(kevent) { document.dispatchEvent(kevent); }, true); } } },true);
This does not fix the problem with Gmail yet.
ZeroDivide
source share