antibotbrowser / puppeteer + change IP by Tor

I’m currently working on a Puppeteer-based script where I want to use Tor to rotate IP addresses dynamically. The code works when I manually set up Tor for simple Puppeteer instances, but I’m having issues integrating it into my full program, which includes puppeteer-extra, puppeteer-extra-plugin-stealth, and antibotbrowser.

My goal is to automatically switch IP addresses using Tor or another proxy service every time a new page is loaded, or after a specific task is completed (like processing a set of links). I’ve implemented a function that randomly selects a Tor port and sets the proxy server for Puppeteer, but the IP address does not seem to change as expected in the context of the full program.

Here’s the relevant portion of my code:

const antibotbrowser = require("antibotbrowser");
const puppeteer = require('puppeteer-extra');
const puppeteerExtraPluginStealth = require('puppeteer-extra-plugin-stealth');
const ac = require('@antiadmin/anticaptchaofficial');...

ac.setAPIKey('afdfdbdf89489fbd4bfd');
const ipLogFile = 'ip_log.txt';
 
async function switchTorCircuit() {
  
  const socksPorts = [9050, 9052, 9053, 9054];
  
  const socksPort = socksPorts[Math.floor(Math.random() * socksPorts.length)];  
  return `socks5://127.0.0.1:${socksPort}`;
}

async function createBrowserWithTorAndAntibot() {  
  
  const proxyServer = await switchTorCircuit();
  
  puppeteer.use(puppeteerExtraPluginStealth());
  const antibrowser = await antibotbrowser.startbrowser();

  const browser = await puppeteer.connect({
    browserWSEndpoint: antibrowser.websokcet,
    args: [
      `--proxy-server=${proxyServer}`,  // Use the selected SOCKS proxy
      '--disable-features=site-per-process',
      '--no-sandbox',
      '--disable-setuid-sandbox',
    ],
    headless: false,
  });

  const page = await browser.newPage();

   // check ip ...
  
  return { browser, page };
}


(async () => {  
  const { browser, page } = await createBrowserWithTorAndAntibot();   

  await page.goto('https://www.xxx');  
  await processPage(page);
...
})();

torrc:
`
SocksPort 9050
SocksPort 9052
SocksPort 9053
SocksPort 9054

MaxCircuitDirtiness 10
NewCircuitPeriod 15

ControlPort 9051
CookieAuthentication 1`

Now I can’t change IP at all.

The API key doesn’t fit 🙂