Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/strands_tools/browser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,25 @@ async def _async_init_session(self, action: InitSessionAction) -> Dict[str, Any]
# Create new browser instance for this session
session = await self.create_browser_session()

if isinstance(session, PlaywrightBrowser):
if self.__class__.__name__ == "AgentCoreBrowser":
# AgentCoreBrowser case
session_browser = session
if not session_browser.contexts:
raise RuntimeError(
"AgentCoreBrowser CDP connection has no contexts. "
"This may indicate a connection issue with the remote browser."
)
session_context = session_browser.contexts[0]
session_page = await session_context.new_page()

elif isinstance(session, PlaywrightBrowser):
# Normal non-persistent case
session_browser = session
session_context = await session_browser.new_context()
session_page = await session_context.new_page()

else:
# Persistent context case
# Local chromium persistent context case
session_context = session
session_browser = session_context.browser
session_page = await session_context.new_page()
Expand Down
28 changes: 4 additions & 24 deletions tests/test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,7 @@ def test_str_replace_no_backup(self, mock_user_input, temp_file, clean_content_h
"""Test str_replace without creating backup when EDITOR_DISABLE_BACKUP is set."""
mock_user_input.return_value = "y"

result = editor.editor(
command="str_replace",
path=temp_file,
old_str="Line 2",
new_str="Modified Line 2"
)
result = editor.editor(command="str_replace", path=temp_file, old_str="Line 2", new_str="Modified Line 2")

assert result["status"] == "success"

Expand All @@ -278,12 +273,7 @@ def test_pattern_replace_no_backup(self, mock_user_input, temp_file, clean_conte
"""Test pattern_replace without creating backup."""
mock_user_input.return_value = "y"

result = editor.editor(
command="pattern_replace",
path=temp_file,
pattern="Line.*",
new_str="Updated Line"
)
result = editor.editor(command="pattern_replace", path=temp_file, pattern="Line.*", new_str="Updated Line")

assert result["status"] == "success"
backup_path = f"{temp_file}.bak"
Expand All @@ -295,12 +285,7 @@ def test_insert_no_backup(self, mock_user_input, temp_file, clean_content_histor
"""Test insert without creating backup."""
mock_user_input.return_value = "y"

result = editor.editor(
command="insert",
path=temp_file,
new_str="New line",
insert_line=2
)
result = editor.editor(command="insert", path=temp_file, new_str="New line", insert_line=2)

assert result["status"] == "success"
backup_path = f"{temp_file}.bak"
Expand All @@ -315,12 +300,7 @@ def test_backup_created_by_default(self, mock_user_input, temp_file, clean_conte

mock_user_input.return_value = "y"

result = editor.editor(
command="str_replace",
path=temp_file,
old_str="Line 2",
new_str="Modified Line 2"
)
result = editor.editor(command="str_replace", path=temp_file, old_str="Line 2", new_str="Modified Line 2")

assert result["status"] == "success"
backup_path = f"{temp_file}.bak"
Expand Down
Loading