ajax-hook icon indicating copy to clipboard operation
ajax-hook copied to clipboard

implemented `onConfig` to by pass the request if certain conditions are matched

Open cyfung1031 opened this issue 1 year ago • 3 comments

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)
    }
})

cyfung1031 avatar Aug 16 '23 11:08 cyfung1031

Combined Distribution Script ajaxhook.js for Testing (PR 119, 120, 121, 122) https://cdn.jsdelivr.net/gh/cyfung1031/ajax-hook@1ebe48e08108449669290a226e52fc6fbf7ec9ef/dist/ajaxhook.js

cyfung1031 avatar Aug 16 '23 15:08 cyfung1031

新增 api 需要完善一下 markdown 文档

DAHUIAAAAA avatar Sep 06 '23 16:09 DAHUIAAAAA

新增 api 需要完善一下 markdown 文档

新增了

cyfung1031 avatar Sep 14 '23 10:09 cyfung1031