Skip to content
Advertisement

Intercept fetch() API requests and responses in JavaScript

I want to intercept fetch API requests and responses in JavaScript.

For example, before sending the request I want to intercept the request URL. I’d like to intercept the response once it arrives as well.

The below code is for intercepting responses of all XMLHTTPRequests.

JavaScript

I want to implement the same feature for fetch() API. How can I do this?

Advertisement

Answer

For intercepting the fetch request and parameter we can go for below mentioned way. its resolved my issue.

JavaScript
Advertisement