-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncaptchaRequestInterceptor.js
41 lines (35 loc) · 1.25 KB
/
funcaptchaRequestInterceptor.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
(function () {
const originalFetch = window.fetch;
window.fetch = async function (...args) {
const [resource] = args;
const url = typeof resource === 'string' ? resource : resource.url;
const response = await originalFetch.apply(this, args);
if (url.includes('/fc/gfct/')) {
try {
const clone = await response.clone().text();
window.postMessage({ type: 'gfct-response', body: clone }, '*');
} catch (err) {
console.error('[Inject Fetch] Error:', err);
}
}
return response;
};
const originalOpen = XMLHttpRequest.prototype.open;
const originalSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function (method, url, ...rest) {
this._interceptUrl = url;
return originalOpen.call(this, method, url, ...rest);
};
XMLHttpRequest.prototype.send = function (...args) {
if (this._interceptUrl?.includes('/fc/gfct/')) {
this.addEventListener('load', function () {
try {
window.postMessage({ type: 'gfct-response', body: this.responseText }, '*');
} catch (e) {
console.error('[Inject XHR] Error:', e);
}
});
}
return originalSend.apply(this, args);
};
})();