Ryan H
Ryan H

Reputation: 2953

Launch Tor browser using Puppeteer instead of Chrome on Windows 10

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?

Upvotes: 1

Views: 1259

Answers (1)

Dotun Showunmi
Dotun Showunmi

Reputation: 36

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//

Upvotes: 2

Related Questions