MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / go_to_url

Method go_to_url

src/environment/browser/service.py:227–302  ·  view source on GitHub ↗

Navigate to URL, set new_tab=True to open in new tab, False to navigate in current tab

(self, request: GoToUrlRequest)

Source from the content-addressed store, hash-verified

225 )
226
227 async def go_to_url(self, request: GoToUrlRequest) -> ActionResult:
228 """Navigate to URL, set new_tab=True to open in new tab, False to navigate in current tab"""
229 try:
230 # Ensure browser session is ready
231 if not self._session.agent_focus:
232 logger.warning("Browser session not ready, waiting for initialization...")
233 await asyncio.sleep(1.0)
234
235 # Dispatch navigation event
236 event = self._session.event_bus.dispatch(NavigateToUrlEvent(url=request.url, new_tab=request.new_tab))
237 await event
238 await event.event_result(raise_if_any=True, raise_if_none=False)
239
240 # Wait for page to be ready and CDP session to be stable
241 await asyncio.sleep(1.0)
242
243 # Additional check to ensure page is loaded
244 try:
245 # Try to get current URL to verify page is ready
246 current_url = await self._session.get_current_page_url()
247 logger.debug(f"Page loaded successfully, current URL: {current_url}")
248 except Exception as e:
249 logger.warning(f"Could not verify page readiness: {e}")
250 # Continue anyway as the navigation might still be successful
251
252 if request.new_tab:
253 memory = f'Opened new tab with URL {request.url}'
254 msg = f'🔗 Opened new tab with url {request.url}'
255 else:
256 memory = f'Navigated to {request.url}'
257 msg = f'🔗 {memory}'
258
259 logger.info(msg)
260 return ActionResult(
261 success=True,
262 message=msg,
263 extra={"memory": memory}
264 )
265 except Exception as e:
266 error_msg = str(e)
267 # Always log the actual error first for debugging
268 self._session.logger.error(f'❌ Navigation failed: {error_msg}')
269
270 # Check if it's specifically a RuntimeError about CDP client
271 if isinstance(e, RuntimeError) and 'CDP client not initialized' in error_msg:
272 self._session.logger.error('❌ Browser connection failed - CDP client not properly initialized')
273 return ActionResult(
274 success=False,
275 message=f"Browser connection error: {error_msg}",
276 extra={"error": error_msg}
277 )
278 # Check for network-related errors
279 elif any(
280 err in error_msg
281 for err in [
282 'ERR_NAME_NOT_RESOLVED',
283 'ERR_INTERNET_DISCONNECTED',
284 'ERR_CONNECTION_REFUSED',

Callers

nothing calls this directly

Calls 7

NavigateToUrlEventClass · 0.90
ActionResultClass · 0.90
warningMethod · 0.80
get_current_page_urlMethod · 0.80
debugMethod · 0.80
infoMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected