Getting Started with Playwright
Launch BotBrowser with Playwright using profile-first configuration and framework-specific cleanup.
Prerequisites
- BotBrowser installed. See Installation.
- Node.js 18+.
playwright-coreinstalled.- Profile file (
.encfor production).
Quick Start
npm init -y
npm install playwright-coreimport { chromium } from "playwright-core";
const browser = await chromium.launch({
executablePath: process.env.BOTBROWSER_EXEC_PATH,
headless: true,
args: [
`--bot-profile=${process.env.BOT_PROFILE_PATH}`,
"--proxy-server=socks5://user:pass@proxy.example.com:1080",
],
});
const page = await browser.newPage();
// Playwright-specific cleanup before first navigation
await page.addInitScript(() => {
delete window.__playwright__binding__;
delete window.__pwInitScripts;
});
await page.goto("https://example.com");
await browser.close();How It Works
Playwright integration has one key requirement in addition to normal BotBrowser launch:
- Launch with BotBrowser flags in
args(--bot-profile, optional--proxy-server). - Run
addInitScript()before first navigation to remove Playwright-injected bindings. - Keep profile-managed identity surfaces unchanged (no custom viewport overrides unless required).
For shared automation guidance (runtime consistency, bot-script fallback, troubleshooting baseline), see Automation Consistency.
Common Scenarios
Geo override with Playwright
const browser = await chromium.launch({
executablePath: process.env.BOTBROWSER_EXEC_PATH,
headless: true,
args: [
`--bot-profile=${process.env.BOT_PROFILE_PATH}`,
"--proxy-server=socks5://user:pass@proxy.example.com:1080",
"--bot-config-timezone=Europe/Berlin",
"--bot-config-locale=de-DE",
"--bot-config-languages=de-DE,de,en-US,en",
],
});Per-context fingerprint assignment
const browser = await chromium.launch({
executablePath: process.env.BOTBROWSER_EXEC_PATH,
headless: true,
args: [`--bot-profile=${process.env.BOT_PROFILE_PATH}`],
});
const client = await browser.newBrowserCDPSession();
// Snapshot existing context IDs
const { browserContextIds: before } = await client.send("Target.getBrowserContexts");
const context = await browser.newContext();
const { browserContextIds: after } = await client.send("Target.getBrowserContexts");
const contextId = after.filter(id => !before.includes(id))[0];
await client.send("BotBrowser.setBrowserContextFlags", {
browserContextId: contextId,
botbrowserFlags: [
"--bot-profile=/path/to/another.enc",
"--proxy-server=socks5://user:pass@proxy2.example.com:1080",
],
});Troubleshooting / FAQ
| Problem | Solution |
|---|---|
| Playwright bindings still visible | Ensure addInitScript() runs before first page.goto(). |
| Geo values do not match proxy | Pass proxy via args using --proxy-server, not framework proxy options. |
| Launch fails | Verify BOTBROWSER_EXEC_PATH points to BotBrowser binary and has execute permission. |
| Multiple instances conflict | Provide unique --user-data-dir per instance. |
Next Steps
- Automation Consistency
- Puppeteer Guide
- Proxy Geolocation Alignment
- Multi-Account Isolation
- CLI Flags Reference
Related documentation: Examples | Per-Context Fingerprint
Legal Disclaimer & Terms of Use • Responsible Use Guidelines . BotBrowser is for authorized fingerprint protection and privacy research only.