Intercept Fetch() API responses and request in Javascript

前端 未结 5 1970
忘掉有多难
忘掉有多难 2020-12-05 14:10

I want to intercept the fetch API request and response in Javascript.

For ex: Before sending the request want to intercept the request URL and once get the respons

5条回答
  •  无人及你
    2020-12-05 14:28

    const fetch = window.fetch;
    window.fetch = (...args) => (async(args) => {
        var result = await fetch(...args);
        console.log(result); // intercept response here
        return result;
    })(args);
    

提交回复
热议问题