MCPcopy Create free account
hub / github.com/apify/crawlee-python / _launch_new_browser

Method _launch_new_browser

src/crawlee/browsers/_browser_pool.py:362–379  ·  view source on GitHub ↗

Launch a new browser instance using the specified plugin.

(self, page_id: str, plugin: BrowserPlugin)

Source from the content-addressed store, hash-verified

360 self._inactive_browsers.append(browser)
361
362 async def _launch_new_browser(self, page_id: str, plugin: BrowserPlugin) -> BrowserController:
363 """Launch a new browser instance using the specified plugin."""
364 await self._execute_hooks(self._pre_launch_hooks, page_id, plugin)
365 browser = await plugin.new_browser()
366
367 try:
368 await self._execute_hooks(self._post_launch_hooks, page_id, browser)
369 except BaseException:
370 # Catch BaseException to also clean up on CancelledError raised by the outer
371 # asyncio.wait_for(operation_timeout) wrapping this call.
372 try:
373 await browser.close(force=True)
374 except Exception:
375 logger.exception('Failed to close browser after post_launch_hook error.')
376 raise
377
378 self._active_browsers.append(browser)
379 return browser
380
381 def _identify_inactive_browsers(self) -> None:
382 """Identify inactive browsers and move them to the inactive list if their idle time exceeds the threshold."""

Callers 1

_get_new_pageMethod · 0.95

Calls 3

_execute_hooksMethod · 0.95
new_browserMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected