-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtraffic.js
77 lines (77 loc) · 1.69 KB
/
traffic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var SeleniumXMLHttpRequest = window.SeleniumXMLHttpRequest = window.XMLHttpRequest;
SeleniumXMLHttpRequest.requests = [];
SeleniumXMLHttpRequest.get = function() {
var requests = SeleniumXMLHttpRequest.requests.splice(0);
SeleniumXMLHttpRequest.requests = [];
return requests;
}
window.XMLHttpRequest = function() {
this.xhr = new SeleniumXMLHttpRequest();
};
[
'open',
'abort',
'setRequestHeader',
'send',
'addEventListener',
'removeEventListener',
'getResponseHeader',
'getAllResponseHeaders',
'dispatchEvent',
'overrideMimeType'
].forEach(function(method){
window.XMLHttpRequest.prototype[method] = function() {
if (method == 'open') {
this.open = arguments;
}
if (method == 'send') {
this.send = arguments;
}
return this.xhr[method].apply(this.xhr, arguments);
}
});
[
'onabort',
'onerror',
'onload',
'onloadstart',
'onloadend',
'onprogress',
'readyState',
'responseText',
'responseType',
'responseXML',
'status',
'statusText',
'upload',
'withCredentials',
'DONE',
'UNSENT',
'HEADERS_RECEIVED',
'LOADING',
'OPENED'
].forEach(function(scalar){
Object.defineProperty(window.XMLHttpRequest.prototype, scalar, {
get: function(){
return this.xhr[scalar];
},
set: function(obj){
this.xhr[scalar] = obj;
}
});
});
Object.defineProperty(window.XMLHttpRequest.prototype, 'onreadystatechange', {
get: function(){
return this.xhr.onreadystatechange;
},
set: function(onreadystatechange){
var _ = this;
_.xhr.onreadystatechange = function(){
if (_.xhr.readyState == 4) {
debugger
SeleniumXMLHttpRequest.requests.push([_.xhr.status, _.open[0], _.open[1], _.send[0], _.xhr.responseText]);
}
onreadystatechange.call(_.xhr);
};
}
});