Run Puppeteer with Tor

Viewed 7109

I installed the Tor Expert Bundle and I would like to run it with Puppeteer.

I try:

const browser = await puppeteer.launch({headless: false,args:['--proxy-server="socks5://127.0.0.1:9050"']});

But I get the error ERR_NO_SUPPORTED_PROXIES. I can run it with a normal Chrome browser.

3 Answers

There's an opened bug in chromium regarding more complex configurations for proxy in headless mode (Source). There has not been any activity since July 2017.

However, I've been able to run Puppeteer (1.3.0) with a headless chromium and SOCKS5 proxy configuration.

const browser = await puppeteer.launch({args: ['--proxy-server=socks5://127.0.0.1:1337']});

Try updating Puppeteer, which also updates the bundled Chromium, and run again. Also seems like you might have a typo: remove the " between socks5://127.0.0.1:9050.

Based on Running Puppeteer with Tor.

/**************************************************************************
 * IMPORTS
 ***************************************************************************/

const puppeteer = require('puppeteer')

/**************************************************************************
 * DEMOS > USING PUPPETEER BEHIND TOR
 * BASED ON https://medium.com/@jsilvax/running-puppeteer-with-tor-45cc449e5672
 ***************************************************************************/

;(async () => {
  const browser = await puppeteer.launch({
    args: ['--proxy-server=socks5://127.0.0.1:9050'],
    headless: false,
  })

  const page = await browser.newPage()
  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()
  }

  console.log('Using Tor. Continuing... ')

  // Now you can go wherever you want
  await page.goto('https://www.facebook.com/')

  // You would add additional code to do stuff...

  // Then when you're done, just close
  await browser.close()
})()
Related