To launch or connect to a browser, pass any playwright / browsernode configuration arguments you want to
BrowserSession(...)
:
The new
BrowserSession
& BrowserProfile
accept all the same arguments that Playwright’s launchPersistentContext(...)
takes, giving you full control over browser settings at launch. (see below for the full list)BrowserSession
BrowserSession()
is browsernode’s object that tracks a connection to a running browser. It sets up:- the
playwright
,browser
,browserContext
, andpage
objects and tracks which tabs the agent/human are focused on - methods to interact with the browser window, apply config needed by the Agent, and run the
DOMService
for element detection - it can take a
browserProfile=BrowserProfile(...)
template containing some config defaults,session-specific config overrides
- the
Browser Connection Parameters
Provide any one of these options to connect to an existing browser. These options are session-specific and cannot be stored in aBrowserProfile(...)
template.
wssUrl
cdpUrl
http://localhost:9222
). See here for CDP connection instructions.
browserPid
For web scraping tasks on sites that restrict automated access, we recommend
using our cloud or an external browser provider for better reliability.
See the Connect to your Browser guide for detailed connection instructions.
Session-Specific Parameters
browserProfile
BrowserProfile
template containing default config to use for the BrowserSession
. (see below for more info)
playwright
(import { chromium as PlaywrightChromium } from "playwright"; PlaywrightChromium)
or ( import { chromium as PatchrightChromium } from "patchright"; PatchrightChromium)
, which spawns a node.js child subprocess that relays commands to the browser over CDP.
See here for more detailed usage instructions.
browser
browserContext
page
aka agentCurrentPage
page=...
as a shortcut. See here for more detailed usage instructions.
humanCurrentPage
initialized
params
BrowserSession
can also accept all of the parameters below.
(the parameters above this point are specific to BrowserSession
and cannot be stored in a BrowserProfile
template)
Extra {...params}
passed to BrowserSession(...)
act as session-specific overrides to the BrowserProfile(...)
template.
BrowserProfile
A BrowserProfile
is a 📋 config template for a 🎭 BrowserSession(...)
.
It’s basically just a typed + validated version of a dict
to hold config.
When you find yourself storing or re-using many browser configs, you can upgrade from:
You don’t ever need to use a
BrowserProfile
, you can always pass config parameters directly to BrowserSession
:BrowserProfile
is optional, but it provides a number of benefits over a normal Record<string, unknown>
for holding config:
- has type hints and pydantic field descriptions that show up in your IDE
- validates config at runtime quickly without having to start a browser
- provides helper methods to autodetect screen size, set up local paths, save/load config as json, and more…
BrowserProfiles
s are designed to easily be given 🆔 uuid
s and put in a database + made editable by users.
BrowserSession
s get their own 🆔 uuid
s and be linked by 🖇 foreign key to whatever BrowserProfiles
they use.This cleanly separates the per-connection rows from the bulky re-usable config and avoids wasting space in your db.
This is useful because a user may only have 2 or 3 profiles, but they could have 100k+ sessions within a few months.BrowserProfile
and BrowserSession
can both take any of the:
- Playwright parameters
- browsernode parameters (extra options we provide on top of
playwright
)
BrowserProfile
can NOT take are the session-specific connection parameters and live playwright objects:
cdpUrl
, wssUrl
, browserPid
, page
, browser
, browserContext
, playwright
, etc.
Basic Example
browsernode Parameters
These parameters control browsernode-specific features, and are outside the standard playwright set. They can be passed toBrowserSession(...)
and/or stored in a BrowserProfile
template.
keepAlive
True
it wont close the browser after the first agent.run()
ends. Useful for running multiple tasks with the same browser instance. If this is left as null
and the Agent launched its own browser, the default is to close the browser after the agent completes. If the agent connected to an existing browser then it will leave it open.
stealth
True
to use patchright
to avoid bot-blocking. (Might cause issues with some sites, requires manual testing.)
allowedDomains
['google.com', '*.wikipedia.org']
- Here the agent will only be able to access google.com
exactly and wikipedia.org
+ *.wikipedia.org
.
Glob patterns are supported:
['example.com']
✅ will match onlyhttps://example.com/*
exactly, subdomains will not be allowed. It’s always the most secure to list all the domains you want to give the access to explicitly w/ schemes e.g.['https://google.com', 'http*://www.google.com', 'https://myaccount.google.com', 'https://mail.google.com', 'https://docs.google.com']
['*.example.com']
⚠️ CAUTION this will matchhttps://example.com
and all its subdomains. Make sure all the subdomains are safe for the agent!abc.example.com
,def.example.com
, …,useruploads.example.com
,admin.example.com
disableSecurity
⚠️ Setting this to
It completely disables all basic browser security features.
True
is NOT RECOMMENDED.It completely disables all basic browser security features.
bypassCsp=True
instead.
deterministicRendering
⚠️ Setting this to
It can be glitchy & slow, and it increases chances of getting blocked by anti-bot systems. It’s mostly useful for QA applications.
True
is NOT RECOMMENDED.It can be glitchy & slow, and it increases chances of getting blocked by anti-bot systems. It’s mostly useful for QA applications.
--deterministic-mode
--js-flags=--random-seed=1157259159
--force-color-profile=srgb
--font-render-hinting=null
--force-device-scale-factor=2
--enable-webgl
highlightElements
viewportExpansion
-1
: All elements from the entire page will be included, regardless of visibility (highest token usage but most complete).0
: Only elements which are currently visible in the viewport will be included.500
(default): Elements in the viewport plus an additional 500 pixels in each direction will be included, providing a balance between context and token usage.
includeDynamicAttributes
minimumWaitPageLoadTime
waitForNetworkIdlePageLoadTime
maximumWaitPageLoadTime
waitBetweenActions
cookiesFile
This option is DEPRECATED. Use
⬇️
storageState
instead, it’s the standard playwright format and also supports localStorage
and indexedDB
!The library will automatically save a new storageState.json
next to any cookiesFile
path you provide, just use `storageState=‘path/to/storageState.json’ to switch to the new format:cookiesFile.json
: [{cookie}, {cookie}, {cookie}]
⬇️
storage_state.json
: {"cookies": [{cookie}, {cookie}, {cookie}], "origins": {... optional localstorage state ...}}
Or run playwright open https://example.com/ --save-storage=storage_state.json
and log into any sites you need to generate a fresh storage state file.profileDirectory
userDataDir
(e.g. Default
, Profile 1
, Work
, etc.).
No need to set this unless you have multiple profiles set up in a single userDataDir
and need to use a specific one.
windowPosition
saveRecordingPath
tracePath
{tracePath}/{contextId}.zip
.
Playwright Launch Options
All the parameters below are standard playwright parameters and can be passed to bothBrowserSession
and BrowserProfile
.
They are defined in browsernode/browser/profile.ts
. See here for the official Playwright documentation for all of these options.
headless
headless=False
on a server with no monitor attached, the browser will fail to launch (use xvfb
+ vnc to give a headless server a virtual display you can remote control).
headless=False
is recommended for maximum stealth and is required for human-in-the-loop workflows.
channel
['chromium']
(default when stealth=False
), 'chrome'
(default when stealth=True
), 'chrome-beta'
, 'chrome-dev'
, 'chrome-canary'
, 'msedge'
, 'msedge-beta'
, 'msedge-dev'
, 'msedge-canary'
Don’t worry, other chromium-based browsers not in this list (e.g. brave
) are still supported if you provide your own executablePath
, just set it to chromium
for those.
executablePath
userDataDir
null
to use an ephemeral temporary profile (aka incognito mode).
Multiple running browsers cannot share a single userDataDir
at the same time. You must set it to null
or
provide a unique userDataDir
per-session if you plan to run multiple browsers.
The browser version run must always be equal to or greater than the version used to create the userDataDir
.
If you see errors like Failed to parse Extensions
or similar and failures when launching, you’re attempting to run an older browser with an incompatible userDataDir
that’s already been migrated to a newer schema version.
args
ignoreDefaultArgs
True
to disable all default options (not recommended).
env
{'DISPLAY': '1'}
to use a specific X11 display.
chromiumSandbox
False
when running inside Docker
because Docker provides its own sandboxing can conflict with Chrome’s.
devtools
headless=False
).
slowMo
timeout
acceptDownloads
proxy
{"server": "http://proxy.com:8080", "username": "user", "password": "pass"}
.
permissions
storageState
storageState
documentation on how to use it.
This option is only applied when launching a new browser using the default builtin playwright chromium and userDataDir=null
is set.
Playwright Timing Settings
These control how the browser waits for CDP API calls to complete and pages to load.defaultTimeout
10000
if you want 10s).
defaultNavigationTimeout
30000
if you want 30s).
Playwright Viewport Options
Configure browser window size, viewport, and display properties:userAgent
playwright.devices
.
isMobile
hasTouch
geolocation
{"latitude": 59.95, "longitude": 30.31667}
locale
en-GB
, de-DE
, etc. Locale will affect the navigator.language
value, Accept-Language
request header value as well as number and date formatting rules.
timezoneId
'America/New_York'
or 'UTC'
).
windowSize
{"width": 1920, "height": 1080}
viewport
width
and height
. Example: {"width": 1280, "height": 720}
noViewport
viewport
setting above.
A viewport is always used in headless mode regardless of this setting, and is never used in headful mode unless you pass viewport={width, height}
explicitly.
deviceScaleFactor
screen
colorScheme
'light'
, 'dark'
, 'no-preference'
contrast
'no-preference'
, 'more'
, 'null'
reducedMotion
'reduce'
, 'no-preference'
, 'null'
forcedColors
'active'
, 'null'
Playwright Security Options
See allowedDomains
above too!
offline
httpCredentials
extraHTTPHeaders
ignoreHTTPSErrors
bypassCSP
Enabling this can increase security risk and makes the bot very easy to fingerprint. (Cloudflare, Datadome, etc. will block you)
javaScriptEnabled
Not recommended, untested with browsernode and likely breaks things.
serviceWorkers
'allow'
, 'block'
baseURL
page.goto()
and similar operations.
strictSelectors
clientCertificates
Playwright Recording Options
Note: browsernode also provides some of our own recording-related options not listed below (see above).recordVideoDir
.webm
video recordings. Playwright Docs: recordVideoDir
This parameter also has an alias
saveRecordingPath
for backwards compatibility with past versions, but we recommend using the standard Playwright name recordVideoDir
going forward.recordVideoSize
{"width": 1280, "height": 720}
recordHarPath
.har
network trace files. Playwright Docs: recordHarPath
This parameter also has an alias
saveHarPath
for backwards compatibility with past versions, but we recommend using the standard Playwright name recordHarPath
going forward.recordHarContent
'omit'
, 'embed'
, 'attach'
recordHarMode
'full'
, 'minimal'
recordHarOmitContent
recordHarUrlFilter
downloadsPath
downloadsDir
, saveDownloadsPath
)
Local filesystem directory to save browser file downloads to.
tracesDir
{tracesDir}/{contextId}.zip
. Playwright Docs: tracesDir
This parameter also has an alias
tracePath
for backwards compatibility with past versions, but we recommend using the standard Playwright name tracesDir
going forward.handleSIGHUP
handleSIGINT
handleSIGTERM
Full Example
Summary
- BrowserSession (defined in
browsernode/src/browser/session.ts
) handles the live browser connection and runtime state - BrowserProfile (defined in
browsernode/src/browser/profile.ts
) is a template that can store default config parameters for aBrowserSession(...)
BrowserConnectArgs
- args forBrowserType.connect(...)
BrowserLaunchArgs
- args forBrowserType.launch(...)
BrowserNewContextArgs
- args forBrowserType.newContext(...)
BrowserLaunchPersistentContextArgs
- args forBrowserType.launchPersistentContext(...)
- browsernode’s own internal methods