A scalable architecture for browser automation using Playwright and VNC for visual debugging.
- TypeScript-based architecture
- Page Object Model design pattern
- Docker containerization with VNC support
- Configurable browser settings
- Logging utilities
- Credential management
- Node.js (v14 or later)
- Docker and Docker Compose (for containerized execution)
- VNC Viewer (for visual debugging)
-
Install dependencies:
npm install
-
Create a configuration file:
cp config.json.example config.json
-
Edit the
config.json
file with your credentials and settings. -
Run a script:
npm start
-
Build and start the container:
docker-compose up --build
-
Access the browser via web interface:
- Open your web browser
- Navigate to
http://localhost:8080
- You'll see the browser running in your web browser
-
Alternatively, connect via a VNC client:
- Open your VNC viewer
- Connect to
localhost:5900
- No password is required
-
Build and start the lightweight container:
npm run docker:build:light npm run docker:up:light
-
Access the browser via web interface:
- Open your web browser
- Navigate to
http://localhost:8081
- You'll see the browser running in your web browser
-
Alternatively, connect via a VNC client:
- Open your VNC viewer
- Connect to
localhost:5901
- No password is required
browser-automation-arch/
├── src/
│ ├── core/ # Core browser management
│ ├── pages/ # Page Object Models
│ ├── types/ # TypeScript type definitions
│ └── utils/ # Utilities (logging, config, etc.)
├── scripts/ # Automation scripts
├── data/ # Data storage
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── docker-entrypoint.sh # Docker entry point script
├── tsconfig.json # TypeScript configuration
├── package.json # Node.js dependencies
└── config.json # Application configuration
- Create a new file in the
src/pages
directory - Extend the
BasePage
class - Define selectors and methods for interacting with the page
Example:
import { Page } from 'playwright';
import { BasePage } from './base-page';
export class MyNewPage extends BasePage {
// Selectors
private myButtonSelector = 'button.my-button';
constructor(page: Page) {
super(page);
}
async clickMyButton(): Promise<void> {
await this.page.click(this.myButtonSelector);
}
}
- Create a new file in the
scripts
directory - Import the necessary classes and utilities
- Implement your automation logic
This project can be deployed to Hugging Face Spaces:
-
Create a new Space on Hugging Face:
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Select "Docker" as the Space SDK
- Give your Space a name (e.g., "browser-automation-demo")
- Set visibility (public or private)
- Click "Create Space"
-
Push your code to the Space:
git remote add space https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME git push --force space main
-
Hugging Face will automatically build and deploy your Docker container.
This project can also be deployed to Railway:
-
Create a new project on Railway:
- Go to https://railway.app/
- Sign up or log in
- Click "New Project"
- Select "Deploy from GitHub repo"
-
Connect your GitHub repository and deploy.
MIT