Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use setWorkingFolder along with userDataDir on multiple instances #67

Open
viniciuspatzer opened this issue Dec 16, 2023 · 0 comments

Comments

@viniciuspatzer
Copy link

viniciuspatzer commented Dec 16, 2023

The code executes just fine when launching the first instance, the error seems to occur with subsequent instances, and also does not happen 100% of the time but appears to occur in the majority of cases. When I comment out the setWorkingFolder line or the userDataDir one, the code executes without this error.

Error: Failed to launch the browser process!

TROUBLESHOOTING: https://pptr.dev/troubleshooting

    at Interface.onClose (C:\Users\Administrator\Desktop\test-bot\node_modules\@puppeteer\browsers\lib\cjs\launch.js:262:24)
    at Interface.emit (node:events:525:35)
    at Interface.close (node:internal/readline/interface:533:10)
    at Socket.onend (node:internal/readline/interface:259:10)
    at Socket.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
import path from 'path';
import PQueue from 'p-queue';
import { plugin } from 'puppeteer-with-fingerprints';

const queue = new PQueue({ concurrency: 5 });
const launchQueue = new PQueue({ concurrency: 1 });

async function launchPuppeteer(instanceId) {
  plugin.setWorkingFolder(`./engines/instance_${instanceId}`);

  const fingerprint = await plugin.fetch('', {
    tags: ['Microsoft Windows', 'Chrome'],
  });

  plugin.useFingerprint(fingerprint);

  const browser = await plugin.launch({
    headless: false,
    userDataDir: path.resolve(`./sessions/${instanceId}`),
  });

  const page = await browser.newPage();

  return { browser, page };
}

(async () => {
  const instancesIds = ['1', '2', '3', '4', '5'];

  instancesIds.forEach((instancesId) => {
    queue.add(async () => {
      const { browser, page } = await launchQueue.add(() => launchPuppeteer(instancesId));

      await page.goto('https://browserleaks.com/');

      await new Promise((resolve) => browser.on('disconnected', resolve));
    });
  });
})();
@viniciuspatzer viniciuspatzer changed the title Can't use setWorkingFolder along with userDataDir Can't use setWorkingFolder along with userDataDir on multiple instances Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant