# Video Recording Feature for TradingView Automation

This feature allows you to record videos of the browser automation process for debugging and monitoring purposes.

## Environment Variables

- `TRADINGVIEW_DEBUG=true` - Enable debug mode (shows browser window locally, enables video recording)
- `TRADINGVIEW_RECORD_VIDEO=true` - Explicitly enable video recording
- `DOCKER_ENV=true` - Automatically detected in Docker containers

## Usage Examples

### Local Development with Live Browser Window
```bash
TRADINGVIEW_DEBUG=true node test-video-recording.js
```
This will:
- Show the browser window in real-time
- Slow down actions (250ms delay)
- Open DevTools
- Take debug screenshots
- Record video if TRADINGVIEW_RECORD_VIDEO=true

### Local Development with Video Recording
```bash
TRADINGVIEW_DEBUG=true TRADINGVIEW_RECORD_VIDEO=true node test-video-recording.js
```
This will do everything above plus save MP4 videos to the `videos/` directory.

### Docker Container Mode
```bash
DOCKER_ENV=true node test-video-recording.js
```
This will:
- Run in headless mode (required for Docker)
- Use Docker-optimized browser arguments
- Take debug screenshots
- Record video if TRADINGVIEW_RECORD_VIDEO=true

### Production Mode with Video Recording
```bash
TRADINGVIEW_RECORD_VIDEO=true node your-script.js
```

## File Locations

- **Screenshots**: `screenshots/` directory
- **Videos**: `videos/` directory
- **Debug Screenshots**: Automatically named with timestamps and step descriptions

## Video Settings

- **FPS**: 10 (optimized for Docker)
- **Quality**: 50% (smaller file sizes)
- **Aspect Ratio**: 16:9
- **Format**: MP4

## Docker Considerations

When running in Docker containers:
1. The browser runs in headless mode only
2. Video recording works but files are saved inside the container
3. Mount volumes to access videos: `-v $(pwd)/videos:/app/videos`
4. Ensure sufficient memory for video encoding

## Troubleshooting

### Video Recording Not Working
1. Check if `puppeteer-screen-recorder` is installed
2. Ensure you have sufficient disk space
3. In Docker, check memory limits

### Browser Not Showing Locally
1. Ensure `TRADINGVIEW_DEBUG=true` is set
2. Check if you're running in Docker mode
3. Verify X11 forwarding if using SSH

### Performance Issues
1. Reduce video quality in the code
2. Lower FPS settings
3. Increase Docker memory limits
4. Use SSD storage for video files
