-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathHook_xhr.js
52 lines (47 loc) · 1.8 KB
/
Hook_xhr.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
// ==UserScript==
// @name Hook_xhr
// @namespace https://github.com/0xsdeo/Hook_JS
// @version 2024-11-30
// @description set RequestHeader -> log stack and RequestHeader info && send Request -> log stack and request info
// @attention 当打印的request内容为[object Blob]时,则表示请求内容为二进制流。
// @author 0xsdeo
// @match http://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function () {
'use strict';
let hook_open = XMLHttpRequest.prototype.open;
let hook_setRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
let hook_send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function () {
this.method = arguments[0];
this.url = arguments[1];
return hook_open.call(this, ...arguments);
}
XMLHttpRequest.prototype.setRequestHeader = function () {
console.log(
"请求 " + this.url + " 时请求头被设置\n" +
"请求头:" + arguments[0] + ": " + arguments[1]
)
console.log(new Error().stack);
return hook_setRequestHeader.call(this, ...arguments);
}
XMLHttpRequest.prototype.send = function () {
this.data = arguments[0];
if (this.data != null) {
console.log(
"请求方式:" + this.method + "\n" +
"请求url:" + this.url + "\n" +
"请求内容:" + this.data + "\n"
);
} else {
console.log(
"请求方式:" + this.method + "\n" +
"请求url:" + this.url + "\n"
);
}
console.log(new Error().stack);
return hook_send.call(this, ...arguments);
}
})();