Skip to content

Commit

Permalink
await AsyncPlaywright.stop on close
Browse files Browse the repository at this point in the history
  • Loading branch information
elacuesta committed Jul 22, 2023
1 parent 229442c commit 5970c05
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions scrapy_playwright/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ async def _launch(self) -> None:
"""Launch Playwright manager and configured startup context(s)."""
logger.info("Starting download handler")
self.playwright_context_manager = PlaywrightContextManager()
playwright_instance = await self.playwright_context_manager.start()
self.browser_type: BrowserType = getattr(playwright_instance, self.browser_type_name)
self.playwright = await self.playwright_context_manager.start()
self.browser_type: BrowserType = getattr(self.playwright, self.browser_type_name)
if self.startup_context_kwargs:
logger.info("Launching %i startup context(s)", len(self.startup_context_kwargs))
await asyncio.gather(
Expand Down Expand Up @@ -266,6 +266,7 @@ async def _close(self) -> None:
logger.info("Closing browser")
await self.browser.close()
await self.playwright_context_manager.__aexit__()
await self.playwright.stop()

def download_request(self, request: Request, spider: Spider) -> Deferred:
if request.meta.get("playwright"):
Expand Down

0 comments on commit 5970c05

Please sign in to comment.