PlaywrightCapture 1.40.8__tar.gz → 1.41.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.4
2
2
  Name: PlaywrightCapture
3
- Version: 1.40.8
3
+ Version: 1.41.0
4
4
  Summary: A simple library to capture websites using playwright
5
5
  License-Expression: BSD-3-Clause
6
6
  License-File: LICENSE
@@ -19,7 +19,7 @@ Classifier: Topic :: Internet
19
19
  Classifier: Topic :: Security
20
20
  Provides-Extra: recaptcha
21
21
  Requires-Dist: SpeechRecognition (>=3.17.0) ; extra == "recaptcha"
22
- Requires-Dist: aiohttp-socks (>=0.11.0)
22
+ Requires-Dist: aiohttp-socks (>=0.12.0)
23
23
  Requires-Dist: aiohttp[speedups] (>=3.14.3)
24
24
  Requires-Dist: async-timeout (>=5.0.1) ; python_version < "3.11"
25
25
  Requires-Dist: beautifulsoup4[charset-normalizer,lxml] (>=4.15.0)
@@ -32,7 +32,7 @@ Requires-Dist: playwright-stealth (>=2.0.3)
32
32
  Requires-Dist: pure-magic-rs (>=0.4.3)
33
33
  Requires-Dist: pydub-ng (>=0.2.0) ; extra == "recaptcha"
34
34
  Requires-Dist: pyfaup-rs (>=0.4.6,<0.5.0)
35
- Requires-Dist: python-socks (>=2.7.1,<3.0.0)
35
+ Requires-Dist: python-socks (>=3.0.0,<4.0.0)
36
36
  Requires-Dist: rfc3161-client (>=1.0.4,<2.0.0)
37
37
  Requires-Dist: typing-extensions (>=4.12.2,<5.0.0) ; python_version < "3.12"
38
38
  Requires-Dist: w3lib (>=2.4.1)
@@ -31,7 +31,7 @@ from bs4 import BeautifulSoup
31
31
  from charset_normalizer import from_bytes
32
32
  from lookyloo_models import Cookie, CaptureSettings
33
33
  from playwright._impl._errors import TargetClosedError
34
- from playwright.async_api import async_playwright, Frame, Error, Page, Download, Request, Route
34
+ from playwright.async_api import async_playwright, Frame, Error, Page, Download, Request, Route, ConsoleMessage
35
35
  from playwright.async_api import TimeoutError as PlaywrightTimeoutError
36
36
  from playwright_stealth import Stealth, ALL_EVASIONS_DISABLED_KWARGS # type: ignore[attr-defined]
37
37
  from pure_magic_rs import MagicDb
@@ -101,6 +101,9 @@ class CaptureResponse(TypedDict, total=False):
101
101
  # dict[<entry name>] = '<base64 encoded timestamp response>'
102
102
  trusted_timestamps: dict[str, str] | None
103
103
 
104
+ # The entries in the debug console gathered during the captue
105
+ console_messages: list[dict[str, str | int | float]] | None
106
+
104
107
  # One day, playwright will support getting the favicon from the capture itself
105
108
  # favicon: Optional[bytes]
106
109
  # in the meantime, we need a workaround: https://github.com/Lookyloo/PlaywrightCapture/issues/45
@@ -226,6 +229,9 @@ class Capture():
226
229
  # Trusted Timestamp Settings are provided by LacusCore
227
230
  self.tt_settings = tt_settings
228
231
 
232
+ # Gather console messages
233
+ self.console_messages: list[dict[str, str | int | float]] = []
234
+
229
235
  # Prepare the env to use for playwright
230
236
  if env:
231
237
  self._env.update(env)
@@ -391,6 +397,19 @@ class Capture():
391
397
  self.logger.info(f'Unable to force download: {e}')
392
398
  await route.continue_()
393
399
 
400
+ async def handle_console_msg(msg: ConsoleMessage) -> None:
401
+ to_add = {'timestamp': msg.timestamp, 'type': msg.type, 'text': msg.text}
402
+
403
+ if msg.location.get('url') is not None:
404
+ to_add['url'] = msg.location['url']
405
+ if msg.location.get('line') is not None:
406
+ # can be 0
407
+ to_add['line'] = msg.location['line']
408
+ if msg.location.get('column') is not None:
409
+ # can be 0
410
+ to_add['column'] = msg.location['column']
411
+ self.console_messages.append(to_add)
412
+
394
413
  np_retry = 3
395
414
  while np_retry > 0:
396
415
  try:
@@ -435,6 +454,7 @@ class Capture():
435
454
  page.on("requestfinished", store_request)
436
455
  page.on("dialog", lambda dialog: dialog.accept())
437
456
  page.on("download", handle_download)
457
+ page.on("console", handle_console_msg)
438
458
  return page
439
459
 
440
460
  def __prepare_proxy_playwright(self, proxy: str) -> ProxySettings:
@@ -1304,6 +1324,8 @@ class Capture():
1304
1324
  await self._get_trusted_timestamps(to_return)
1305
1325
  except Exception as e:
1306
1326
  self.logger.warning(f'Unable to get trusted timestamps: {e}')
1327
+ if self.console_messages:
1328
+ to_return['console_messages'] = self.console_messages
1307
1329
 
1308
1330
  def __check_local_url(self, url: str) -> tuple[bool, str]:
1309
1331
  try:
@@ -2029,6 +2051,7 @@ class Capture():
2029
2051
  'Error receiving data: Connection reset by peer',
2030
2052
  'Internal SOCKSv5 proxy server error.',
2031
2053
  'Host unreachable through SOCKSv5 server.',
2054
+ 'Connection to SOCKSv5 proxy server lost',
2032
2055
  'Operation was cancelled',
2033
2056
  'The URL can’t be shown',
2034
2057
  'Frame was detached',
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PlaywrightCapture"
3
- version = "1.40.8"
3
+ version = "1.41.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"}
@@ -18,10 +18,10 @@ dependencies = [
18
18
  "playwright-stealth (>=2.0.3)",
19
19
  "async-timeout (>=5.0.1) ; python_version < \"3.11\"",
20
20
  "aiohttp[speedups] (>=3.14.3)",
21
- "aiohttp-socks (>=0.11.0)",
21
+ "aiohttp-socks (>=0.12.0)",
22
22
  "typing-extensions (>=4.12.2,<5.0.0) ; python_version < \"3.12\"",
23
23
  "dnspython (>=2.7.0,<3.0.0)",
24
- "python-socks (>=2.7.1,<3.0.0)",
24
+ "python-socks (>=3.0.0,<4.0.0)",
25
25
  "rfc3161-client (>=1.0.4,<2.0.0)",
26
26
  "orjson (>=3.11.4,<4.0.0)",
27
27
  "pure-magic-rs (>=0.4.3)",
@@ -52,8 +52,8 @@ recaptcha = [
52
52
  [tool.poetry.group.dev.dependencies]
53
53
  types-beautifulsoup4 = "^4.12.0.20250516"
54
54
  pytest = "^9.1.1"
55
- mypy = "^2.3.0"
56
- types-dateparser = "^1.4.1.20260806"
55
+ mypy = "^2.3.1"
56
+ types-dateparser = "^1.4.2.20260813"
57
57
  types-pytz = "^2026.3.1.20260727"
58
58
 
59
59