Add launchPersistentContext() to avoid incognito detection
Enchace idea
Currently launch() and launchContext() both use browser.launch() + browser.newContext(), which always creates incognito/ephemeral contexts. This is detected by multiple anti-bot services:
- BrowserScan flags it as "Incognito mode: Yes" with a -10% penalty
- FingerprintJS can distinguish incognito from normal sessions via storage API behavior
- CreepJS checks FileSystem API availability which differs in incognito
This undermines the stealth that CloakBrowser's 26 C++ patches provide. A browser can have perfect canvas, WebGL, audio, and font fingerprints — but if it's detected as incognito, it's immediately suspicious. Real users rarely browse in incognito, especially when creating accounts or making purchases.
The root cause: Playwright's browser.newContext() creates isolated BrowserContexts that behave identically to incognito mode — no persistent storage, no cookies from previous sessions, limited FileSystem API access. The only way to get a non-incognito context in Playwright is chromium.launchPersistentContext() with a userDataDir.
Current workaround
Since CloakBrowser doesn't export a persistent context launcher, we import internal modules directly and wire them into Playwright's native chromium.launchPersistentContext(). Full working example (JS):
import { chromium } from 'playwright-core';
import path from 'path';
import { fileURLToPath } from 'url';
const { resolveProxyGeo } = await import('file:///path/to/node_modules/cloakbrowser/dist/geoip.js');
const { parseProxyUrl } = await import('file:///path/to/node_modules/cloakbrowser/dist/proxy.js');
const { getDefaultStealthArgs } = await import('file:///path/to/node_modules/cloakbrowser/dist/config.js');
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const profileDir = path.join(__dirname, 'chrome-profile');
const binary = binaryInfo().binaryPath;
const proxyStr = 'http://user:pass@host:port';
const { timezone, locale } = await resolveProxyGeo(proxyStr);
const stealthArgs = getDefaultStealthArgs();
const proxyParsed = parseProxyUrl(proxyStr);
const context = await chromium.launchPersistentContext(profileDir, {
executablePath: binary,
headless: false,
viewport: { width: 1920, height: 1080 },
timezoneId: timezone,
locale: locale,
ignoreDefaultArgs: ['--enable-automation'],
args: stealthArgs,
proxy: proxyParsed,
});
const page = context.pages()[0] || await context.newPage();
await page.goto('https://browserscan.net/');
// BrowserScan now shows: Incognito mode: No
This works, but has problems: relies on internal module paths (dist/geoip.js, dist/config.js, dist/proxy.js) not part of the public API; requires file:// URL imports because the modules are ESM but not listed in package.json exports; users must manually find the binary path; could break on any update; not documented.
Proposed API
A new exported function wrapping Playwright's chromium.launchPersistentContext() with the same stealth defaults, geoip resolution, and proxy handling that launch() already provides.
JavaScript:
import { launchPersistentContext } from 'cloakbrowser';
const context = await launchPersistentContext({
userDataDir: './chrome-profile',
headless: false,
proxy: 'http://user:pass@host:port',
geoip: true,
viewport: { width: 1920, height: 1080 },
});
const page = context.pages()[0] || await context.newPage();
await page.goto('https://example.com');
await context.close();
Python:
from cloakbrowser import launch_persistent_context
context = launch_persistent_context(
user_data_dir="./chrome-profile",
headless=False,
proxy="http://user:pass@host:port",
geoip=True,
)
page = context.pages[0] if context.pages else context.new_page()
page.goto("https://example.com")
context.close()
The function should: auto-download/locate the stealth binary, apply default stealth args, support geoip: true for auto timezone/locale, parse proxy URL strings, set ignoreDefaultArgs: ['--enable-automation'], and accept all standard Playwright launchPersistentContext options as passthrough.
Test results: launch() vs persistent context workaround
| Check | launch() | Persistent context |
|---|---|---|
| BrowserScan Incognito | Yes (-10%) | No |
| Cookies persist across restarts | No | Yes |
| localStorage persist | No | Yes |
| reCAPTCHA v3 returning visitor bonus | No | Yes |
Benefits
- Eliminates incognito detection — BrowserScan shows "Incognito mode: No", removing -10% penalty
- Session persistence — cookies, localStorage, IndexedDB survive between launches
- Combined with --fingerprint=seed, creates realistic returning visitor sessions
- Drop-in simplicity — same pattern as launch() and launchContext()
- Users don't need to import undocumented internal dist/ modules
Environment
- cloakbrowser: 0.3.4 (JS wrapper)
- Chromium binary: 145.0.7632.109.2
- OS: Windows 11 x64
- Node.js: 18.20.4
- playwright-core: latest
Great writeup — the incognito detection analysis is solid, and your test results confirm the impact.
This is already in progress. @yahooguntu has an open PR (#17) adding launch_persistent_context() for Python, should be merged soon. JS support will follow after that lands.
Thanks for pushing for this.
https://github.com/CloakHQ/CloakBrowser/pull/22
If your interested in my way of doing it. It's ok if not :)
Shipped in v0.3.5. Both Python and JS now have first-class persistent context support:
JavaScript: launchPersistentContext() — PR #22
Python: launch_persistent_context() / launch_persistent_context_async() — PR #22
Thanks @evelaa123 for the thorough analysis and the PR!