From b28d5bfb464c7109740100f400e7550b35fff9ab Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 11 Jul 2024 14:39:56 +0200 Subject: [PATCH] Bugfix - Watches with BrowserSteps should recreate the data-dir if it was missing (in the case that you deleted/migrated) --- changedetectionio/content_fetchers/base.py | 8 +++++++- changedetectionio/content_fetchers/playwright.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/changedetectionio/content_fetchers/base.py b/changedetectionio/content_fetchers/base.py index eb95f04a..91fcc8e1 100644 --- a/changedetectionio/content_fetchers/base.py +++ b/changedetectionio/content_fetchers/base.py @@ -95,6 +95,9 @@ class Fetcher(): @abstractmethod def screenshot_step(self, step_n): + if self.browser_steps_screenshot_path and not os.path.isdir(self.browser_steps_screenshot_path): + logger.debug(f"> Creating data dir {self.browser_steps_screenshot_path}") + os.mkdir(self.browser_steps_screenshot_path) return None @abstractmethod @@ -168,5 +171,8 @@ class Fetcher(): if os.path.isfile(f): os.unlink(f) - def save_step_html(self, param): + def save_step_html(self, step_n): + if self.browser_steps_screenshot_path and not os.path.isdir(self.browser_steps_screenshot_path): + logger.debug(f"> Creating data dir {self.browser_steps_screenshot_path}") + os.mkdir(self.browser_steps_screenshot_path) pass diff --git a/changedetectionio/content_fetchers/playwright.py b/changedetectionio/content_fetchers/playwright.py index 04ab2759..e908ce1c 100644 --- a/changedetectionio/content_fetchers/playwright.py +++ b/changedetectionio/content_fetchers/playwright.py @@ -58,6 +58,7 @@ class fetcher(Fetcher): self.proxy['password'] = parsed.password def screenshot_step(self, step_n=''): + super().screenshot_step(step_n=step_n) screenshot = self.page.screenshot(type='jpeg', full_page=True, quality=int(os.getenv("SCREENSHOT_QUALITY", 72))) if self.browser_steps_screenshot_path is not None: @@ -67,6 +68,7 @@ class fetcher(Fetcher): f.write(screenshot) def save_step_html(self, step_n): + super().save_step_html(step_n=step_n) content = self.page.content() destination = os.path.join(self.browser_steps_screenshot_path, 'step_{}.html'.format(step_n)) logger.debug(f"Saving step HTML to {destination}")