Browser Automation
Reliable Chrome and Selenium startup, execution and cleanup across every request, including failure paths.
A production-ready website screenshot service built with Flask, Selenium and Headless Chrome, designed for authenticated and configurable browser capture.
The project is a secure screenshot automation API capable of capturing websites from URLs with configurable viewport and device presets, PNG/JPG output formats, custom headers, cookies, user-agent strings, capture delay, full-page capture and dark mode — all behind API-key authentication.
Reliable browser screenshot automation involves much more than simply loading a URL. Browser lifecycle, responsive dimensions, HTTP customization, rendering time and output handling must all work consistently.
Reliable Chrome and Selenium startup, execution and cleanup across every request, including failure paths.
Handling predefined viewport sizes that accurately represent different devices and screen widths.
Support for custom headers, cookies and user-agent configuration so authenticated or restricted pages can be captured.
Error handling, guaranteed browser cleanup and predictable API responses under real production load.
{
"url": "https://example.com",
"device": "laptop",
"format": "png",
"full_page": true,
"dark_mode": false,
"delay_ms": 1500
}
{
"success": true,
"data": {
"request_id": "...",
"duration_ms": "...",
"screenshot": {
"width": "...",
"height": "...",
"format": "png"
}
}
}
Every request creates browser resources that must be cleaned up correctly even when capture fails.
Use controlled driver initialization and guaranteed browser cleanup after screenshot processing.
Normal viewport screenshots do not capture content below the visible browser area.
Support full-page capture by adjusting browser dimensions based on page content before capture.
Some websites require specific HTTP headers, authenticated cookies or custom browser identity.
Apply request headers through Chrome DevTools Protocol and inject cookies/browser configuration before capture.
Browser screenshot output is naturally PNG while clients may require JPG/JPEG.
Use image processing to safely convert screenshot output into the requested image format.
Automated browser processes can leave resources behind when failures occur.
Use structured exception handling, predictable API responses and driver cleanup.
The final API provides authenticated website screenshot generation with responsive viewport presets, configurable browser requests, multiple image formats and controlled browser automation.