how to open multiple instances of puppeteer without affecting the speed of the instances/network

Viewed 208

so am doing automation for some website which i want to open multiple(6-10) instances at the same time in that purpose am doing that using Worker threads but the thing is that the more instances i open the slower it get is that a normal or it can be fixed

and am using proxies each instance has it's own proxy the code :

  const browser = await puppeteer.launch({
    executablePath: "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
    headless: false,
    devtools: false,
    ignoreHTTPSErrors: true,
    ignoreDefaultArgs: "--enable-automation",

    args: [
      " --enable-automation",
      "--no-sandbox",
      "--ignore-certificate-errors",
      "--enable-features=NetworkService",
      "--allow-running-insecure-content",
      "--disable-web-security",
      `--window-size=${options.width},${options.height}`,
      "--proxy-server=" + Proxyy,
      // '--user-data-dir=C:\\Users\\USER\\AppData\\Local\\Google\\Chrome\\User Data'

    ],
  });
  const page = await browser.newPage();
  await page.setDefaultNavigationTimeout(0); 
  await page.authenticate({
    username: Puser,
    password: Ppass,
  });

really normal stuffs and the worker threads code

Multi_processing = (() => {
  return async () => {
    if (isMainThread) {

 
//? -------------------------------------------------------------------------- */
//?                                 Proxy input                                */
//? -------------------------------------------------------------------------- */
      let ProxyList = await prompt(" Input Proxy List ");
      Proxy_list = ProxyList.split("\r");
      console.log(`${Proxy_list.length} tasks has been started `.green.bold)
//! -------------------------------------------------------------------------- */
//!                           Starting MultiThreading                          */
//! -------------------------------------------------------------------------- */
      for (let i = 0; i < Proxy_list.length; i++) {        
          new Worker(__filename, {
          workerData: {
            Proxy_list: Proxy_list[i],
          
          },
        });
      }
    } else {
  
      /* -------------------------------------------------------------------------- */
      /*                               Proxie spliting                              */
      /* -------------------------------------------------------------------------- */
      parts = workerData.Proxy_list.split(":");
      if (parts.length == 4) {
        Aproxy = parts[0] + ":" + parts[1];
        pUser = parts[2];
        pPass = parts[3];
      }

      // console.log("Proxies : ".green + parts);
      console.log("Worker Of ID ".green + threadId);
      /* -------------------------------------------------------------------------- */
      /*                                Main Function                               */
      /* -------------------------------------------------------------------------- */
      try {
        MAIN(pUser, pPass, Aproxy,threadId);
      } catch (e) {
        console.log("Failed".red);
        console.log(e);
      }
    }
  };
})();
0 Answers
Related