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

Run parallel browsers from one node process #22

Open
ClassAxion opened this issue Jun 28, 2023 · 9 comments
Open

Run parallel browsers from one node process #22

ClassAxion opened this issue Jun 28, 2023 · 9 comments

Comments

@ClassAxion
Copy link

Does this package support for run multiple browsers at once? Like 10-50 parallel browsers from the same node process?

I'm trying but browsers starting very very long or even timeout at 300s and freezes.

How to do this correctly? I'm using plugin.launch with headless: 'new' and useFingerprint for launching browsers

@CheshireCaat
Copy link
Owner

CheshireCaat commented Jul 2, 2023

At this point in time, the launch of browsers is synchronized, but after that you can work with them in parallel in any way.

Parallel unsynchronized launch isn't yet supported due to some limitations - we may fix this in the future, so we'll leave the ticket open for now.

Launching the browser takes longer than default one, as it requires additional configuration and the presence of an engine that is downloaded once. If a timeout error occurs, you can change the default timeout to any value you like via the FINGERPRINT_TIMEOUT environment variable.

If you're having trouble launching multiple browsers and then working with them, or if I misunderstood you, please describe the problem in more detail and attach sample code.

@ClassAxion
Copy link
Author

So I should use some mutex for plugin.launch option and launch only one browser at a time? Then I can use page.goto etc. without any mutex, sync. etc?

As far as I understood correctly, the problem is that the browsers uses the same data directory and this causes a problem with unsynchronized launch of multiple browsers?

@ClassAxion
Copy link
Author

I just tested my code which didn't work with async-mutex putted on plugin.launch and it works fine. I think that this is the current workaround

@CheshireCaat
Copy link
Owner

I still don't understand what your problem is and why you need to use additional mutex inside launch. Here's an example straight from the repository demonstrating running multiple browsers:

require('dotenv').config();
const { plugin } = require('puppeteer-with-fingerprints');

async function main(index) {
  const browser = await plugin.launch();

  const page = await browser.newPage();
  await page.goto(`https://jsonplaceholder.typicode.com/todos/${index + 1}`, { waitUntil: 'domcontentloaded' });

  const todo = JSON.parse(await page.$eval('pre', (pre) => pre.innerText));

  await browser.close();
  return todo;
}

Promise.all([0, 1, 2].map(main)).then((todos) => {
  console.log({ todos });
});

I tested it many times and it worked. Try running it and let me know what specific problems you're having with it.

@ClassAxion
Copy link
Author

but this example doesn't use useFingerprint method, if you use useFingerprint then launch should freeze after some time (for example if you have 20+ workers that runs unsynchronised and restart the browser every 5 minutes)

@bablosoft
Copy link
Collaborator

@ClassAxion can you attach minimum runnable source code and what error do you get.

Please avoid using FingerprintSwitcher key in your code.

@emretulek
Copy link

Hello, I'm having the same problem.

project_folder -> index.js

export const index = async (plugin) => {
    const fingerprint = await plugin.fetch('key', {
        tags: ['Microsoft Windows', 'Chrome'],
    });
    log.yellow("STEP: fingerprints fetched");

    plugin.useProxy(proxy, {
        changeGeolocation: true,
    });

    log.white("STEP: proxy setted");

    plugin.useFingerprint(fingerprint);

    log.white("STEP: figerprint using");

    const browser = await plugin.launch({
        headless: isHeadless,
        // minBrowserVersion: 102,
        // minWidth: 1024,
        // minHeight: 768,
        // maxWidth: 1920,
        // maxHeight: 1080,
    });

    log.white("STEP: browser launched");
}

project_folder -> sub_folder1

import { plugin } from "puppeteer-with-fingerprints";
import {index} from "../index.js";

await index(plugin);

It is installed in the puppeteer-with-fingerprints subdirectory, so each browser is used from a different directory.
After a few hours the lunch method freezes. ctr + c doesn't work, console hangs. If I close other processes as well, the frozen console exits. Mostly the error does not appear.

At the same place, I sometimes encounter the following error.

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read'
}

Node.js v19.0.0

@CheshireCaat
Copy link
Owner

@emretulek I don't see any issues here, your code works fine for me - please, describe your problem in more details. Also keep in mind that you must close browsers properly whether you are using a plugin or not. Otherwise, it can lead to other problems, such as excessive consumption of resources, and the process can remain open, including because of this.

@emretulek
Copy link

emretulek commented Aug 4, 2023

@CheshireCaat When I open multiple browsers, the most noticeable problem is that processes freeze in relation to one another. For example, if 5 processes are started at the same time, and the 2nd process is frozen, it cannot be terminated even with ctr+c. But it freezes in conjunction with one of the processes 1 - 3 - 4 - 5. When 1-4-5 is closed, nothing changes, while 3 is turned off, 2 continues from where it left off. (It doesn't have to be 3, it can be any one specifically.)

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

4 participants