(function () {
const log = [];
const save = (type, url, body, status) => {
log.push({ type, url, body: body && String(body).slice(0, 2000), status, t: Date.now() });
console.log('%c[CATCH]', 'color:lime', type, url, body && String(body).slice(0, 300));
};
const ofetch = window.fetch;
window.fetch = async function (...args) {
const url = typeof args[0] === 'string' ? args[0] : (args[0] && args[0].url);
const init = args[1] || {};
let reqBody = init.body;
try {
const res = await ofetch.apply(this, args);
const clone = res.clone();
let text = '';
try { text = await clone.text(); } catch (e) {}
save('fetch', url, (reqBody || '') + ' => ' + text.slice(0, 1500), res.status);
return res;
} catch (e) {
save('fetch-err', url, String(e), 0);
throw e;
}
};
const oopen = XMLHttpRequest.prototype.open;
const osend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function (m, u, ...r) {
this._u = u; this._m = m;
return oopen.call(this, m, u, ...r);
};
XMLHttpRequest.prototype.send = function (b) {
this.addEventListener('load', () => {
save('xhr', this._m + ' ' + this._u, (b || '') + ' => ' + String(this.responseText).slice(0, 1500), this.status);
});
return osend.call(this, b);
};
window.__meshLog = log;
console.log('%cперехват включён — ответь на 1 вопрос', 'color:lime;font-size:14px');
})();