Intercept Fetch() API responses and request in Javascript : <p>I want to intercept the fetch API request and response in Javascript. </p>

<p>For ex: 
Before sending the request want to intercept the request URL and once get the response wants to intercept the response.</p>

<p>The below code is for intercepting response of All XMLHTTPRequest.</p>

<pre><code>(function(open) {
 XMLHttpRequest.prototype.open = function(XMLHttpRequest) {
    var self = this;
    this.addEventListener("readystatechange", function() {
        if (this.responseText.length &gt; 0 &amp;&amp; this.readyState == 4 &amp;&amp; this.responseURL.indexOf('www.google.com') &gt;= 0) {
            Object.defineProperty(self, 'response', {
                get: function() { return bValue; },
                set: function(newValue) { bValue = newValue; },
                enumerable: true,
                configurable: true
            });
            self.response = 'updated value' //Intercepted Value 
        }
    }, false);
    open.apply(this, arguments);
};
})(XMLHttpRequest.prototype.open);
</code></pre>

<p>I wan to implement the same feature for Fetch() API. </p>

<p>Thanks in Advance..</p>
