File size: 4,198 Bytes
a4a8647
 
 
 
 
 
 
 
 
 
0b2f2ef
a4a8647
0b2f2ef
a4a8647
0b2f2ef
bf310a8
0b2f2ef
 
 
a4a8647
0b2f2ef
a4a8647
0b2f2ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4a8647
 
0b2f2ef
 
 
 
a4a8647
 
 
0b2f2ef
a4a8647
0b2f2ef
 
 
 
 
 
 
a4a8647
0b2f2ef
a4a8647
0b2f2ef
a4a8647
0b2f2ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
---

title: Page Screenshot API
emoji: πŸ“Έ
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
---


# πŸ“Έ Page Screenshot API

Professional web page screenshot service built with Node.js and Puppeteer, optimized for Hugging Face Spaces.

## πŸš€ Live Demo

- **API Endpoint**: `https://your-username-page-shot.hf.space/screenshot`
- **Demo Interface**: `https://your-username-page-shot.hf.space/demo`
- **Health Check**: `https://your-username-page-shot.hf.space/`

## πŸ” Access Control

This API uses **Hugging Face system-level authentication**:

### Public Spaces
- Open access for all users
- Rate limited to 100 requests per 15 minutes
- Perfect for demos and testing

### Private Spaces
- Requires valid Hugging Face access token
- Access controlled by HF platform automatically
- Higher security for production use

## πŸ“– API Usage

### Public Space Access
```bash

curl -X POST https://your-space.hf.space/screenshot \

  -H "Content-Type: application/json" \

  -d '{"url": "https://example.com", "width": 1280, "height": 720}' \

  --output screenshot.jpg

```

### Private Space Access
```bash

curl -X POST https://your-space.hf.space/screenshot \

  -H "Content-Type: application/json" \

  -H "Authorization: Bearer hf_your_token_here" \

  -d '{"url": "https://example.com", "width": 1280, "height": 720}' \

  --output screenshot.jpg

```

### JavaScript Example
```javascript

const response = await fetch('https://your-space.hf.space/screenshot', {

  method: 'POST',

  headers: {

    'Content-Type': 'application/json',

    // Add this line only for private spaces:

    // 'Authorization': 'Bearer hf_your_token_here'

  },

  body: JSON.stringify({

    url: 'https://example.com',

    width: 1280,

    height: 720,

    quality: 80

  })

});



const imageBlob = await response.blob();

```

## πŸ“Š Parameters

| Parameter | Type | Default | Range | Description |
|-----------|------|---------|-------|-------------|
| `url` | string | **required** | - | Target webpage URL |
| `width` | number | 1280 | 100-1600 | Screenshot width in pixels |
| `height` | number | 720 | 100-1200 | Screenshot height in pixels |
| `quality` | number | 75 | 10-100 | JPEG quality percentage |

## πŸ”„ Response Examples

### Success Response
```

HTTP/1.1 200 OK

Content-Type: image/jpeg

Content-Length: 245760



[Binary JPEG data]

```

### Error Response
```json

{

  "error": "Failed to capture screenshot",

  "message": "Navigation timeout exceeded"

}

```

### Server Busy Response
```json

{

  "status": "busy",

  "error": "Server is currently overloaded",

  "cpuUsage": "96%",

  "queueLength": 3

}

```

## πŸ› οΈ Features

- βœ… **Queue Management** - Handles concurrent requests efficiently
- βœ… **CPU Monitoring** - Automatic load balancing
- βœ… **Rate Limiting** - Prevents abuse
- βœ… **HF Authentication** - Integrated with HuggingFace platform
- βœ… **Error Handling** - Comprehensive error responses
- βœ… **Demo Interface** - Built-in testing UI
- βœ… **Health Monitoring** - Status endpoint for monitoring

## πŸ“ˆ Monitoring

### Health Check
```bash

curl https://your-space.hf.space/

```

### Server Status
```bash

curl https://your-space.hf.space/status

```

## 🚨 Rate Limits

| Space Type | Requests | Window |
|------------|----------|--------|
| Public | 100 | 15 minutes |
| Private | 100 | 15 minutes |

## πŸ”§ Deployment

This application is optimized for Hugging Face Spaces with:
- Docker-based deployment
- Automatic dependency management
- Resource-efficient Chrome configuration
- Built-in security features
- HuggingFace platform integration

## πŸ”’ Security Notes

- **Private Spaces**: Access automatically controlled by HF platform
- **Public Spaces**: Open access with rate limiting
- **No API keys needed**: Authentication handled by HuggingFace
- **Secure by design**: Follows HF Spaces best practices

## πŸ“„ License

Proprietary - Commercial use requires license. See [LICENSE](LICENSE) for details.

## 🀝 Support

For technical support or questions, please contact the administrator.