Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion pydoll/browser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):

await self._connection_handler.close()

async def start(self) -> None:
async def start(self, headless: bool = False) -> None:
"""
Main method to start the browser.

Expand All @@ -102,6 +102,11 @@ async def start(self) -> None:
self.options.binary_location or self._get_default_binary_location()
)

if headless:
headless_arg = '--headless'
if headless_arg not in self.options.arguments:
self.options.add_argument(headless_arg)

self._setup_user_dir()
proxy_config = self._proxy_manager.get_proxy_credentials()

Expand Down
4 changes: 1 addition & 3 deletions pydoll/connection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,9 @@ async def close(self):
Closes the WebSocket connection and clears all event callbacks.
"""
await self.clear_callbacks()

if self._ws_connection is not None:
await self._ws_connection.close()

logger.info('WebSocket connection closed.')
logger.info('WebSocket connection closed.')

async def _ensure_active_connection(self):
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ async def test_start_browser_failure(mock_browser):
await mock_browser.start()


@pytest.mark.asyncio
async def test_start_headless(mock_browser):
mock_browser._connection_handler.ping.return_value = True
await mock_browser.start(headless=True)

assert "--headless" in mock_browser.options.arguments


@pytest.mark.asyncio
async def test_proxy_configuration(mock_browser):
mock_browser._proxy_manager.get_proxy_credentials = MagicMock(
Expand Down
Loading