PlaywrightCapture 1.31.6__tar.gz → 1.32.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: PlaywrightCapture
3
- Version: 1.31.6
3
+ Version: 1.32.0
4
4
  Summary: A simple library to capture websites using playwright
5
5
  License: BSD-3-Clause
6
6
  Author: Raphaël Vinot
@@ -20,9 +20,9 @@ Classifier: Topic :: Security
20
20
  Provides-Extra: recaptcha
21
21
  Requires-Dist: SpeechRecognition (>=3.14.3) ; extra == "recaptcha"
22
22
  Requires-Dist: aiohttp-socks (>=0.10.1)
23
- Requires-Dist: aiohttp[speedups] (>=3.12.14)
23
+ Requires-Dist: aiohttp[speedups] (>=3.12.15)
24
24
  Requires-Dist: async-timeout (>=5.0.1) ; python_version < "3.11"
25
- Requires-Dist: beautifulsoup4[charset-normalizer,lxml] (>=4.13.4)
25
+ Requires-Dist: beautifulsoup4[charset-normalizer,lxml] (>=4.13.5)
26
26
  Requires-Dist: dateparser (>=1.2.2)
27
27
  Requires-Dist: dnspython (>=2.7.0,<3.0.0)
28
28
  Requires-Dist: playwright (>=1.54.0)
@@ -1,4 +1,6 @@
1
1
  from .capture import Capture # noqa
2
+ from .capture import CaptureResponse # noqa
3
+ from .capture import SetCookieParam, Cookie # noqa
2
4
  from .helpers import get_devices # noqa
