Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

use default dir for chrome-profile

Nick Sweetingfa4871593ac9
diff --git a/browser_use/browser/browser.py b/browser_use/browser/browser.py
index 6a9e9d9fa..191937684 100644
--- a/browser_use/browser/browser.py
+++ b/browser_use/browser/browser.py
@@ -213,10 +213,16 @@ class Browser:
except httpx.RequestError:
logger.debug('🌎 No existing Chrome instance found, starting a new one')
+ from platformdirs import user_config_dir
+
+ config_dir = user_config_dir('browseruse', ensure_exists=True)
+ chrome_profile_dir = config_dir / 'browser_profiles' / 'default'
+
# Start a new Chrome instance
chrome_launch_args = [
*{ # remove duplicates (usually preserves the order, but not guaranteed)
f'--remote-debugging-port={self.config.chrome_remote_debugging_port}',
+ '--user-data-dir={chrome_profile_dir}',
*CHROME_ARGS,
*(CHROME_DOCKER_ARGS if IN_DOCKER else []),
*(CHROME_HEADLESS_ARGS if self.config.headless else []),
diff --git a/browser_use/browser/chrome.py b/browser_use/browser/chrome.py
index e3fa229eb..0c92b638f 100644
--- a/browser_use/browser/chrome.py
+++ b/browser_use/browser/chrome.py
@@ -2,18 +2,18 @@ CHROME_EXTENSIONS = {} # coming in a separate PR
CHROME_EXTENSIONS_PATH = 'chrome_extensions'
CHROME_PROFILE_PATH = 'chrome_profile'
CHROME_PROFILE_USER = 'Default'
-CHROME_DEBUG_PORT = 9222
+CHROME_DEBUG_PORT = 9242
CHROME_DISABLED_COMPONENTS = [
'Translate',
'AcceptCHFrame',
'OptimizationHints',
'ProcessPerSiteUpToMainFrameThreshold',
'InterestFeedContentSuggestions',
- 'CalculateNativeWinOcclusion',
+ # 'CalculateNativeWinOcclusion',
'BackForwardCache',
- 'HeavyAdPrivacyMitigations',
+ # 'HeavyAdPrivacyMitigations',
'LazyFrameLoading',
- 'ImprovedCookieControls',
+ # 'ImprovedCookieControls',
'PrivacySandboxSettings4',
'AutofillServerCommunication',
'CertificateTransparencyComponentUpdater',
@@ -55,29 +55,32 @@ CHROME_DISABLE_SECURITY_ARGS = [
'--ignore-certificate-errors',
'--ignore-ssl-errors',
'--ignore-certificate-errors-spki-list',
- '--allow-insecure-localhost',
+ # '--allow-insecure-localhost',
]
# flags to make chrome behave more deterministically across different OS's
CHROME_DETERMINISTIC_RENDERING_ARGS = [
- # '--deterministic-mode',
- # '--js-flags=--random-seed=1157259159', # make all JS random numbers deterministic by providing a seed
- # '--force-device-scale-factor=1',
- '--hide-scrollbars', # hide scrollbars because otherwise they show up in screenshots
+ '--deterministic-mode',
+ '--js-flags=--random-seed=1157259159', # make all JS random numbers deterministic by providing a seed
+ '--force-device-scale-factor=1',
# GPU, canvas, text, and pdf rendering config
# chrome://gpu
- # '--enable-webgl', # enable web-gl graphics support
- # '--font-render-hinting=none', # make rendering more deterministic by ignoring OS font hints, may also need css override, try: * {text-rendering: geometricprecision !important; -webkit-font-smoothing: antialiased;}
- # '--force-color-profile=srgb', # make rendering more deterministic by using consistent color profile, if browser looks weird, try: generic-rgb
+ '--enable-webgl', # enable web-gl graphics support
+ '--font-render-hinting=none', # make rendering more deterministic by ignoring OS font hints, may also need css override, try: * {text-rendering: geometricprecision !important; -webkit-font-smoothing: antialiased;}
+ '--force-color-profile=srgb', # make rendering more deterministic by using consistent color profile, if browser looks weird, try: generic-rgb
# '--disable-partial-raster', # make rendering more deterministic (TODO: verify if still needed)
- # '--disable-skia-runtime-opts', # make rendering more deterministic by avoiding Skia hot path runtime optimizations
- # '--disable-2d-canvas-clip-aa', # make rendering more deterministic by disabling antialiasing on 2d canvas clips
+ '--disable-skia-runtime-opts', # make rendering more deterministic by avoiding Skia hot path runtime optimizations
+ '--disable-2d-canvas-clip-aa', # make rendering more deterministic by disabling antialiasing on 2d canvas clips
# '--disable-gpu', # falls back to more consistent software renderer across all OS's, especially helps linux text rendering look less weird
# // '--use-gl=swiftshader', <- DO NOT USE, breaks M1 ARM64. it makes rendering more deterministic by using simpler CPU renderer instead of OS GPU renderer bug: https://groups.google.com/a/chromium.org/g/chromium-dev/c/8eR2GctzGuw
# // '--disable-software-rasterizer', <- DO NOT USE, harmless, used in tandem with --disable-gpu
# // '--run-all-compositor-stages-before-draw', <- DO NOT USE, makes headful chrome hang on startup (tested v121 Google Chrome.app on macOS)
# // '--disable-gl-drawing-for-tests', <- DO NOT USE, disables gl output (makes tests run faster if you dont care about canvas)
# // '--blink-settings=imagesEnabled=false', <- DO NOT USE, disables images entirely (only sometimes useful to speed up loading)
+]
+
+
+CHROME_ARGS = [
# Process management & performance tuning
# chrome://process-internals
# '--disable-lazy-loading', # make rendering more deterministic by loading all content up-front instead of on-focus
@@ -89,10 +92,6 @@ CHROME_DETERMINISTIC_RENDERING_ARGS = [
# '--disable-extensions-http-throttling', # dont throttle http traffic based on runtime heuristics
# '--disable-field-trial-config', # disable shared field trial state between browser processes
# '--disable-back-forward-cache', # disable browsing navigation cache
-]
-
-
-CHROME_ARGS = [
# Profile data dir setup
# chrome://profile-internals
# f'--user-data-dir={CHROME_PROFILE_PATH}', # managed by playwright arg instead
@@ -117,7 +116,8 @@ CHROME_ARGS = [
# '--window-position=0,0',
# '--start-maximized',
'--install-autogenerated-theme=0,0,0', # black border makes it easier to see which chrome window is browser-use's
- #'--virtual-time-budget=60000', # fast-forward all animations & timers by 60s, dont use this it's unfortunately buggy and breaks screenshot and PDF capture sometimes
+ '--hide-scrollbars', # stop scrollbars from affecting screenshot width/height
+ #'--virtual-time-budget=60000', # DONT USE THIS, makes chrome hang forever and doesn't work, used to fast-forward all animations & timers by 60s, dont use this it's unfortunately buggy and breaks screenshot and PDF capture sometimes
#'--autoplay-policy=no-user-gesture-required', # auto-start videos so they trigger network requests + show up in outputs
#'--disable-gesture-requirement-for-media-playback',
#'--lang=en-US,en;q=0.9',
@@ -125,8 +125,8 @@ CHROME_ARGS = [
# chrome://inspect
'--log-level=2', # 1=DEBUG 2=WARNING 3=ERROR
'--enable-logging=stderr',
- # '--remote-debugging-address=127.0.0.1', <- never expose to non-localhost, would allow attacker to drive your browser from any machine
- # '--enable-experimental-extension-apis', # add support for tab groups
+ # '--remote-debugging-address=127.0.0.1', <- DONT USE THIS, no longer supported on chrome >100, never expose to non-localhost, would allow attacker to drive your browser from any machine
+ # '--enable-experimental-extension-apis', # add support for tab groups via chrome.tabs extension API
'--disable-focus-on-load', # prevent browser from hijacking focus
'--disable-window-activation',
# '--in-process-gpu', <- DONT USE THIS, makes headful startup time ~5-10s slower (tested v121 Google Chrome.app on macOS)
@@ -173,6 +173,6 @@ CHROME_ARGS = [
'--disable-breakpad',
# other feature flags
# chrome://flags chrome://components
- # f'--disable-features={",".join(CHROME_DISABLED_COMPONENTS)}',
- # '--enable-features=NetworkService',
+ f'--disable-features={",".join(CHROME_DISABLED_COMPONENTS)}',
+ '--enable-features=NetworkService',
]