Skip to content

Commit f9253fc

Browse files
authored
await AsyncPlaywright.stop on close (#214)
1 parent 229442c commit f9253fc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

scrapy_playwright/handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ async def _launch(self) -> None:
113113
"""Launch Playwright manager and configured startup context(s)."""
114114
logger.info("Starting download handler")
115115
self.playwright_context_manager = PlaywrightContextManager()
116-
playwright_instance = await self.playwright_context_manager.start()
117-
self.browser_type: BrowserType = getattr(playwright_instance, self.browser_type_name)
116+
self.playwright = await self.playwright_context_manager.start()
117+
self.browser_type: BrowserType = getattr(self.playwright, self.browser_type_name)
118118
if self.startup_context_kwargs:
119119
logger.info("Launching %i startup context(s)", len(self.startup_context_kwargs))
120120
await asyncio.gather(
@@ -266,6 +266,7 @@ async def _close(self) -> None:
266266
logger.info("Closing browser")
267267
await self.browser.close()
268268
await self.playwright_context_manager.__aexit__()
269+
await self.playwright.stop()
269270

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

0 commit comments

Comments
 (0)