diff --git a/playwrightcapture/capture.py b/playwrightcapture/capture.py index 911f12e..de2272f 100644 --- a/playwrightcapture/capture.py +++ b/playwrightcapture/capture.py @@ -732,7 +732,7 @@ async def __frame_consent(self, frame: Frame) -> bool: await frame.get_by_label(label).click(timeout=2000) break except (TimeoutError, asyncio.TimeoutError) as e: - self.logger.warning(f'Frame consent timeout: {e}') + self.logger.warning(f'Consent timeout (label {label}) : {e}') try: async with timeout(5): @@ -742,9 +742,9 @@ async def __frame_consent(self, frame: Frame) -> bool: await frame.get_by_role("button", name=label).click(timeout=2000) break except (TimeoutError, asyncio.TimeoutError) as e: - self.logger.warning(f'Frame consent timeout: {e}') + self.logger.warning(f'Frame consent timeout (button {label}): {e}') except Exception as e: - self.logger.info(f'Issue with frame consent: {e}') + self.logger.info(f'Issue with consent validation: {e}') return got_button async def _move_time_forward(self, page: Page, time: int) -> None: @@ -825,12 +825,18 @@ async def store_request(request: Request) -> None: capturing_sub = False try: page = await self.context.new_page() - await page.clock.install() except Error as e: - self.logger.warning(f'The context is in a broken state: {e}') + self.logger.warning(f'Unable to create new page, the context is in a broken state: {e}') self.should_retry = True return to_return + try: + await page.clock.install() + clock_set = True + except Error as e: + self.logger.warning(f'Unable to install the clock: {e}') + clock_set = False + if allow_tracking: # Add authorization clickthroughs await self.__dialog_didomi_clickthrough(page) @@ -898,8 +904,7 @@ async def store_request(request: Request) -> None: await page.bring_to_front() self.logger.debug('Page moved to front.') except Error as e: - self.logger.warning('Page in a broken state.') - raise e + self.logger.warning(f'Unable to bring the page to the front: {e}.') # page instrumentation await self._wait_for_random_timeout(page, 5) # Wait 5 sec after document loaded @@ -969,7 +974,8 @@ async def store_request(request: Request) -> None: self.logger.debug('Got button on main frame') await self._wait_for_random_timeout(page, 10) # Wait 10 sec after click - await self._move_time_forward(page, 10) + if clock_set: + await self._move_time_forward(page, 10) if parsed_url.fragment: # We got a fragment, make sure we go to it and scroll only a little bit. @@ -1037,8 +1043,9 @@ async def store_request(request: Request) -> None: z.writestr(f'{i}_{filename}', file_content) to_return["downloaded_file"] = mem_zip.getvalue() - # fast forward ~30s - await self._move_time_forward(page, 30) + if clock_set: + # fast forward ~30s + await self._move_time_forward(page, 30) self.logger.debug('Done with instrumentation, waiting for network idle.') await self._wait_for_random_timeout(page, 5) # Wait 5 sec after instrumentation diff --git a/poetry.lock b/poetry.lock index 514c3b6..5217fc5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1140,13 +1140,13 @@ files = [ [[package]] name = "packaging" -version = "24.1" +version = "24.2" description = "Core utilities for Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "packaging-24.1-py3-none-any.whl", hash = "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"}, - {file = "packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002"}, + {file = "packaging-24.2-py3-none-any.whl", hash = "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759"}, + {file = "packaging-24.2.tar.gz", hash = "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index 58ed7f7..cdc367d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "PlaywrightCapture" -version = "1.27.0" +version = "1.27.1" description = "A simple library to capture websites using playwright" authors = ["Raphaƫl Vinot "] license = "BSD-3-Clause"