ajax-hook
ajax-hook copied to clipboard
implemented `onConfig` to by pass the request if certain conditions are matched
close #118
Remarks
Since most requests are async
, it might not be suitable to do the bypassing in onRequest
.
onConfig
is synchronously triggered in xhr.open
, so it can completely bypass the entire open
+setRequestHeader
(POST request)+send
.
Usage
const { unProxy, originXhr } = proxy({
onConfig: (config, xhrProxy) => {
console.log(`url: ${config.url}`)
if (config.url.indexOf('google.com') >= 0) return false;
},
onRequest: (config, handler) => {
handler.next(config);
},
onError: (err, handler) => {
handler.next(err)
},
onResponse: (response, handler) => {
handler.next(response)
}
})
Combined Distribution Script ajaxhook.js
for Testing (PR 119, 120, 121, 122)
https://cdn.jsdelivr.net/gh/cyfung1031/ajax-hook@1ebe48e08108449669290a226e52fc6fbf7ec9ef/dist/ajaxhook.js
新增 api 需要完善一下 markdown 文档
新增 api 需要完善一下 markdown 文档
新增了