0

I'm on a Windows 10 machine, I've downloaded the Tor browser and using the Tor browser normally works fine, but I'd like to make Puppeteer use Tor to launch in a headless mode, I'm seeing a lot regarding the Socks5 proxy but can't figure out how to set this up and why it's not working? Presumably when running the launch method it launches Tor in the background?

Here's my JS code in node so far...

// puppeteer-extra is a drop-in replacement for puppeteer,
// it augments the installed puppeteer with plugin functionality
const puppeteer = require('puppeteer-extra')

// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())

// artificial sleep function
const sleep = async (ms) => {
  return new Promise((res, rej) => {
    setTimeout(() => {
      res()
    }, ms)
  })
}

// login function
const emulate = async () => {

  // initiate a Puppeteer instance with options and launch
  const browser = await puppeteer.launch({
    headless: false,
    args: [
      '--proxy-server=socks5://127.0.0.1:1337'
    ]
  });

  // launch Facebook and wait until idle
  const page = await browser.newPage()

  // go to Tor
  await page.goto('https://check.torproject.org/');

  const isUsingTor = await page.$eval('body', el =>
     el.innerHTML.includes('Congratulations. This browser is configured to use Tor')
    );

    if (!isUsingTor) {
        console.log('Not using Tor. Closing...')
        return await browser.close()
    }


  // do something...

}

// kick it off
emulate()

This gives me a ERR_PROXY_CONNECTION_FAILED error in chromium, why isn't it launching using Tor?

Ryan H
  • 2,620
  • 4
  • 37
  • 109
  • From [the home page for Puppeteer](https://developers.google.com/web/tools/puppeteer/): "Puppeteer is a Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium." Nothing about Tor browser. Nothing about any browser other than Chrome or Chromium... Not sure what you were looking for. See also [Can I use this for other browsers? #1667](https://github.com/puppeteer/puppeteer/issues/1667) – Heretic Monkey Feb 16 '22 at 20:56
  • Something like `--proxy-server=socks5://127.0.0.1:1337` is what I'm trying to achieve, I've seen some people using this online, but it doesn't work for me. – Ryan H Feb 16 '22 at 21:05
  • Just to correct some misinformation, puppeteer can actually be used with non-Chrome browsers, namely Firefox. See the more recent thread [how do you install and run puppeteer for firefox](https://stackoverflow.com/questions/63212435/how-do-you-install-and-run-puppeteer-for-firefox). I don't see anything about TOR support though. – Skyler Ferris Jan 22 '23 at 17:43

1 Answers1

1

There are lot more steps you need to take.

  1. You need to install tor on your system. You might want to use- brew install tor
  2. Start tor with- brew services start tor
  3. tor use port 9050 by default, so your proxy should look like this; --proxy-server=socks5://127.0.0.1:9050 If you must use another port, then it must be added in the torrc file. Also, you might need to do your //go to tor// before your //launch facebook//