diff --git a/aider/gui.py b/aider/gui.py index 7fa90bc38..6c5b012dc 100755 --- a/aider/gui.py +++ b/aider/gui.py @@ -11,7 +11,7 @@ from aider.coders import Coder from aider.dump import dump # noqa: F401 from aider.io import InputOutput from aider.main import main as cli_main -from aider.scrape import Scraper +from aider.scrape import Scraper, has_playwright class CaptureIO(InputOutput): @@ -484,7 +484,7 @@ class GUI: url = self.web_content if not self.state.scraper: - self.scraper = Scraper(print_error=self.info) + self.scraper = Scraper(print_error=self.info, playwright_available=has_playwright()) content = self.scraper.scrape(url) or "" if content.strip(): diff --git a/aider/scrape.py b/aider/scrape.py index 8ab5a93ed..3d5cfa86f 100755 --- a/aider/scrape.py +++ b/aider/scrape.py @@ -14,7 +14,7 @@ aider_user_agent = f"Aider/{__version__} +{urls.website}" # platforms. -def install_playwright(io): +def check_env(): try: from playwright.sync_api import sync_playwright @@ -29,6 +29,16 @@ def install_playwright(io): except Exception: has_chromium = False + return has_pip, has_chromium + + +def has_playwright(): + has_pip, has_chromium = check_env() + return has_pip and has_chromium + + +def install_playwright(io): + has_pip, has_chromium = check_env() if has_pip and has_chromium: return True @@ -262,7 +272,7 @@ def slimdown_html(soup): def main(url): - scraper = Scraper() + scraper = Scraper(playwright_available=has_playwright()) content = scraper.scrape(url) print(content)