fix: add FetchProxy
This will let us intercept fetch requests (until now we're only proxying
XMLHttpRequest), in order to fix the issues we're experiencing with some
features.
Bug: twpowertools:229
Change-Id: I277473c05479ca39bb6183a51855382124890bde
diff --git a/src/xhrInterceptor/XHRProxy.js b/src/xhrInterceptor/XHRProxy.js
index 14d2aae..1552966 100644
--- a/src/xhrInterceptor/XHRProxy.js
+++ b/src/xhrInterceptor/XHRProxy.js
@@ -1,7 +1,6 @@
import {waitFor} from 'poll-until-promise';
import {correctArrayKeys} from '../common/protojs';
-import ResponseModifier from '../xhrInterceptor/ResponseModifier';
import * as utils from '../xhrInterceptor/utils.js';
const kSpecialEvents = ['load', 'loadend'];
@@ -55,13 +54,16 @@
* requests through our internal interceptors to read/modify requests/responses.
*
* Slightly based in https://stackoverflow.com/a/24561614.
+ *
+ * @param responseModifier
+ * @param messageIdTracker
*/
export default class XHRProxy {
- constructor() {
+ constructor(responseModifier, messageIdTracker) {
this.originalXMLHttpRequest = window.XMLHttpRequest;
- this.messageID = 0;
- this.responseModifier = new ResponseModifier();
+ this.messageIdTracker = messageIdTracker;
+ this.responseModifier = responseModifier;
this.#overrideXHRObject();
}
@@ -80,7 +82,7 @@
window.XMLHttpRequest = function() {
this.xhr = new XHRProxyInstance.originalXMLHttpRequest();
- this.$TWPTID = XHRProxyInstance.messageID++;
+ this.$TWPTID = XHRProxyInstance.messageIdTracker.getNewId();
this.$responseModified = false;
this.$responseIntercepted = false;
this.specialHandlers = {