PlaywrightCapture 1.25.5__py3-none-any.whl → 1.25.7__py3-none-any.whl

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.
@@ -339,19 +339,10 @@ class Capture():
339
339
  return self._headers
340
340
 
341
341
  @headers.setter
342
- def headers(self, headers: str | dict[str, str] | None) -> None:
342
+ def headers(self, headers: dict[str, str] | None) -> None:
343
343
  if not headers:
344
344
  return
345
- if isinstance(headers, str):
346
- new_headers: dict[str, str] = {}
347
- for header_line in headers.splitlines():
348
- if header_line and ':' in header_line:
349
- splitted = header_line.split(':', 1)
350
- if splitted and len(splitted) == 2:
351
- header, h_value = splitted
352
- if header.strip() and h_value.strip():
353
- new_headers[header.strip()] = h_value.strip()
354
- elif isinstance(headers, dict):
345
+ if isinstance(headers, dict):
355
346
  # Check if they are valid
356
347
  new_headers = {name.strip(): value.strip() for name, value in headers.items() if isinstance(name, str) and isinstance(value, str) and name.strip() and value.strip()}
357
348
  if new_headers != headers:
@@ -413,17 +404,24 @@ class Capture():
413
404
  device_context_settings = {}
414
405
  if self.device_name:
415
406
  device_context_settings = self.playwright.devices[self.device_name]
407
+ # We need to make sure the device_context_settings dict doesn't contains
408
+ # keys that are set by default in the context creation
409
+ if context_ua := device_context_settings.pop('user_agent', None):
410
+ ua = self.user_agent if self.user_agent else context_ua
411
+ if context_vp := device_context_settings.pop('viewport', self._default_viewport):
412
+ # Always true, but we also always want to pop it.
413
+ vp = self.viewport if self.viewport else context_vp
416
414
 
417
415
  self.context = await self.browser.new_context(
418
416
  record_har_path=self._temp_harfile.name,
419
417
  ignore_https_errors=True,
420
418
  bypass_csp=True,
421
419
  http_credentials=self.http_credentials if self.http_credentials else None,
422
- user_agent=self.user_agent if self.user_agent else device_context_settings.pop('user_agent', None),
420
+ user_agent=ua,
423
421
  locale=self.locale if self.locale else None,
424
422
  timezone_id=self.timezone_id if self.timezone_id else None,
425
423
  color_scheme=self.color_scheme if self.color_scheme else None,
426
- viewport=self.viewport if self.viewport else device_context_settings.pop('viewport', self._default_viewport),
424
+ viewport=vp,
427
425
  # For debug only
428
426
  # record_video_dir='./videos/',
429
427
  **device_context_settings
@@ -1096,7 +1094,7 @@ class Capture():
1096
1094
  try:
1097
1095
  async with timeout(30):
1098
1096
  return await page.content()
1099
- except (Error, TimeoutError):
1097
+ except (Error, TimeoutError, asyncio.TimeoutError):
1100
1098
  self.logger.debug('Unable to get page content, trying again.')
1101
1099
  tries -= 1
1102
1100
  await self._wait_for_random_timeout(page, 1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PlaywrightCapture
3
- Version: 1.25.5
3
+ Version: 1.25.7
4
4
  Summary: A simple library to capture websites using playwright
5
5
  Home-page: https://github.com/Lookyloo/PlaywrightCapture
6
6
  License: BSD-3-Clause
@@ -31,7 +31,7 @@ Requires-Dist: playwright-stealth (>=1.0.6,<2.0.0)
31
31
  Requires-Dist: puremagic (>=1.26,<2.0)
32
32
  Requires-Dist: pydub (>=0.25.1,<0.26.0) ; extra == "recaptcha"
33
33
  Requires-Dist: pytz (>=2024.1,<2025.0) ; python_version < "3.9"
34
- Requires-Dist: setuptools (>=70.3.0,<71.0.0)
34
+ Requires-Dist: setuptools (>=71.1.0,<72.0.0)
35
35
  Requires-Dist: tzdata (>=2024.1,<2025.0)
36
36
  Requires-Dist: w3lib (>=2.2.1,<3.0.0)
37
37
  Project-URL: Repository, https://github.com/Lookyloo/PlaywrightCapture
@@ -1,9 +1,9 @@
1
1
  playwrightcapture/__init__.py,sha256=F90Y8wYS13tDjgsfjuFrCfmzQfdnH44G-ovuilJfLEE,511
2
- playwrightcapture/capture.py,sha256=rPzmotG1_o-SS0I6oJbMPnVoVweSS_BQ-zUdDaInEsg,70897
2
+ playwrightcapture/capture.py,sha256=iB0hw4402_XrO14A4sblQdB5hVK1NZ-n7D_VkD7Y0hs,70768
3
3
  playwrightcapture/exceptions.py,sha256=LhGJQCGHzEu7Sx2Dfl28OFeDg1OmrwufFjAWXlxQnEA,366
4
4
  playwrightcapture/helpers.py,sha256=SXQLEuxMs8-bcWykMiUVosHzzxBKuS-QC0gBV3OmKmo,1764
5
5
  playwrightcapture/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- playwrightcapture-1.25.5.dist-info/LICENSE,sha256=uwFc39fTLacBUG-XTuxX6IQKTKhg4z14gWOLt3ex4Ho,1775
7
- playwrightcapture-1.25.5.dist-info/METADATA,sha256=KfTBTvcCfRoKhAZVGUXjoYfXODyrBFc0iWjTZeWwZ-I,3173
8
- playwrightcapture-1.25.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
- playwrightcapture-1.25.5.dist-info/RECORD,,
6
+ playwrightcapture-1.25.7.dist-info/LICENSE,sha256=uwFc39fTLacBUG-XTuxX6IQKTKhg4z14gWOLt3ex4Ho,1775
7
+ playwrightcapture-1.25.7.dist-info/METADATA,sha256=h0djpVBPhsTTxH2Hm1kV6AkGMPfVwEHA2lcgtoWEx7M,3173
8
+ playwrightcapture-1.25.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
+ playwrightcapture-1.25.7.dist-info/RECORD,,