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 +4 -2
- package/dist/esm/index.js +4 -2
- package/dist/iife/index.js +4 -2
- package/package.json +1 -1
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.
|
|
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
|
|
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.
|
|
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
|
|
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) {
|
package/dist/iife/index.js
CHANGED
|
@@ -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.
|
|
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
|
|
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.
|
|
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",
|