From cea6cd65aae0e43ff332ec71977f966d057bd302 Mon Sep 17 00:00:00 2001 From: mike <219478+ilude@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:11:06 -0400 Subject: [PATCH] fix path issue and allow screencap to fail without the ui failing --- app/app.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/app/app.py b/app/app.py index 9715655..63a44cd 100644 --- a/app/app.py +++ b/app/app.py @@ -6,24 +6,22 @@ app = Flask(__name__) +# Create a headless browser instance +options = webdriver.ChromeOptions() +options.add_argument('--headless') +driver = webdriver.Chrome(options=options) + def expand_url(url): try: url = requests.head(url, allow_redirects=True).url - # Create a headless browser instance - options = webdriver.ChromeOptions() - options.add_argument('--headless') - driver = webdriver.Chrome(options=options) - - # Navigate to the URL - driver.get(url) - - # Take a screenshot of the page - driver.save_screenshot('app/assets/screenshot.png') + try: + # Take a screenshot of the page + driver.get(url) + driver.save_screenshot('app/static/screenshots/screenshot.png') + except Exception as e: + return f"Error taking screenshot: {str(e)}" - # Close the browser - driver.quit() - return url except Exception as e: return f"Error expanding URL: {str(e)}"