Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I detect keyboard events in Gmail
    primarykey
    data
    text
    <p>I am writing a browser extension that needs to attach handlers to the keyup and keydown events on all pages. I can get it working pretty well with the following content script code. </p> <pre><code>document.addEventListener("keydown",keyDown, true); document.addEventListener("keyup", keyUp, true); </code></pre> <p>I can't get this to work in Gmail though. Specifically I can't get it to work when composing the body of an new email. It will work everywhere else I have tested. I think the problem is because Gmail is calling <code>stopPropagation</code> on all keyboard events but it is difficult to debug their minimized code. I thought that setting the 3rd parameter to <code>true</code> would cause the event to be captured during the <code>CAPTURE_PHASE</code> but this isn't working. </p> <p>How can I capture <code>keyup</code> and <code>keydown</code> events while composing a new body in Gmail with a Google Chrome content script?</p> <p>Edit:</p> <p>I've ensured that my content scripts are being injected into all iframes of the DOM by adding <code>"all_frames": true,</code> to my manifest. I have even tried using the following code: </p> <pre><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); </code></pre> <p>This still doesn't fix the issue with Gmail. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload