From c0cf65984823faa9d0b5180508affde75e13acc0 Mon Sep 17 00:00:00 2001 From: Eugenio Lacuesta <1731933+elacuesta@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:45:10 -0300 Subject: [PATCH] Close page later, unpin playwright version in tests (#224) --- scrapy_playwright/handler.py | 8 ++++---- tox.ini | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scrapy_playwright/handler.py b/scrapy_playwright/handler.py index b1f69ad1..8b4458ba 100644 --- a/scrapy_playwright/handler.py +++ b/scrapy_playwright/handler.py @@ -350,10 +350,6 @@ async def _download_request_with_page( ) request.meta["download_latency"] = time() - start_time - if not request.meta.get("playwright_include_page"): - await page.close() - self.stats.inc_value("playwright/page_count/closed") - server_ip_address = None with suppress(AttributeError, KeyError, TypeError, ValueError): server_addr = await response.server_addr() @@ -362,6 +358,10 @@ async def _download_request_with_page( with suppress(AttributeError): request.meta["playwright_security_details"] = await response.security_details() + if not request.meta.get("playwright_include_page"): + await page.close() + self.stats.inc_value("playwright/page_count/closed") + body, encoding = _encode_body(headers=headers, text=body_str) respcls = responsetypes.from_args(headers=headers, url=page.url, body=body) return respcls( diff --git a/tox.ini b/tox.ini index 6b5b10c9..9ebf66d4 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,6 @@ deps = pytest_asyncio==0.21.1 pytest_cov==4.1.0 pytest_twisted==1.14 - playwright==1.36.0 commands = playwright install py.test -vv --reactor=asyncio \