ajax-hooker 1.2.2 → 1.2.4

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/README.md CHANGED
@@ -3,9 +3,8 @@
3
3
  English | [中文](./README.zh-CN.md)
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/ajax-hooker.svg)](https://www.npmjs.com/package/ajax-hooker)
6
- [![npm downloads](https://img.shields.io/npm/dm/ajax-hooker.svg)](https://www.npmjs.com/package/ajax-hooker)
6
+ [![npm downloads](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.npmjs.org%2Fdownloads%2Fpoint%2Flast-day%2Fajax-hooker&query=%24.downloads&label=downloads&suffix=%2Fday&color=green)](https://www.npmjs.com/package/ajax-hooker)
7
7
  [![CI](https://img.shields.io/github/actions/workflow/status/Arktomson/ajaxInterceptor/ci.yml?branch=master&label=ci)](https://github.com/Arktomson/ajaxInterceptor/actions/workflows/ci.yml)
8
- [![bundle size](https://img.shields.io/bundlephobia/minzip/ajax-hooker)](https://bundlephobia.com/package/ajax-hooker)
9
8
 
10
9
  `ajax-hooker` is a browser-side AJAX interception library (XMLHttpRequest interceptor + Fetch interceptor). It deeply hooks native `XMLHttpRequest` and `fetch`, then normalizes both into one hook lifecycle so interception logic can be written once and reused across request types.
11
10
 
package/README.zh-CN.md CHANGED
@@ -5,7 +5,6 @@
5
5
  [![npm version](https://img.shields.io/npm/v/ajax-hooker.svg)](https://www.npmjs.com/package/ajax-hooker)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/ajax-hooker.svg)](https://www.npmjs.com/package/ajax-hooker)
7
7
  [![CI](https://img.shields.io/github/actions/workflow/status/Arktomson/ajaxInterceptor/ci.yml?branch=master&label=ci)](https://github.com/Arktomson/ajaxInterceptor/actions/workflows/ci.yml)
8
- [![bundle size](https://img.shields.io/bundlephobia/minzip/ajax-hooker)](https://bundlephobia.com/package/ajax-hooker)
9
8
 
10
9
  `ajax-hooker` 是一个浏览器端 AJAX 拦截库(XMLHttpRequest 拦截 + Fetch 拦截)。它会对原生 `XMLHttpRequest` 和 `fetch` 做深度劫持,并把两者抹平为统一的 Hook 生命周期,让拦截逻辑写一次即可复用。
11
10
 
package/dist/cjs/index.js CHANGED
@@ -404,11 +404,19 @@ class FetchInterceptor {
404
404
  if (headers instanceof Headers) return headers;
405
405
  return new Headers(headers);
406
406
  }
407
+ isWasmRequest(url) {
408
+ try {
409
+ return new URL(url).pathname.endsWith(".wasm");
410
+ } catch (_error) {
411
+ return url.split("?")[0].endsWith(".wasm");
412
+ }
413
+ }
407
414
  _generateProxyFetch() {
408
415
  const self = this;
409
416
  async function proxyFetch(req, options = {}) {
410
417
  const request = self.normalizeRequest(req);
411
418
  const winFetch = self.nativeFetch;
419
+ if (self.isWasmRequest(request.url)) return winFetch(req, options);
412
420
  const hooker = new FetchCycleScheduler;
413
421
  const sourceMap = {
414
422
  method: "default",
package/dist/esm/index.js CHANGED
@@ -398,11 +398,19 @@ class FetchInterceptor {
398
398
  if (headers instanceof Headers) return headers;
399
399
  return new Headers(headers);
400
400
  }
401
+ isWasmRequest(url) {
402
+ try {
403
+ return new URL(url).pathname.endsWith(".wasm");
404
+ } catch (_error) {
405
+ return url.split("?")[0].endsWith(".wasm");
406
+ }
407
+ }
401
408
  _generateProxyFetch() {
402
409
  const self = this;
403
410
  async function proxyFetch(req, options = {}) {
404
411
  const request = self.normalizeRequest(req);
405
412
  const winFetch = self.nativeFetch;
413
+ if (self.isWasmRequest(request.url)) return winFetch(req, options);
406
414
  const hooker = new FetchCycleScheduler;
407
415
  const sourceMap = {
408
416
  method: "default",
@@ -389,11 +389,19 @@ var AjaxHooker = function(exports) {
389
389
  if (headers instanceof Headers) return headers;
390
390
  return new Headers(headers);
391
391
  }
392
+ isWasmRequest(url) {
393
+ try {
394
+ return new URL(url).pathname.endsWith(".wasm");
395
+ } catch (_error) {
396
+ return url.split("?")[0].endsWith(".wasm");
397
+ }
398
+ }
392
399
  _generateProxyFetch() {
393
400
  const self = this;
394
401
  async function proxyFetch(req, options = {}) {
395
402
  const request = self.normalizeRequest(req);
396
403
  const winFetch = self.nativeFetch;
404
+ if (self.isWasmRequest(request.url)) return winFetch(req, options);
397
405
  const hooker = new FetchCycleScheduler;
398
406
  const sourceMap = {
399
407
  method: "default",
@@ -15,5 +15,6 @@ export declare class FetchInterceptor {
15
15
  private resolveRequest;
16
16
  private resolveOptions;
17
17
  private resolveHeaders;
18
+ private isWasmRequest;
18
19
  private _generateProxyFetch;
19
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ajax-hooker",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
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",