CallMeFred
Issue with Browserless template
This is the start of the function:
def screenshot_url(url, output_path='screenshot.png'):
# Set up Chrome options for headless browsing
chrome_options = Options()
chrome_options.set_capability('browserless:token', os.getenv('BROWSER_TOKEN'))
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument("--disable-background-timer-throttling")
chrome_options.add_argument("--disable-backgrounding-occluded-windows")
chrome_options.add_argument("--disable-breakpad")
chrome_options.add_argument("--disable-component-extensions-with-background-pages")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-features=TranslateUI,BlinkGenPropertyTrees")
chrome_options.add_argument("--disable-ipc-flooding-protection")
chrome_options.add_argument("--disable-renderer-backgrounding")
chrome_options.add_argument("--enable-features=NetworkService,NetworkServiceInProcess")
chrome_options.add_argument("--force-color-profile=srgb")
chrome_options.add_argument("--hide-scrollbars")
chrome_options.add_argument("--metrics-recording-only")
chrome_options.add_argument("--mute-audio")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
# Initialize the browser
try:
driver = webdriver.Remote(
command_executor=os.getenv('BROWSER_WEBDRIVER_ENDPOINT'),
options=chrome_options
)
except Exception as e:
print(f"Error initializing WebDriver: {e}")
return
18 replies