feat: add userAgent parameter for custom User-Agent headers
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled

- Add userAgent?: string to ScreenshotOptions interface
- Implement validation (max 500 chars, no newlines for security)
- Call page.setUserAgent() after page acquisition, before navigation
- Add route handler support for both POST body and GET query
- Add comprehensive test coverage (11 new tests)
- Update OpenAPI documentation with parameter specs and examples
- Update Node.js and Python SDK README examples
- All userAgent tests passing (414 → 425 total tests)

Fixes potential HTTP header injection by rejecting newlines.
Enables custom User-Agent strings for specific browser emulation needs.
This commit is contained in:
SnapAPI Developer 2026-03-05 15:10:06 +01:00
parent a17f492cc3
commit 9290c759da
5 changed files with 313 additions and 0 deletions

View file

@ -83,6 +83,17 @@ const darkScreenshot = await snap.capture({
});
```
### Custom User Agent
```typescript
// Set a custom User-Agent string for the request
const screenshot = await snap.capture({
url: 'https://example.com',
userAgent: 'Mozilla/5.0 (compatible; SnapAPI/1.0)',
format: 'png',
});
```
### Hide Elements Before Capture
```typescript