Skip to content

Commit d51576c

Browse files
committed
go_to always navigates directly
1 parent 54fc517 commit d51576c

2 files changed

Lines changed: 5 additions & 79 deletions

File tree

pydoll/browser/tab.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,6 @@ async def go_to(self, url: str, timeout: int = 300):
894894
"""
895895
Navigate to URL and wait for loading to complete.
896896
897-
Refreshes if URL matches current page.
898-
899897
Args:
900898
url: Target URL to navigate to.
901899
timeout: Maximum seconds to wait for page load (default 300).
@@ -905,14 +903,8 @@ async def go_to(self, url: str, timeout: int = 300):
905903
PageLoadTimeout: If page doesn't finish loading within timeout.
906904
"""
907905
logger.info(f'Navigating to URL: {url} (timeout={timeout}s)')
908-
if await self._refresh_if_url_not_changed(url, timeout):
909-
logger.debug('URL matches current page; refreshed with navigation')
910-
return
911-
912906
async with self._wait_page_load(timeout=timeout):
913-
response: NavigateResponse = await self._execute_command(
914-
PageCommands.navigate(url)
915-
)
907+
response: NavigateResponse = await self._execute_command(PageCommands.navigate(url))
916908
error_text = response['result'].get('errorText')
917909
if error_text:
918910
raise NavigationError(url, error_text)
@@ -1829,36 +1821,6 @@ def _get_evaluate_command(
18291821
serialization_options=serialization_options,
18301822
)
18311823

1832-
async def _refresh_if_url_not_changed(
1833-
self, url: str, timeout: int = 300
1834-
) -> bool:
1835-
"""Navigate to URL if it matches the current page.
1836-
1837-
Uses Page.navigate instead of Page.reload so that navigation
1838-
errors (e.g., DNS failures) are detected via errorText.
1839-
1840-
Args:
1841-
url: URL to compare against the current page.
1842-
timeout: Maximum seconds to wait for page load.
1843-
1844-
Returns:
1845-
True if the URL matched and a navigate-refresh was performed.
1846-
1847-
Raises:
1848-
NavigationError: If the navigation fails.
1849-
"""
1850-
current_url = await self.current_url
1851-
if current_url == url:
1852-
async with self._wait_page_load(timeout=timeout):
1853-
response: NavigateResponse = await self._execute_command(
1854-
PageCommands.navigate(url)
1855-
)
1856-
error_text = response['result'].get('errorText')
1857-
if error_text:
1858-
raise NavigationError(url, error_text)
1859-
return True
1860-
return False
1861-
18621824
@staticmethod
18631825
def _validate_argument_error(response: EvaluateResponse) -> None:
18641826
"""

tests/test_browser/test_browser_tab.py

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ class TestTabNavigation:
389389
async def test_go_to_new_url(self, tab):
390390
"""Test navigating to a new URL."""
391391
tab._connection_handler.execute_command.side_effect = [
392-
{'result': {'result': {'value': 'https://old-url.com'}}}, # current_url
393392
{'result': {}}, # Page.enable
394393
{'result': {'frameId': 'frame-id'}}, # navigate command
395394
{'result': {}}, # Page.disable
@@ -403,15 +402,14 @@ async def fire_callback(event_name, callback, temporary=False):
403402

404403
await tab.go_to('https://example.com')
405404

406-
assert tab._connection_handler.execute_command.call_count == 4
405+
assert tab._connection_handler.execute_command.call_count == 3
407406

408407
@pytest.mark.asyncio
409408
async def test_go_to_navigation_error(self, tab):
410409
"""Test that navigation errors raise NavigationError."""
411410
from pydoll.exceptions import NavigationError
412411

413412
tab._connection_handler.execute_command.side_effect = [
414-
{'result': {'result': {'value': 'https://old-url.com'}}}, # current_url
415413
{'result': {}}, # Page.enable
416414
{'result': {'frameId': 'f', 'errorText': 'net::ERR_NAME_NOT_RESOLVED'}},
417415
{'result': {}}, # Page.disable
@@ -431,11 +429,10 @@ async def fire_callback(event_name, callback, temporary=False):
431429

432430
@pytest.mark.asyncio
433431
async def test_go_to_same_url(self, tab):
434-
"""Test navigating to the same URL (should refresh)."""
432+
"""Test navigating to the same URL works the same as a new URL."""
435433
tab._connection_handler.execute_command.side_effect = [
436-
{'result': {'result': {'value': 'https://example.com'}}}, # current_url
437434
{'result': {}}, # Page.enable
438-
{'result': {}}, # refresh command
435+
{'result': {'frameId': 'frame-id'}}, # navigate command
439436
{'result': {}}, # Page.disable
440437
]
441438

@@ -447,13 +444,12 @@ async def fire_callback(event_name, callback, temporary=False):
447444

448445
await tab.go_to('https://example.com')
449446

450-
assert tab._connection_handler.execute_command.call_count == 4
447+
assert tab._connection_handler.execute_command.call_count == 3
451448

452449
@pytest.mark.asyncio
453450
async def test_go_to_timeout(self, tab):
454451
"""Test navigation timeout."""
455452
tab._connection_handler.execute_command.side_effect = [
456-
{'result': {'result': {'value': 'https://old-url.com'}}}, # current_url
457453
{'result': {}}, # Page.enable
458454
{'result': {'frameId': 'frame-id'}}, # navigate command
459455
{'result': {}}, # Page.disable
@@ -1851,38 +1847,6 @@ async def fire_callback(event_name, callback, temporary=False):
18511847

18521848
assert tab._page_events_enabled is False
18531849

1854-
@pytest.mark.asyncio
1855-
async def test_refresh_if_url_not_changed_same_url(self, tab):
1856-
"""Test _refresh_if_url_not_changed with same URL."""
1857-
tab._connection_handler.execute_command.side_effect = [
1858-
{'result': {'result': {'value': 'https://example.com'}}}, # current_url call
1859-
{'result': {}}, # Page.enable
1860-
{'result': {}}, # refresh call
1861-
{'result': {}}, # Page.disable
1862-
]
1863-
1864-
async def fire_callback(event_name, callback, temporary=False):
1865-
callback({'method': event_name, 'params': {}})
1866-
return 1
1867-
1868-
tab._connection_handler.register_callback = AsyncMock(side_effect=fire_callback)
1869-
1870-
result = await tab._refresh_if_url_not_changed('https://example.com')
1871-
1872-
assert result is True
1873-
assert tab._connection_handler.execute_command.call_count == 4
1874-
1875-
@pytest.mark.asyncio
1876-
async def test_refresh_if_url_not_changed_different_url(self, tab):
1877-
"""Test _refresh_if_url_not_changed with different URL."""
1878-
tab._connection_handler.execute_command.return_value = {
1879-
'result': {'result': {'value': 'https://different.com'}}
1880-
}
1881-
1882-
result = await tab._refresh_if_url_not_changed('https://example.com')
1883-
1884-
assert result is False
1885-
assert_mock_called_at_least_once(tab._connection_handler)
18861850

18871851

18881852
class TestTabRequestManagement:

0 commit comments

Comments
 (0)