Closed Wizzzz closed 1 month ago
I was able to run two browsers within the same process using most of your code, but with some caveats:
import { BrowserInstance } from './browser';
async function main() {
const commonOptions = {
headless: false,
creationTimeout: 90000 * 10,
fingerprintSwitcherKey: 'FINGERPRINT_KEY',
};
const instance1 = new BrowserInstance({
browserOptions: {
...commonOptions,
profilePath: './testProfile1',
},
});
const instance2 = new BrowserInstance({
browserOptions: {
...commonOptions,
profilePath: './testProfile2',
},
});
await Promise.allSettled([instance1.init(), instance2.init()]);
}
main();
isBrowserCreated
, you need to significantly increase it, because the engine may take much longer to download and decompress completely, otherwise errors are possible.launchPersistentContext
usage, where the timeout was doubled.bas-remote-node
package - I will definitely fix it in future updates, while you can patch it yourself. Right before this line, you need to add the following:if (!fs.existsSync(this._scriptDir)) return;
With this in mind, your code worked for me without errors and launched two browsers, although I had to remove the import of some types and the use of extensions. If all this does not fix the problem, please send me the complete project with all types and data to repeat by email cheshirecat902@gmail.com. Or you can make a private repository and invite me, as it will be more convenient for you - I will look at it in my free time and try to identify the problem if it remains.
The problem is not at launch after several minutes, I would make a repo during the day that stimulates tasks to show my problem, thank for response
The problem is not at launch after several minutes, I would make a repo during the day that stimulates tasks to show my problem, thank for response
Hey bro, add me on discord -- so we can properly discuss this
@CheshireCaat I've just thought about it, in view of the way I manage engines, wouldn't it be possible in my case to modify your code so that it doesn't lock the file?
Added @dr3adx
@Wizzzz you can try, at least for the bas-remote
and for the browser-with-fingerprints
. But it can lead to other issues, so in such case i can't help.
@CheshireCaat okok I won't hide the fact that this is my last solution, as I would have tried everything else.
I invited you to my repo where I manage my browser and sent an email with details, if you have time to look at my email which is very serious!
Hi, I'm back to give you an update on my last message.
Since I deactivated the lock on the package, I have no more lock problems. It's been 4 days now that I have no problems.
Here's the link to the modified package for those interested. You'll have to import it with npm using the github link, as I haven't posted it on npm. https://github.com/Wizzzz/playwright-with-fingerprints-without-lock
If you want to reproduce my code, you have 2 choices, either download FastExecuteScriptProtected.x64, put it on your desktop and build a folder with your node in the same way as the package, all you have to do is 'setWorkingFolder' and the package will take care of the rest.
The second, faster option is to first extract FastExecuteScriptProtected.zip and build the folder yourself, then copy the folder for each instance you make.
You'll also need to create a powershell script that automatically deletes the folders you've created, because in less than 2 hours you're likely to run out of space on your machine (in my case, I've got 1to).
@CheshireCaat On the other hand, I'm facing a problem I've had before, and I don't really know how to solve it. Sometimes, when I launch the browser, it never launches, and what's more, it completely blocks my node, making it impossible to continue except by shutting it down and relaunching manually. I do use 'setRequestTimeout', though, and I've even made a home-made timeout with promise.race
await Promise.race([ sleep(MAX_LAUNCH_TIMEOUT).then(() => { if (!isLaunch) throw '[BROWSER INSTANCE] Timeout during launch'; }), new Promise((resolve, reject) => { plugin .launchPersistentContext(this.instanceOptions.browserOptions.profilePath, { headless: this.instanceOptions.browserOptions.headless, args }) .then((browser: BrowserContext) => { isLaunch = true; this.browser = browser; resolve(browser); }) .catch((error: any) => { reject(error); throw error; }); })
If anyone has an idea for solving this problem, I'd be very happy to hear it, as it's currently my last problem with the package
@CheshireCaat Hi, sorry for the message, but I'd like to ask you again about the problem with the browser that never launches. Unfortunately it's totally blocking my node and I have to restart it manually.
This is my latest problem with the package
@Wizzzz hi, please check your email, I replied to your message there.
@CheshireCaat
Hello, I would like to open a new issue to know if there is an example on the Lock error when you are in multi-thraeds, I have tried everything and I can not make sure not to have the error.
I'm attaching my code but I really don't see how it's possible that I still get the error.
To put it simply, in my current code I've generated a brand new engine in a folder, and as soon as I create a browser, I copy the engine and use it with setWorkingFolder
When I run just one task (say a scrapper on site A), I don't have any problems, but if I run my second scrapper on site B, after a few minutes I'll get the error.
Is there really a way to launch several scrappers with the package?
I can't hide the fact that I've been working full-time on this for 4 days now and I'm really starting to lose patience because it's putting me behind on all my projects :(
I can pay for durable solution if someone have
` import { FetchOptions } from 'browser-with-fingerprints'; import crypto from 'crypto'; import fs from 'fs'; import { createCursor } from 'ghost-cursor-playwright'; import { homedir } from 'os'; import path from 'path'; import { BrowserContext } from 'playwright-core'; import { plugin } from 'playwright-with-fingerprints';
import { Logger } from '../../logger'; import { Proxy } from '../../proxy'; import { BrowserOptions } from '../../types/browser'; import { capsolverDefaultConfig, CapsolverOptions } from '../../types/capsolver'; import { nopechaDefaultConfig, NopechaOptions } from '../../types/nopecha'; import { sleep } from '../../utils'; import { humanClick, humaneMove, humanType } from '../humanize';
type InstanceOptions = { browserOptions: BrowserOptions; capsolverOptions?: CapsolverOptions; nopechaOptions?: NopechaOptions; proxy?: Proxy; taskDuration?: number; };
type PageOptions = { useHumanization?: boolean; blockImageDomains?: string[]; };
export class BrowserInstance { private browser: BrowserContext | null = null; readonly instanceOptions: InstanceOptions;
}
`