ajax-hooker 1.2.5 → 1.2.6

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.
package/dist/cjs/index.js CHANGED
@@ -31,7 +31,7 @@ Object.getOwnPropertyDescriptor.bind(Object);
31
31
 
32
32
  const getType = Object.prototype.toString.call.bind(Object.prototype.toString);
33
33
 
34
- const resolveUrl = (url = "") => new URL(url, window.location.origin).toString();
34
+ const resolveUrl = (url = "") => new URL(url, window.location.href).toString();
35
35
 
36
36
  const getProxyValue = (target, prop) => {
37
37
  const value = Reflect.get(target, prop);
@@ -97,6 +97,7 @@ class XhrInterceptor {
97
97
  console.warn("[AjaxInterceptor] Error in xhr request hooks:", error);
98
98
  }
99
99
  hooker.req = newRequest;
100
+ if (target.readyState !== XMLHttpRequest.OPENED) return;
100
101
  const needReopen = oldRequest.method !== newRequest.method || oldRequest.url !== newRequest.url;
101
102
  const headersChanged = !self.headersEqual(oldRequest.headers, newRequest.headers);
102
103
  const shouldReopen = needReopen || headersChanged;
@@ -354,7 +355,8 @@ class FetchInterceptor {
354
355
  };
355
356
  }
356
357
  resolveRequest(req, newRequest, sourceMap) {
357
- const urlChanged = typeof req === "string" && newRequest.url !== req || req instanceof URL && newRequest.url !== req.href || req instanceof Request && newRequest.url !== req.url;
358
+ const resolvedOriginalUrl = typeof req === "string" ? resolveUrl(req) : req instanceof URL ? req.href : req.url;
359
+ const urlChanged = newRequest.url !== resolvedOriginalUrl;
358
360
  if (typeof req === "string") return urlChanged ? newRequest.url : req;
359
361
  if (req instanceof URL) return urlChanged ? new URL(newRequest.url) : req;
360
362
  if (req instanceof Request) {
package/dist/esm/index.js CHANGED
@@ -25,7 +25,7 @@ Object.getOwnPropertyDescriptor.bind(Object);
25
25
 
26
26
  const getType = Object.prototype.toString.call.bind(Object.prototype.toString);
27
27
 
28
- const resolveUrl = (url = "") => new URL(url, window.location.origin).toString();
28
+ const resolveUrl = (url = "") => new URL(url, window.location.href).toString();
29
29
 
30
30
  const getProxyValue = (target, prop) => {
31
31
  const value = Reflect.get(target, prop);
@@ -91,6 +91,7 @@ class XhrInterceptor {
91
91
  console.warn("[AjaxInterceptor] Error in xhr request hooks:", error);
92
92
  }
93
93
  hooker.req = newRequest;
94
+ if (target.readyState !== XMLHttpRequest.OPENED) return;
94
95
  const needReopen = oldRequest.method !== newRequest.method || oldRequest.url !== newRequest.url;
95
96
  const headersChanged = !self.headersEqual(oldRequest.headers, newRequest.headers);
96
97
  const shouldReopen = needReopen || headersChanged;
@@ -348,7 +349,8 @@ class FetchInterceptor {
348
349
  };
349
350
  }
350
351
  resolveRequest(req, newRequest, sourceMap) {
351
- const urlChanged = typeof req === "string" && newRequest.url !== req || req instanceof URL && newRequest.url !== req.href || req instanceof Request && newRequest.url !== req.url;
352
+ const resolvedOriginalUrl = typeof req === "string" ? resolveUrl(req) : req instanceof URL ? req.href : req.url;
353
+ const urlChanged = newRequest.url !== resolvedOriginalUrl;
352
354
  if (typeof req === "string") return urlChanged ? newRequest.url : req;
353
355
  if (req instanceof URL) return urlChanged ? new URL(newRequest.url) : req;
354
356
  if (req instanceof Request) {
@@ -22,7 +22,7 @@ var AjaxHooker = function(exports) {
22
22
  }
23
23
  Object.getOwnPropertyDescriptor.bind(Object);
24
24
  const getType = Object.prototype.toString.call.bind(Object.prototype.toString);
25
- const resolveUrl = (url = "") => new URL(url, window.location.origin).toString();
25
+ const resolveUrl = (url = "") => new URL(url, window.location.href).toString();
26
26
  const getProxyValue = (target, prop) => {
27
27
  const value = Reflect.get(target, prop);
28
28
  if (typeof value !== "function") return value;
@@ -85,6 +85,7 @@ var AjaxHooker = function(exports) {
85
85
  console.warn("[AjaxInterceptor] Error in xhr request hooks:", error);
86
86
  }
87
87
  hooker.req = newRequest;
88
+ if (target.readyState !== XMLHttpRequest.OPENED) return;
88
89
  const needReopen = oldRequest.method !== newRequest.method || oldRequest.url !== newRequest.url;
89
90
  const headersChanged = !self.headersEqual(oldRequest.headers, newRequest.headers);
90
91
  const shouldReopen = needReopen || headersChanged;
@@ -339,7 +340,8 @@ var AjaxHooker = function(exports) {
339
340
  };
340
341
  }
341
342
  resolveRequest(req, newRequest, sourceMap) {
342
- const urlChanged = typeof req === "string" && newRequest.url !== req || req instanceof URL && newRequest.url !== req.href || req instanceof Request && newRequest.url !== req.url;
343
+ const resolvedOriginalUrl = typeof req === "string" ? resolveUrl(req) : req instanceof URL ? req.href : req.url;
344
+ const urlChanged = newRequest.url !== resolvedOriginalUrl;
343
345
  if (typeof req === "string") return urlChanged ? newRequest.url : req;
344
346
  if (req instanceof URL) return urlChanged ? new URL(newRequest.url) : req;
345
347
  if (req instanceof Request) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ajax-hooker",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "Browser AJAX interceptor for XMLHttpRequest and fetch with unified hooks, request/response mutation, and streaming response support.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",