以下是我如何使用的方式 我ajaxHook之后 发现页面上的fetch都能劫持到 但是我自己写的fetch会劫持不到
并且我想用这个劫持去修改 header x-forwarded-for
// ==UserScript==
// @name DXXXX
// @namespace http://tampermonkey.net/
// @version 2.0.21
// @description
// @grant GM_getValue
// @grant GM_setValue
// @require https://scriptcat.org/lib/637/1.4.0/ajaxHooker.js#sha256=2yxSlbNRgvhzRczZ32IEACTSHFaqFtO6VtLu769ZBdM=
// @grant GM_xmlhttpRequest
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
ajaxHooker.hook(request => {
request.response = res => {
const responseText = res.responseText; // 注意保存原数据
console.log(responseText);
};
});
fetch(`https://www.example.com`, {
headers: {
"accept": "*/*",
"accept-language": "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"cache-control": "max-age=0",
"content-type": "application/x-www-form-urlencoded",
"if-modified-since": "0"
},
referrer: "https://www.example.com",
referrerPolicy: "strict-origin-when-cross-origin",
method: "POST",
mode: "cors",
credentials: "include"
}).then(response => {
if (!response.ok) {
throw new Error('Network response was not ok.');
}
return response.text();
}).then(data => {
}).catch(error => {
});
})();