Skip to content

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

Use UTF-8 for agent file writes

Ghravenc39253ff5073
diff --git a/browser_use/filesystem/file_system.py b/browser_use/filesystem/file_system.py
index 49946a1ea..f7cb2b435 100644
--- a/browser_use/filesystem/file_system.py
+++ b/browser_use/filesystem/file_system.py
@@ -110,12 +110,14 @@ class BaseFile(BaseModel, ABC):
def sync_to_disk_sync(self, path: Path) -> None:
file_path = path / self.full_name
- file_path.write_text(self.content)
+ file_path.write_text(self.content, encoding='utf-8')
async def sync_to_disk(self, path: Path) -> None:
file_path = path / self.full_name
with ThreadPoolExecutor() as executor:
- await asyncio.get_event_loop().run_in_executor(executor, lambda: file_path.write_text(self.content))
+ await asyncio.get_event_loop().run_in_executor(
+ executor, lambda: file_path.write_text(self.content, encoding='utf-8')
+ )
async def write(self, content: str, path: Path) -> None:
self.write_file_content(content)
diff --git a/tests/ci/infrastructure/test_filesystem.py b/tests/ci/infrastructure/test_filesystem.py
index 779a5f89d..3e7da4efe 100644
--- a/tests/ci/infrastructure/test_filesystem.py
+++ b/tests/ci/infrastructure/test_filesystem.py
@@ -106,7 +106,7 @@ class TestBaseFile:
"""Test file sync to disk operations."""
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
- file_obj = MarkdownFile(name='test', content='# Test Content')
+ file_obj = MarkdownFile(name='test', content='# Test Content\nJosé')
# Test sync to disk
await file_obj.sync_to_disk(tmp_path)
@@ -114,7 +114,8 @@ class TestBaseFile:
# Verify file was created on disk
file_path = tmp_path / 'test.md'
assert file_path.exists()
- assert file_path.read_text() == '# Test Content'
+ assert file_path.read_text(encoding='utf-8') == '# Test Content\nJosé'
+ assert file_path.read_bytes().endswith('José'.encode('utf-8'))
# Test write operation
await file_obj.write('# New Content', tmp_path)