-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstealth-launcher.js
More file actions
59 lines (48 loc) · 2.19 KB
/
Copy pathstealth-launcher.js
File metadata and controls
59 lines (48 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
// Launches Brave with playwright-extra stealth plugin and exposes a CDP endpoint.
// .NET connects to it via ConnectOverCDPAsync to run publisher code without bot detection.
//
// Usage: node stealth-launcher.js <cdpPort> [profilePath]
// profilePath: e.g. "C:\Users\...\Brave-Browser\User Data\Profile 1"
// If it ends in "Profile N" or "Default", splits into userDataDir + --profile-directory.
// Otherwise used directly as userDataDir (e.g. our own profiles/makerworld dir).
const { chromium } = require('playwright-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
chromium.use(StealthPlugin());
const path = require('path');
const cdpPort = parseInt(process.argv[2] || '9222', 10);
const profilePath = process.argv[3] || null;
(async () => {
const commonArgs = [
`--remote-debugging-port=${cdpPort}`,
'--disable-blink-features=AutomationControlled',
'--no-first-run',
'--no-default-browser-check',
];
const launchOptions = {
headless: false,
executablePath: 'C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe',
args: commonArgs,
};
let context;
if (profilePath) {
const profileName = path.basename(profilePath);
const isNamedProfile = /^Profile \d+$/i.test(profileName) || profileName === 'Default';
const userDataDir = isNamedProfile ? path.dirname(profilePath) : profilePath;
if (isNamedProfile) {
launchOptions.args = [...commonArgs, `--profile-directory=${profileName}`];
}
// Must use launchPersistentContext — playwright-extra blocks --user-data-dir as a launch arg
context = await chromium.launchPersistentContext(userDataDir, launchOptions);
} else {
const browser = await chromium.launch(launchOptions);
context = browser.contexts()[0] || await browser.newContext();
}
// Signal ready — .NET already knows the port
process.stdout.write(`READY:${cdpPort}\n`);
// Exit when the context/browser closes
context.on('close', () => process.exit(0));
})().catch(err => {
process.stderr.write(`stealth-launcher error: ${err.message}\n`);
process.exit(1);
});