| 707 | return Path(files.get_abs_path("tmp/browser/screenshots", self.safe_context_id)) |
| 708 | |
| 709 | async def ensure_started(self) -> None: |
| 710 | if self._context_is_alive(): |
| 711 | return |
| 712 | if self.context: |
| 713 | await self._discard_stale_context("Browser context is stale; restarting.") |
| 714 | |
| 715 | if self._start_lock is None: |
| 716 | self._start_lock = asyncio.Lock() |
| 717 | |
| 718 | async with self._start_lock: |
| 719 | if self._context_is_alive(): |
| 720 | return |
| 721 | if self.context: |
| 722 | await self._discard_stale_context("Browser context is stale; restarting.") |
| 723 | elif self.playwright and not self._closing: |
| 724 | await self._stop_playwright("Browser context closed; restarting Playwright.") |
| 725 | await self._start() |
| 726 | |
| 727 | def _context_is_alive(self) -> bool: |
| 728 | if not self.context: |