CheshireCaat / browser-with-fingerprints

Anonymous automation with fingerprint replacement technology.
MIT License
111 stars 19 forks source link

[Suggestion] Use options as alternative to FINGERPRINT_CWD #11

Closed ClassAxion closed 1 year ago

ClassAxion commented 1 year ago

For now, we have to use cluster or worker_threads to use multiple browser with different FINGERPRINT_CWD. I think, that it will be easiest to use some argument to control the workingDir so we will be able to use multiple browsers with different FINGERPRINT_CWD in one NodeJS script so the RAM usage will be less. I don't know if this is possible but I initially checked and there should be no problems. Of course, FINGERPRINT_CWD may still be supported.

bablosoft commented 1 year ago

Yes, this will be implemented eventually.

ClassAxion commented 1 year ago

Can I know when approximately? Then I will know what to do next with my software

bablosoft commented 1 year ago

This is only for convenience, I belive, that you could set env variable directly from source now.

ClassAxion commented 1 year ago

I'm using worker_threads for now that have separate environment so I'm able to set different FINGERPRINT_CWD but that consumes more RAM

bablosoft commented 1 year ago

Have you tried to assign to process.env. Or you want to have different dir in one process?

ClassAxion commented 1 year ago

I need different workingDir in one process

ClassAxion commented 1 year ago

Workaround for now using decache pkg for puppeteer-with-fingerprints

import decache from "decache";

async function launch(workingDir: string) {
    process.env.FINGERPRINT_CWD = workingDir;

    decache("puppeteer-with-fingerprints");

    const { plugin } = require("puppeteer-with-fingerprints");

    const browser = await plugin.launch({
        headless: false,
    });

    const page = await browser.newPage();

    await page.goto("http://ip.bablosoft.com/");
}

(async () => {
    await Promise.all([
        launch("./data1"),
        launch("./data2"),
        launch("./data3"),
    ]);
})();
CheshireCaat commented 1 year ago

@ClassAxion now it's possible to use the setWorkingFolder method:

plugin.setWorkingFolder('./data1');
const browser1 = await plugin.launch({ headless: false });

plugin.setWorkingFolder('./data2');
const browser2 = await plugin.launch({ headless: false });

This is a replacement for similar settings via environment variables.

At the moment, consider the problem solved - if this is not the case or you have other questions, please, open a separate ticket.

Please note that your code above is not thread-safe, since one of the calls can override the path to the working folder, such code needs to be synchronized.