油猴脚本代码如下,但是在指定页面中不能捕获到对应的fetch请求,请问我该如何获取到该fetch请求呢?
// ==UserScript==
// @name xx 功能增强
// @namespace http://tampermonkey.net/
// @version 0.1
// @description xx 调试功能
// @author You
// @match https://xxx/main/biz_details/*/xx?defaultActiveKey=debug
// @icon https://www.google.com/s2/favicons?sz=64
// @grant unsafeWindow
// ==/UserScript==
(function () {
console.log(window.unsafeWindow)
const originFetch = fetch;
console.log(originFetch);
window.unsafeWindow.fetch = (url, options) => {
console.log('外层捕获请求',url);
return originFetch(url, options).then(async (response) => {
console.log('内层捕获请求',url);
if (url === 'https://xxx/v3/curlRtpQuery') {
console.log('捕获链接',url);
const responseClone = response.clone();
let res = await responseClone.json();
res.data.push('油猴脚本修改数据')
const responseNew = new Response(JSON.stringify(res), response);
return responseNew;
} else {
return response;
}
});
};
// Your code here...
})();