@webrecorder/wombat 3.8.14 → 3.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,10 +8,13 @@ function WBWombat(info) {
8
8
  if (!(this instanceof WBWombat)) return new WBWombat(info);
9
9
  /** @type {Object} */
10
10
  this.info = info;
11
+ this.prefixMod = this.info.prefix + this.info.mod + '/';
12
+
11
13
  this.initImportScriptsRewrite();
12
14
  this.initHTTPOverrides();
13
15
  this.initClientApisOverride();
14
16
  this.initCacheApisOverride();
17
+ this.initSelfOverrides();
15
18
  }
16
19
 
17
20
  /**
@@ -35,7 +38,10 @@ WBWombat.prototype.noRewrite = function(url) {
35
38
  * @return {boolean}
36
39
  */
37
40
  WBWombat.prototype.isRelURL = function(url) {
38
- return url.indexOf('/') === 0 || (!url.startsWith('http:') && !url.startsWith('https:'));
41
+ return (
42
+ url.indexOf('/') === 0 ||
43
+ (!url.startsWith('http:') && !url.startsWith('https:'))
44
+ );
39
45
  };
40
46
 
41
47
  /**
@@ -81,7 +87,10 @@ WBWombat.prototype.ensureURL = function(url, resolveAgainst) {
81
87
 
82
88
  // if url starts with current origin, but not properly rewritten, rewrite against current baseUr
83
89
  if (newURL.indexOf(self.location.origin) === 0) {
84
- return this.maybeResolveURL(newURL.slice(self.location.origin.length), resolveAgainst);
90
+ return this.maybeResolveURL(
91
+ newURL.slice(self.location.origin.length),
92
+ resolveAgainst
93
+ );
85
94
  }
86
95
  return newURL;
87
96
  };
@@ -94,12 +103,23 @@ WBWombat.prototype.ensureURL = function(url, resolveAgainst) {
94
103
  WBWombat.prototype.rewriteURL = function(url) {
95
104
  var rwURL = this.ensureURL(url, this.info.originalURL);
96
105
  if (!rwURL) return url;
97
- if (this.info.prefixMod) {
98
- return this.info.prefixMod + rwURL;
106
+ if (this.prefixMod) {
107
+ return this.prefixMod + rwURL;
99
108
  }
100
109
  return rwURL;
101
110
  };
102
111
 
112
+ /**
113
+ * Extract original URL
114
+ */
115
+ WBWombat.prototype.extractOriginalURL = function(url) {
116
+ if (url && url.startsWith(this.prefixMod)) {
117
+ return url.slice(this.prefixMod.length);
118
+ }
119
+
120
+ return url;
121
+ };
122
+
103
123
  /**
104
124
  * Rewrites the supplied URL of an controlled page using the mp\_ modifier
105
125
  * @param {string} url
@@ -184,9 +204,7 @@ WBWombat.prototype.rewriteFetchApi = function(input) {
184
204
  rwInput = new Request(new_url, input);
185
205
  }
186
206
  } else if (input.href) {
187
- // it is likely that input is either self.location or self.URL
188
- // we cant do anything here so just let it go
189
- rwInput = input.href;
207
+ rwInput = this.rewriteURL(input.href);
190
208
  }
191
209
  break;
192
210
  }
@@ -221,6 +239,67 @@ WBWombat.prototype.initImportScriptsRewrite = function() {
221
239
  };
222
240
  };
223
241
 
242
+ WBWombat.prototype.initSelfOverrides = function() {
243
+ //self.__WB_pmw = function() { return this; };
244
+
245
+ var wombat = this;
246
+
247
+ self._WB_wombat_location = new Proxy(self.location, {
248
+ get(target, prop, receiver) {
249
+ if (prop === 'href') {
250
+ return wombat.extractOriginalURL(target[prop]);
251
+ }
252
+
253
+ return target[prop];
254
+ }
255
+ });
256
+
257
+ self.____wb_rewrite_import__ = function(base, url) {
258
+ // if esm and base provided (set to import.meta.url), use that as base for imports
259
+ if (url && base) {
260
+ //if (!isImportMapped(url)) {
261
+ url = new URL(url, base).href;
262
+ //}
263
+ // non-esm single param call, url is base
264
+ } else if (base && url === undefined) {
265
+ url = base;
266
+ }
267
+ return import(/*webpackIgnore: true*/ wombat.rewriteURL(url));
268
+ };
269
+
270
+ var pm_origin = function pm_origin(origin_self) {
271
+ this.__WB_source = origin_self;
272
+ return this;
273
+ };
274
+
275
+ try {
276
+ self.Object.defineProperty(self.Object.prototype, '__WB_pmw', {
277
+ get: function() {
278
+ return pm_origin;
279
+ },
280
+ set: function() {},
281
+ configurable: true,
282
+ enumerable: false
283
+ });
284
+ } catch (e) {}
285
+
286
+ const WB_CHECK_THIS_FUNC = '_____WB$wombat$check$this$function_____';
287
+
288
+ self.Object.defineProperty(self.Object.prototype, WB_CHECK_THIS_FUNC, {
289
+ configutable: false,
290
+ enumerable: false,
291
+ value: function(thisObj) {
292
+ try {
293
+ return thisObj && thisObj._WB_wombat_obj_proxy
294
+ ? thisObj._WB_wombat_obj_proxy
295
+ : thisObj;
296
+ } catch (e) {
297
+ return thisObj;
298
+ }
299
+ }
300
+ });
301
+ };
302
+
224
303
  /**
225
304
  * Applies overrides to the XMLHttpRequest.open and XMLHttpRequest.responseURL
226
305
  * in order to ensure URLs are rewritten.
@@ -288,7 +367,7 @@ WBWombat.prototype.initHTTPOverrides = function() {
288
367
  if (self.Response && self.Response.prototype) {
289
368
  var originalRedirect = self.Response.prototype.redirect;
290
369
  self.Response.prototype.redirect = function redirect(url, status) {
291
- var rwURL = wombat.rewriteUrl(url);
370
+ var rwURL = wombat.rewriteURL(url);
292
371
  return originalRedirect.call(this, rwURL, status);
293
372
  };
294
373
  }
@@ -299,7 +378,7 @@ WBWombat.prototype.initHTTPOverrides = function() {
299
378
  return function EventSource(url, configuration) {
300
379
  var rwURL = url;
301
380
  if (url != null) {
302
- rwURL = wombat.rewriteUrl(url);
381
+ rwURL = wombat.rewriteURL(url);
303
382
  }
304
383
  return new EventSource_(rwURL, configuration);
305
384
  };