🏠 返回首頁 

js拦截全局网络请求

使用 ajaxhook , 拦截全局网络请求.


Install this script?
// ==UserScript==
// @name         js拦截全局网络请求
// @namespace    http://tampermonkey.net/
// @description  使用 ajaxhook , 拦截全局网络请求.
// @version      0.1
// @author       Plzbefat
// @match        *
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/ajaxhook.min.js
// @grant        none
// ==/UserScript==
(function() {
'use strict';
ah.proxy({
//请求发起前进入
onRequest: (config, handler) => {
console.log("发生请求,请求地址:"+config.url)
handler.next(config);
},
//请求发生错误时进入,比如超时;注意,不包括http状态码错误,如404仍然会认为请求成功
onError: (err, handler) => {
console.log("发生错误,错误信息:"+err.type)
handler.next(err)
},
//请求成功后进入
onResponse: (response, handler) => {
console.log("请求成功,反馈信息:"+response.response)
handler.next(response)
}
})
})();