A demonstration of file download automation using Kernel cloud browsers with Playwright and Chrome DevTools Protocol (CDP).
This example shows how to automate downloading files from websites using Kernel's remote browser infrastructure, then retrieve those files from the cloud browser's filesystem to your local machine.

This script automates a receipt download workflow:
- Creates a remote browser session via Kernel
- Navigates to a parking receipt lookup page
- Fills out a form with email and order number
- Downloads a PDF receipt
- Retrieves the file from the remote browser filesystem
- Streams it to your local
./downloads/directory
The demo combines three key technologies:
- Kernel: Provides cloud-hosted browsers accessible via API
- Playwright: Automates browser interactions (form filling, clicking, navigation)
- CDP (Chrome DevTools Protocol): Handles file download tracking and retrieval
File Download Handling via CDP
Unlike standard Playwright download handling, this demo uses CDP to:
- Set download behavior on the remote browser (
Browser.setDownloadBehavior) - Track download events (
Browser.downloadWillBegin,Browser.downloadProgress) - Access files in the remote filesystem via Kernel's file API
Streaming File Transfer
Files are streamed from the remote browser to local disk using client.browsers.fs.read_file() and write_to_file(), avoiding loading large files into memory.
- Python 3.11 or higher
- uv package manager
- A Kernel API key (sign up at onkernel.com)
- Clone this repository:
git clone <your-repo-url>
cd file-io-demo- Install dependencies using uv:
uv sync- Create a
.envfile in the project root:
KERNEL_API_KEY=your_api_key_here
OPENAI_API_KEY=your_openai_api_key_hereRun the automation script:
python main.pyThe script will:
- Print the Kernel browser live view URL (watch the automation in real-time)
- Navigate through the demo site
- Download the receipt
- Save it to
./downloads/
To adapt this for your own website automation:
-
Update the configuration variables in
main.py:WEBSITE_URL = "your-website-url" EMAIL = "your-email" ORDER_NUMBER = "your-order-number" DOWNLOAD_DIR = "/tmp/downloads"
-
Modify the Playwright selectors to match your target website's HTML structure
-
Adjust the CDP event handlers if needed for different download patterns
main.py- Main automation script with download logicsession.py- CustomBrowserSessionsubclass that fixes viewport resizing when connecting via CDPpyproject.toml- Project dependencies and configuration.env- Environment variables (API keys)
Type checking:
mypy .This project is licensed under the MIT License - see the LICENSE file for details.