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
feat(filesystem): add JSONL (JSON Lines) file support
Magnus Müllere86182e11ccd
diff --git a/browser_use/filesystem/file_system.py b/browser_use/filesystem/file_system.pyindex c7dffb403..120c13ec6 100644--- a/browser_use/filesystem/file_system.py+++ b/browser_use/filesystem/file_system.py@@ -112,6 +112,14 @@ class CsvFile(BaseFile):return 'csv'+class JsonlFile(BaseFile):+ """JSONL (JSON Lines) file implementation"""++ @property+ def extension(self) -> str:+ return 'jsonl'++class PdfFile(BaseFile):"""PDF file implementation"""@@ -183,6 +191,7 @@ class FileSystem:'md': MarkdownFile,'txt': TxtFile,'json': JsonFile,+ 'jsonl': JsonlFile,'csv': CsvFile,'pdf': PdfFile,}@@ -261,7 +270,7 @@ class FileSystem:_, extension = self._parse_filename(full_filename)except Exception:return f'Error: Invalid filename format {full_filename}. Must be alphanumeric with a supported extension.'- if extension in ['md', 'txt', 'json', 'csv']:+ if extension in ['md', 'txt', 'json', 'jsonl', 'csv']:import anyioasync with await anyio.open_file(full_filename, 'r') as f:@@ -489,6 +498,8 @@ class FileSystem:file_obj = TxtFile(**file_info)elif file_type == 'JsonFile':file_obj = JsonFile(**file_info)+ elif file_type == 'JsonlFile':+ file_obj = JsonlFile(**file_info)elif file_type == 'CsvFile':file_obj = CsvFile(**file_info)elif file_type == 'PdfFile':diff --git a/tests/ci/test_filesystem.py b/tests/ci/test_filesystem.pyindex 8275a72b0..bb2883b96 100644--- a/tests/ci/test_filesystem.py+++ b/tests/ci/test_filesystem.py@@ -13,6 +13,7 @@ from browser_use.filesystem.file_system import (FileSystem,FileSystemState,JsonFile,+ JsonlFile,MarkdownFile,TxtFile,)@@ -67,6 +68,18 @@ class TestBaseFile:assert csv_file.get_size == len(csv_content)assert csv_file.get_line_count == 3+ def test_jsonl_file_creation(self):+ """Test JsonlFile creation and basic properties."""+ jsonl_content = '{"id": 1, "name": "John"}\n{"id": 2, "name": "Jane"}'+ jsonl_file = JsonlFile(name='data', content=jsonl_content)++ assert jsonl_file.name == 'data'+ assert jsonl_file.content == jsonl_content+ assert jsonl_file.extension == 'jsonl'+ assert jsonl_file.full_name == 'data.jsonl'+ assert jsonl_file.get_size == len(jsonl_content)+ assert jsonl_file.get_line_count == 2+def test_file_content_operations(self):"""Test content update and append operations."""file_obj = TxtFile(name='test')@@ -241,6 +254,7 @@ class TestFileSystem:assert 'md' in extensionsassert 'txt' in extensionsassert 'json' in extensions+ assert 'jsonl' in extensionsassert 'csv' in extensionsdef test_filename_validation(self, temp_filesystem):@@ -253,7 +267,9 @@ class TestFileSystem:assert fs._is_valid_filename('file-name.md') is Trueassert fs._is_valid_filename('file123.txt') is Trueassert fs._is_valid_filename('data.json') is True+ assert fs._is_valid_filename('data.jsonl') is Trueassert fs._is_valid_filename('users.csv') is True+ assert fs._is_valid_filename('WebVoyager_data.jsonl') is True # with underscores# Invalid filenamesassert fs._is_valid_filename('test.doc') is False # wrong extension@@ -263,6 +279,7 @@ class TestFileSystem:assert fs._is_valid_filename('[email protected]') is False # special charsassert fs._is_valid_filename('.md') is False # no nameassert fs._is_valid_filename('.json') is False # no name+ assert fs._is_valid_filename('.jsonl') is False # no nameassert fs._is_valid_filename('.csv') is False # no namedef test_filename_parsing(self, temp_filesystem):