Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix: preserve non-ASCII chars in all remaining JSON file outputs
Laith Weinberger8ebe4385ed3d
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex a311696e2..2337b44ee 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -1357,7 +1357,7 @@ class BrowserSession(BaseModel):output_file = Path(output_path).expanduser().resolve()output_file.parent.mkdir(parents=True, exist_ok=True)- output_file.write_text(json.dumps(storage_state, indent=2))+ output_file.write_text(json.dumps(storage_state, indent=2, ensure_ascii=False), encoding='utf-8')self.logger.info(f'💾 Exported {len(cookies)} cookies to {output_file}')return storage_statediff --git a/browser_use/browser/watchdogs/har_recording_watchdog.py b/browser_use/browser/watchdogs/har_recording_watchdog.pyindex f2a82ae37..cf6d6331c 100644--- a/browser_use/browser/watchdogs/har_recording_watchdog.py+++ b/browser_use/browser/watchdogs/har_recording_watchdog.py@@ -665,7 +665,7 @@ class HarRecordingWatchdog(BaseWatchdog):tmp_path = self._har_path.with_suffix(self._har_path.suffix + '.tmp')# Write as bytes explicitly to avoid any text/binary mode confusion in different environments- tmp_path.write_bytes(json.dumps(har_obj, indent=2).encode('utf-8'))+ tmp_path.write_bytes(json.dumps(har_obj, indent=2, ensure_ascii=False).encode('utf-8'))tmp_path.replace(self._har_path)def _format_page_started_datetime(self, timestamp: float | None) -> str:diff --git a/browser_use/browser/watchdogs/storage_state_watchdog.py b/browser_use/browser/watchdogs/storage_state_watchdog.pyindex 44e328f0f..736235129 100644--- a/browser_use/browser/watchdogs/storage_state_watchdog.py+++ b/browser_use/browser/watchdogs/storage_state_watchdog.py@@ -202,7 +202,7 @@ class StorageStateWatchdog(BaseWatchdog):# Write atomicallytemp_path = json_path.with_suffix('.json.tmp')- temp_path.write_text(json.dumps(merged_state, indent=4))+ temp_path.write_text(json.dumps(merged_state, indent=4, ensure_ascii=False), encoding='utf-8')# Backup existing fileif json_path.exists():diff --git a/browser_use/cli.py b/browser_use/cli.pyindex 5b32f1779..631127bf6 100644--- a/browser_use/cli.py+++ b/browser_use/cli.py@@ -294,8 +294,8 @@ def save_user_config(config: dict[str, Any]) -> None:# Save to separate history filehistory_file = CONFIG.BROWSER_USE_CONFIG_DIR / 'command_history.json'- with open(history_file, 'w') as f:- json.dump(history, f, indent=2)+ with open(history_file, 'w', encoding='utf-8') as f:+ json.dump(history, f, indent=2, ensure_ascii=False)def update_config_with_click_args(config: dict[str, Any], ctx: click.Context) -> dict[str, Any]:diff --git a/browser_use/code_use/views.py b/browser_use/code_use/views.pyindex 676fa4ab2..ef9e25890 100644--- a/browser_use/code_use/views.py+++ b/browser_use/code_use/views.py@@ -398,6 +398,6 @@ class CodeAgentHistoryList:Path(filepath).parent.mkdir(parents=True, exist_ok=True)data = self.model_dump()with open(filepath, 'w', encoding='utf-8') as f:- json.dump(data, f, indent=2)+ json.dump(data, f, indent=2, ensure_ascii=False)except Exception as e:raise ediff --git a/browser_use/skill_cli/commands/browser.py b/browser_use/skill_cli/commands/browser.pyindex e29ba930e..658808298 100644--- a/browser_use/skill_cli/commands/browser.py+++ b/browser_use/skill_cli/commands/browser.py@@ -495,7 +495,7 @@ async def handle(action: str, session: SessionInfo, params: dict[str, Any]) -> A]file_path = Path(params['file'])- file_path.write_text(json.dumps(cookie_list, indent=2))+ file_path.write_text(json.dumps(cookie_list, indent=2, ensure_ascii=False), encoding='utf-8')return {'exported': len(cookie_list), 'file': str(file_path)}elif cookies_command == 'import':