Skip to content

Instantly share code, notes, and snippets.

@jamesr2323
Last active December 3, 2018 23:44
Show Gist options
  • Save jamesr2323/74f5454a50d53b611e69cbc4cf21dc6b to your computer and use it in GitHub Desktop.
Save jamesr2323/74f5454a50d53b611e69cbc4cf21dc6b to your computer and use it in GitHub Desktop.
params = {
cmd: 'Page.addScriptToEvaluateOnNewDocument',
params: {
source: %Q{
(function(XHR) {
"use strict";
window.xhrLog = '';
var open = XHR.prototype.open;
var send = XHR.prototype.send;
XHR.prototype.open = function(method, url, async, user, pass) {
this._url = url; // want to track the url requested
open.call(this, method, url, async, user, pass);
};
XHR.prototype.send = function(data) {
var self = this;
var oldOnReadyStateChange;
var url = this._url;
function onReadyStateChange() {
if(self.status === 200 && self.readyState == 4 /* complete */) {
window.xhrLog +=
'{"data":' + self.responseText + '}***[END]***';
}
if(oldOnReadyStateChange) {
oldOnReadyStateChange();
}
}
if(this.addEventListener) {
this.addEventListener("readystatechange", onReadyStateChange,
false);
} else {
oldOnReadyStateChange = this.onreadystatechange;
this.onreadystatechange = onReadyStateChange;
}
send.call(this, data);
}
})(XMLHttpRequest);
}
}
}
driver.send(:bridge).send_command(params)
### Do some stuff here
raw_ajax = driver.execute_script("return window.xhrLog")
ajax_responses = raw_ajax.split('***[END]***')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment