Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your code doesn't work because <code>event.srcElement</code> refers to the <code>&lt;iframe&gt;</code> element, not its content. To access its content document, you have to wait for the frame to be loaded (<code>onload</code> or polling), then use <code>frame.contentDocument</code> to access the frame.</p> <p>Starting from Chrome 37.0.1995.0, you can also use the <a href="https://developer.chrome.com/extensions/content_scripts#match_about_blank" rel="nofollow noreferrer"><code>match_about_blank</code></a> (with <a href="https://developer.chrome.com/extensions/content_scripts#all_frames" rel="nofollow noreferrer">all_frames</a>) to insert a content script in the <code>about:blank</code> frame that captures the event and sends it to the parent content script.</p> <p>Here is an example of an implementation for the original idea (using polling):</p> <p>The relevant parts of <code>manifest.json</code>:</p> <pre><code> "content_scripts": [{ "matches": ["*://mail.google.com/*"], "js": ["contentscript.js"], "run_at": "document_end" }], </code></pre> <p><code>contentscript.js</code></p> <pre><code>function keyDown(e) {console.log(e.which);}; // Test function keyUp(e) {console.log(e.keyCode);}; // Test (function checkForNewIframe(doc) { if (!doc) return; // document does not exist. Cya // Note: It is important to use "true", to bind events to the capturing // phase. If omitted or set to false, the event listener will be bound // to the bubbling phase, where the event is not visible any more when // Gmail calls event.stopPropagation(). // Calling addEventListener with the same arguments multiple times bind // the listener only once, so we don't have to set a guard for that. doc.addEventListener('keydown', keyDown, true); doc.addEventListener('keyup', keyUp, true); doc.hasSeenDocument = true; for (var i = 0, contentDocument; i&lt;frames.length; i++) { try { contentDocument = iframes[i].document; } catch (e) { continue; // Same-origin policy violation? } if (contentDocument &amp;&amp; !contentDocument.hasSeenDocument) { // Add poller to the new iframe checkForNewIframe(iframes[i].contentDocument); } } setTimeout(checkForNewIframe, 250, doc; // &lt;-- delay of 1/4 second })(document); // Initiate recursive function for the document. </code></pre> <p>Note that I used polling instead of DOM mutation events, because the latter <strong><a href="http://groups.google.com/group/mozilla.dev.platform/browse_thread/thread/2f42f1d75bb906fb?pli=1" rel="nofollow noreferrer">heavily reduces performance</a></strong>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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