[GH-ISSUE #1797] Support capturing traffic when using ofetch #1790

Open
opened 2026-03-03 19:54:26 +03:00 by kerem · 8 comments
Owner

Originally created by @TimvdEijnden on GitHub (Oct 5, 2023).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1797

Originally assigned to: @NghiaTranUIT on GitHub.

Description

Currently https://github.com/unjs/ofetch is not supported, which is used by nuxt 3.

Why this feature/change is important?

Before we were using axios which was supported.

Now we're ending up with these errors and cannot override requests:

 ERROR  [unhandledRejection] socket hang up                        10:49:42 AM

  at connResetException (node:internal/errors:717:14)
  at Socket.socketOnEnd (node:_http_client:526:23)
  at Socket.emit (node:events:525:35)
  at Socket.emit (node:domain:489:12)
  at endReadableNT (node:internal/streams/readable:1359:12)
  at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Originally created by @TimvdEijnden on GitHub (Oct 5, 2023). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1797 Originally assigned to: @NghiaTranUIT on GitHub. ## Description Currently https://github.com/unjs/ofetch is not supported, which is used by nuxt 3. ## Why this feature/change is important? Before we were using axios which was supported. Now we're ending up with these errors and cannot override requests: ``` ERROR [unhandledRejection] socket hang up 10:49:42 AM at connResetException (node:internal/errors:717:14) at Socket.socketOnEnd (node:_http_client:526:23) at Socket.emit (node:events:525:35) at Socket.emit (node:domain:489:12) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) ```
Author
Owner

@NghiaTranUIT commented on GitHub (Oct 6, 2023):

@TimvdEijnden can you try using the Automatic Setup to start the pre-configured Terminal app, then starting your local backend here.

This Terminal has a lot of Global HTTP, and HTTPS env, so it might work with the ofetch out of the box. axios is already worked.

Docs: https://docs.proxyman.io/automatic-setup/automatic-setup

<!-- gh-comment-id:1749883402 --> @NghiaTranUIT commented on GitHub (Oct 6, 2023): @TimvdEijnden can you try using the Automatic Setup to start the pre-configured Terminal app, then starting your local backend here. This Terminal has a lot of Global HTTP, and HTTPS env, so it might work with the `ofetch` out of the box. `axios` is already worked. Docs: https://docs.proxyman.io/automatic-setup/automatic-setup
Author
Owner

@TimvdEijnden commented on GitHub (Oct 6, 2023):

Yes I also tried the automatic setup, same issue

<!-- gh-comment-id:1750125331 --> @TimvdEijnden commented on GitHub (Oct 6, 2023): Yes I also tried the automatic setup, same issue
Author
Owner

@NghiaTranUIT commented on GitHub (Oct 6, 2023):

@TimvdEijnden Can you show me your setup ?


I tested and Proxyman supports ofetch out of the box.

  1. Prepare this JS Code
const { ofetch } = require("ofetch");

// Call start
(async () => {
  const data = await ofetch("https://httpbin.proxyman.app/get?lib=ofetch");
  console.log(data);
})();

  1. Open Proxyman -> Automatic Setup -> Start new Terminal
  2. Run this script npm start
  3. Result:
  • Able to capture & decrypt HTTPS requests from ofetch

CleanShot 2023-10-06 at 16 34 02@2x

Video:

https://github.com/ProxymanApp/Proxyman/assets/5878421/10f8b384-5ba8-4fba-aca2-c5dfd52b99e0

<!-- gh-comment-id:1750291525 --> @NghiaTranUIT commented on GitHub (Oct 6, 2023): @TimvdEijnden Can you show me your setup ? ---------------------- I tested and Proxyman supports `ofetch` out of the box. 1. Prepare this JS Code ```js const { ofetch } = require("ofetch"); // Call start (async () => { const data = await ofetch("https://httpbin.proxyman.app/get?lib=ofetch"); console.log(data); })(); ``` 2. Open Proxyman -> Automatic Setup -> Start new Terminal 3. Run this script `npm start` 4. Result: - Able to capture & decrypt HTTPS requests from `ofetch` ![CleanShot 2023-10-06 at 16 34 02@2x](https://github.com/ProxymanApp/Proxyman/assets/5878421/f6a4c08b-28bd-46c9-bb45-b03ed63a745e) Video: https://github.com/ProxymanApp/Proxyman/assets/5878421/10f8b384-5ba8-4fba-aca2-c5dfd52b99e0
Author
Owner

@TimvdEijnden commented on GitHub (Oct 6, 2023):

@NghiaTranUIT wow 🤩 thanks for quickly diving into it! I'll create a test nuxt 3 project and try again. Might be related to nuxt 3 instead of ofetch then.

<!-- gh-comment-id:1750320372 --> @TimvdEijnden commented on GitHub (Oct 6, 2023): @NghiaTranUIT wow 🤩 thanks for quickly diving into it! I'll create a test nuxt 3 project and try again. Might be related to nuxt 3 instead of ofetch then.
Author
Owner

@reslear commented on GitHub (Apr 28, 2024):

yes, Nuxt have a problem:

 ERROR  [unhandledRejection] socket hang up                                                                                                                                                                   3:39:00 AM

  at Socket.socketOnEnd (node:_http_client:524:23)
  at Socket.emit (node:events:530:35)
  at Socket.emit (node:domain:488:12)
  at endReadableNT (node:internal/streams/readable:1696:12)
  at process.processTicksAndRejections (node:internal/process/task_queues:82:21) (repeated 3503 times)

<!-- gh-comment-id:2081282528 --> @reslear commented on GitHub (Apr 28, 2024): yes, Nuxt have a problem: ```bash ERROR [unhandledRejection] socket hang up 3:39:00 AM at Socket.socketOnEnd (node:_http_client:524:23) at Socket.emit (node:events:530:35) at Socket.emit (node:domain:488:12) at endReadableNT (node:internal/streams/readable:1696:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) (repeated 3503 times) ```
Author
Owner

@TimvdEijnden commented on GitHub (Apr 29, 2024):

Yes I also tried with nuxt 3 and it does not boot up just like @reslear mentions.
Screenshot 2024-04-26 at 15 32 03

@pi0 @danielroe Is there something I can do, I'm willing to dive into it and even make a PR if needed

<!-- gh-comment-id:2082034563 --> @TimvdEijnden commented on GitHub (Apr 29, 2024): Yes I also tried with nuxt 3 and it does not boot up just like @reslear mentions. ![Screenshot 2024-04-26 at 15 32 03](https://github.com/ProxymanApp/Proxyman/assets/951290/638915dc-1d65-4af6-a383-ce4779cde87c) @pi0 @danielroe Is there something I can do, I'm willing to dive into it and even make a PR if needed
Author
Owner

@danielroe commented on GitHub (Apr 29, 2024):

@TimvdEijnden Not familiar with the problem here, so take this with a pinch of salt. If you're prepared to have a look, you might investigate the way we create a 'local fetch' with unenv. We mock internal network requests to avoid hitting the network layer.

Feel free to ping me if I can help with pointing you to the way fetch is architected, once you dig down deeper and start finding what's causing the error here. 🙏

<!-- gh-comment-id:2082135228 --> @danielroe commented on GitHub (Apr 29, 2024): @TimvdEijnden Not familiar with the problem here, so take this with a pinch of salt. If you're prepared to have a look, you might investigate the way we create a 'local fetch' with [unenv](https://github.com/unjs/unenv). We mock internal network requests to avoid hitting the network layer. Feel free to ping me if I can help with pointing you to the way fetch is architected, once you dig down deeper and start finding what's causing the error here. 🙏
Author
Owner
<!-- gh-comment-id:2087997825 --> @reslear commented on GitHub (May 1, 2024): also u found http serve: https://github.com/elk-zone/elk/blob/main/https-dev-config/local-https-server.mjs https://github.com/unjs/nitro/blob/aabdc9c5c78c011a212c754058160ed23391361d/src/runtime/entries/node-server.ts#L34
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#1790
No description provided.