我正在尝试将回调附加到Gmail中的“发送邮件”ajax操作。我已经能够根据请求有效负载区分发送邮件操作与其他AJAX操作,但无法挂钩到实际的AJAX调用。
到目前为止,我已尝试使用重写XMLHttpRequest.open()方法作为详细here。这没效果。我也尝试重写XMLHttpRequest.send()。也失败了。
有什么想法?非常感谢提前。
答案 0 :(得分:8)
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.