In fact, Fetch Api is supported by its own browser and has only one interface: fetch . The constructor returns one Promise , and you cannot receive Request , Response when you want to return your promise to rewrite the selection constructor.
The following code does not work.
(function() { var oldFectch = fetch; fetch.consotructor = function() { return new Promise(resolve, reject) {
So, does this mean that we cannot hook all the Fetch Api? NO!
Firstly, thanks window.fetch polyfill .
Then do something (edit fetch.js ) and rock.
(function(self) { 'use strict'; // comment or delete the following code block // if (self.fetch) { // return // } var support = { searchParams: 'URLSearchParams' in self, iterable: 'Symbol' in self && 'iterator' in Symbol, // ...
Finally, fix everything that is better for you!
self.fetch = function(input, init) { return new Promise(function(resolve, reject) { var request = new Request(input, init) var xhr = new XMLHttpRequest()
Rambo Nov 16 '17 at 10:13 2017-11-16 10:13
source share