I'm trying to attach a callback to the "Send mail" ajax action in Gmail. I've been able to differentiate a Send mail action from other AJAX actions based on the request payload but have been unable to hook into the actual AJAX call.
Thus far, I've tried using overriding the XMLHttpRequest.open() method as detailed here. That hasn't worked. I've also tried overriding XMLHttpRequest.send(). Also failed.
Any thoughts? Much thanks in advance.
I'm trying to attach a callback to the "Send mail" ajax action in Gmail. I've been able to differentiate a Send mail action from other AJAX actions based on the request payload but have been unable to hook into the actual AJAX call.
Thus far, I've tried using overriding the XMLHttpRequest.open() method as detailed here. That hasn't worked. I've also tried overriding XMLHttpRequest.send(). Also failed.
Any thoughts? Much thanks in advance.
Share Improve this question edited May 23, 2017 at 12:22 CommunityBot 11 silver badge asked Jul 5, 2011 at 14:46 Rui JiangRui Jiang 1,6721 gold badge16 silver badges25 bronze badges 4- Are you building a plugin, a bookmarklet or what? – Gerben Commented Jul 5, 2011 at 18:32
- Building a Chrome extension. Using content scripts to inject the javascript. – Rui Jiang Commented Jul 5, 2011 at 21:12
- Did you manage to get it work ? I'm facing the same problem. – Timothée Jeannin Commented Jul 7, 2014 at 15:31
- @TimothéeJeannin Have a look at my answer below. – Joel Commented May 4, 2015 at 19:49
1 Answer
Reset to default 8 +75Google'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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744866121a4597986.html
评论列表(0条)