dzmitry-duboyski / 2captcha-ts

JavaScript package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, Cloudflare turnstile, funcaptcha, geetest and solve any other captchas.
https://www.npmjs.com/package/2captcha-ts
MIT License
18 stars 4 forks source link

Use proxy to send request #13

Open fordca opened 8 months ago

fordca commented 8 months ago

Hi, thanks for this repo to use 2captcha conveniently.

I wonder if there is a way to config a proxy to use solver, because my code run behind a work NAT and can't connect to 2captcha.com directly I have been looked for the code and there is no proxy config for init solver.

Is there a way to solve my problem that I didn't found OR there is no proxy's config for now?

dzmitry-duboyski commented 8 months ago

@fordca at the moment, the proxy can be used along with the rest of the captcha parameters, as described here.

Example:

solver.recaptcha({
  pageurl: 'https://2captcha.com/demo/recaptcha-v2',
  googlekey: '6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u',
  proxy: "login:password@1.2.3.4:8888", // The (Username : Password @ Address : Port) of our chosen proxy
  proxytype: "http" // The 'Type' of proxy, http, https, socks4, socks5.
})
.then((res) => {
  console.log(res)
})
.catch((err) => {
  console.error(err.message)
})
kratzky commented 7 months ago

Is there a way to solve my problem that I didn't found OR there is no proxy's config for now?

2captcha-ts uses node-fetch that doesn't support proxies.

I think you can setup a proxy-agent in your project and it should be used by node-fetch for the API calls. Never tried by myself but it worth to try for your case.

wh1t3h47 commented 6 months ago

Hello Node fetch supports proxies (tested and it works) Although, yes, you need an external agent

For example:

import { SocksProxyAgent } from 'socks-proxy-agent';

const agent = new SocksProxyAgent('socks5h://127.0.0.1:9050');

await fetch('https://google.com', {
        agent,
        method: 'POST',
        body: {}
        headers,
      })
 }

I tested and it works, don't know about DNS leaks tho, but socks5h should have it resolving DNS in socks if the socks-proxy-agent works as supposed. I suggest using wireshark to check it.