PlaywrightCapture 1.41.0__tar.gz → 1.41.2__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.41.0
3
+ Version: 1.41.2
4
4
  Summary: A simple library to capture websites using playwright
5
5
  License-Expression: BSD-3-Clause
6
6
  License-File: LICENSE
@@ -1230,6 +1230,11 @@ class Capture():
1230
1230
  self.logger.warning(f"Unable to get cookies: {e}")
1231
1231
  errors.append(f'Unable to get the cookies: {e}')
1232
1232
  self.should_retry = True
1233
+ except Exception as e:
1234
+ # When the driver explodes for no clear reason.
1235
+ self.logger.warning(f"[Generic Exception] Unable to get cookies: {e}")
1236
+ errors.append(f'[Generic Exception] Unable to get the cookies: {e}')
1237
+ self.should_retry = True
1233
1238
 
1234
1239
  # Collect storage state, including IndexedDB, to capture the full browser state.
1235
1240
  try:
@@ -1243,6 +1248,11 @@ class Capture():
1243
1248
  self.logger.warning(f"Unable to get the storage: {e}")
1244
1249
  errors.append(f'Unable to get the storage: {e}')
1245
1250
  self.should_retry = True
1251
+ except Exception as e:
1252
+ # When the driver explodes for no clear reason.
1253
+ self.logger.warning(f"[Generic Exception] Unable to get the storage: {e}")
1254
+ errors.append(f'[Generic Exception] Unable to get the storage: {e}')
1255
+ self.should_retry = True
1246
1256
 
1247
1257
  try:
1248
1258
  if page.is_closed():
@@ -1387,8 +1397,8 @@ class Capture():
1387
1397
  await route.continue_()
1388
1398
  else:
1389
1399
  # other URLs
1390
- not_local, message = self.__check_local_url(request.url)
1391
- if not_local:
1400
+ public, message = self.__check_local_url(request.url)
1401
+ if public:
1392
1402
  await route.continue_()
1393
1403
  else:
1394
1404
  await route.fulfill(status=404, content_type="text/plain", body=message)
@@ -2284,6 +2294,15 @@ class Capture():
2284
2294
  In the meantime, we try to get all the potential ones in this method.
2285
2295
  Method inspired by https://github.com/ail-project/ail-framework/blob/master/bin/lib/crawlers.py
2286
2296
  """
2297
+ async def __check_local_middleware(req: aiohttp.ClientRequest, handler: aiohttp.ClientHandlerType) -> aiohttp.ClientResponse:
2298
+ if self.only_global_lookup:
2299
+ public, message = self.__check_local_url(str(req.url))
2300
+ if public is False:
2301
+ # got a local URL
2302
+ self.logger.warning(f'Attempted to get a local favicon (in redirect): {message}')
2303
+ raise aiohttp.ClientError(f'Attempted to get a local favicon (in redirect): {message}')
2304
+ return await handler(req)
2305
+
2287
2306
  connector = None
2288
2307
  if self.proxy:
2289
2308
  # NOTE 2024-05-17: switch to async to fetch, the lib uses socks5h by default
@@ -2304,10 +2323,13 @@ class Capture():
2304
2323
  if url_to_fetch.startswith('/'):
2305
2324
  self.logger.info(f'Landing page not valid, cannot get favicon: {rendered_url}')
2306
2325
  continue
2326
+ if url_to_fetch.startswith('blob'):
2327
+ self.logger.warning(f'Cannot get a favicon from a blob URL: {url_to_fetch}')
2328
+ continue
2307
2329
 
2308
2330
  if self.only_global_lookup:
2309
- not_local, message = self.__check_local_url(url_to_fetch)
2310
- if not_local is False:
2331
+ public, message = self.__check_local_url(url_to_fetch)
2332
+ if public is False:
2311
2333
  # got a local URL
2312
2334
  self.logger.warning(f'Attempted to get a local favicon: {message}')
2313
2335
  continue
@@ -2315,7 +2337,7 @@ class Capture():
2315
2337
  if url_to_fetch in self._requests:
2316
2338
  favicon = self._requests[url_to_fetch]
2317
2339
  if not favicon:
2318
- async with session.get(url_to_fetch, ssl=False) as favicon_response:
2340
+ async with session.get(url_to_fetch, ssl=False, middlewares=[__check_local_middleware]) as favicon_response:
2319
2341
  favicon_response.raise_for_status()
2320
2342
  favicon = await favicon_response.read()
2321
2343
  if favicon:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PlaywrightCapture"
3
- version = "1.41.0"
3
+ version = "1.41.2"
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"}