Intercept send mail AJAX request in Gmail Intercept send mail AJAX request in Gmail ajax ajax

Intercept send mail AJAX request in Gmail


Google's trick is that they send the request from inside an iframe which has it's own JavaScript environment. However, since it is loaded from the same origin as the parent, you can still easily manipulate it even from the browser console:

[].slice.apply(document.querySelectorAll('iframe')).forEach(function (iframe) {    try {        var xhrProto = iframe.contentWindow.XMLHttpRequest.prototype;        var origOpen = xhrProto.open;        xhrProto.open = function () {            console.log('DO SOMETHING', arguments);            return origOpen.apply(this, arguments);        };    } catch (e) {}});

You might want to use a MutationObserver to detect newly added iframes reliably.