ProxymanApp / Proxyman

Modern. Native. Delightful Web Debugging Proxy for macOS, iOS, and Android ⚡️
https://proxyman.io
5.41k stars 178 forks source link

Support capturing traffic when using ofetch #1797

Open TimvdEijnden opened 9 months ago

TimvdEijnden commented 9 months ago

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)
NghiaTranUIT commented 9 months ago

@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

TimvdEijnden commented 9 months ago

Yes I also tried the automatic setup, same issue

NghiaTranUIT commented 9 months ago

@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); })();


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
TimvdEijnden commented 9 months ago

@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.

reslear commented 2 months ago

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)
TimvdEijnden commented 2 months ago

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

danielroe commented 2 months ago

@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. 🙏

reslear commented 2 months ago

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