3
5
  from .exceptions import (PlaywrightCaptureException, UnknownPlaywrightDeviceType, # noqa
4
6
  UnknownPlaywrightBrowser, UnknownPlaywrightDevice,
@@ -6,6 +8,8 @@ from .exceptions import (PlaywrightCaptureException, UnknownPlaywrightDeviceType
6
8
 
7
9
  __all__ = [
8
10
  'Capture',
11
+ 'CaptureResponse',
12
+ 'SetCookieParam', 'Cookie',
9
13
  'get_devices',
10
14
  'PlaywrightCaptureException',
11
15
  'UnknownPlaywrightDeviceType',
@@ -46,18 +46,6 @@ if sys.version_info < (3, 11):
46
46
  else:
47
47
  from asyncio import timeout
48
48
 
49
- if sys.version_info < (3, 12):
50
- from typing_extensions import TypedDict
51
- else:
52
- from typing import TypedDict
53
-
54
- if TYPE_CHECKING:
55
- from playwright._impl._api_structures import (SetCookieParam, Geolocation,
56
- HttpCredentials, Headers,
57
- ViewportSize, Cookie,
58
- ProxySettings, StorageState)
59
- BROWSER = Literal['chromium', 'firefox', 'webkit']
60
-
61
49
  try:
62
50
  if sys.version_info < (3, 10):
63
51
  from pydub import AudioSegment # type: ignore[attr-defined]
@@ -68,6 +56,54 @@ try:
68
56
  except ImportError:
69
57
  CAN_SOLVE_CAPTCHA = False
70
58
 
59
+ # ####
60
+ # This bit is required as long as we need to support python < 3.12, stop removing it, you idiot
61
+ # That's the runtime failure: https://github.com/ail-project/lacus/actions/runs/16447900822/job/46484807036
62
+ # And the MyPy failure: https://github.com/ail-project/LacusCore/actions/runs/16447753492/job/46484287947
63
+ if sys.version_info < (3, 12):
64
+ from typing_extensions import TypedDict
65
+ else:
66
+ from typing import TypedDict
67
+
68
+ # These two classes are copies of te ones in Playwright, we need them until we can discard python 3.11
69
+ # They come from this file:
70
+ # https://github.com/microsoft/playwright-python/blob/main/playwright/_impl/_api_structures.py
71
+
72
+
73
+ class SetCookieParam(TypedDict, total=False):
74
+ name: str
75
+ value: str
76
+ url: str
77
+ domain: str
78
+ path: str
79
+ expires: float
80
+ httpOnly: bool
81
+ secure: bool
82
+ sameSite: Literal["Lax", "None", "Strict"]
83
+ partitionKey: str
84
+
85
+
86
+ class Cookie(TypedDict, total=False):
87
+ name: str
88
+ value: str
89
+ domain: str
90
+ path: str
91
+ expires: float
92
+ httpOnly: bool
93
+ secure: bool
94
+ sameSite: Literal["Lax", "None", "Strict"]
95
+ partitionKey: str
96
+
97
+ # ####################################
98
+
99
+
100
+ if TYPE_CHECKING:
101
+ from playwright._impl._api_structures import (Geolocation,
102
+ HttpCredentials, Headers,
103
+ ViewportSize,
104
+ ProxySettings, StorageState)
105
+ BROWSER = Literal['chromium', 'firefox', 'webkit']
106
+
71
107
 
72
108
  class CaptureResponse(TypedDict, total=False):
73
109
 
@@ -198,8 +234,6 @@ class Capture():
198
234
 
199
235
  async def __aenter__(self) -> Capture:
200
236
  '''Launch the browser'''
201
- self._temp_harfile = NamedTemporaryFile(delete=False)
202
-
203
237
  self.playwright = await async_playwright().start()
204
238
 
205
239
  if self.device_name:
@@ -219,11 +253,12 @@ class Capture():
219
253
  # Set of URLs that were captured in that context
220
254
  self._already_captured: set[str] = set()
221
255
 
256
+ # Create the temporary file to store the HAR content.
257
+ self._temp_harfile = NamedTemporaryFile(delete=False, prefix="playwright_capture_har", suffix=".json")
258
+
222
259
  return self
223
260
 
224
261
  async def __aexit__(self, exc_type: Any, exc: Any, tb: Any) -> bool:
225
- if hasattr(self, '_temp_harfile'):
226
- os.unlink(self._temp_harfile.name)
227
262
 
228
263
  try:
229
264
  await self.browser.close(reason="Closing browser at the end of the capture.")
@@ -235,6 +270,13 @@ class Capture():
235
270
  except Exception as e:
236
271
  # this should't happen, but just in case it does...
237
272
  self.logger.info(f'Unable to stop playwright: {e}')
273
+
274
+ if hasattr(self, '_temp_harfile'):
275
+ try:
276
+ os.unlink(self._temp_harfile.name)
277
+ except Exception as e:
278
+ self.logger.warning(f'Unable to remove temp HAR file {self._temp_harfile.name}: {e}')
279
+
238
280
  return True
239
281
 
240
282
  @property
@@ -515,7 +557,9 @@ class Capture():
515
557
 
516
558
  if self.cookies:
517
559
  try:
518
- await self.context.add_cookies(self.cookies)
560
+ # NOTE: Ignore type until we can use python 3.12 + only
561
+ # playwrightcapture.capture.SetCookieParam == playwright._impl._api_structures.SetCookieParam
562
+ await self.context.add_cookies(self.cookies) # type: ignore[arg-type]
519
563
  except Exception:
520
564
  self.logger.exception(f'Unable to set cookies: {self.cookies}')
521
565
 
@@ -1237,7 +1281,9 @@ class Capture():
1237
1281
 
1238
1282
  try:
1239
1283
  async with timeout(15):
1240
- to_return['cookies'] = await self.context.cookies()
1284
+ # NOTE: Ignore type until we can use python 3.12 + only
1285
+ # playwrightcapture.capture.SetCookieParam == playwright._impl._api_structures.SetCookieParam
1286
+ to_return['cookies'] = await self.context.cookies() # type: ignore[typeddict-item]
1241
1287
  except (TimeoutError, asyncio.TimeoutError):
1242
1288
  self.logger.warning("Unable to get cookies (timeout).")
1243
1289
  errors.append("Unable to get the cookies (timeout).")
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PlaywrightCapture"
3
- version = "1.31.6"
3
+ version = "1.32.0"
4
4
  description = "A simple library to capture websites using playwright"
5
5
  authors = [
6
6
  {name="Raphaël Vinot", email= "raphael.vinot@circl.lu"}
@@ -14,14 +14,14 @@ dynamic = [ "classifiers" ]
14
14
  dependencies = [
15
15
  "playwright (>=1.54.0)",
16
16
  "dateparser (>=1.2.2)",
17
- "beautifulsoup4[charset-normalizer,lxml] (>=4.13.4)",
17
+ "beautifulsoup4[charset-normalizer,lxml] (>=4.13.5)",
18
18
  "w3lib (>=2.3.1)",
19
19
  "tzdata (>=2025.2)",
20
20
  "playwright-stealth (>=2)",
21
21
  "setuptools (>=80.9.0)",
22
22
  "puremagic (>=1.30)",
23
23
  "async-timeout (>=5.0.1) ; python_version < \"3.11\"",
24
- "aiohttp[speedups] (>=3.12.14)",
24
+ "aiohttp[speedups] (>=3.12.15)",
25
25
  "aiohttp-socks (>=0.10.1)",
26
26
  "typing-extensions (>=4.12.2,<5.0.0) ; python_version < \"3.12\"",
27
27
  "dnspython (>=2.7.0,<3.0.0)",
@@ -51,9 +51,9 @@ recaptcha = [
51
51
  [tool.poetry.group.dev.dependencies]
52
52
  types-beautifulsoup4 = "^4.12.0.20250516"
53
53
  pytest = "^8.4.1"
54
- mypy = "^1.17.0"
55
- types-dateparser = "^1.2.2.20250627"
56
- types-pytz = "^2025.2.0.20250516"
54
+ mypy = "^1.17.1"
55
+ types-dateparser = "^1.2.2.20250809"
56
+ types-pytz = "^2025.2.0.20250809"
57
57
 
58
58
 
59
59
  [build-system]