Capture screenshots in Swift
Add screenshot and scrolling GIF capabilities to your Swift applications with native URLSession. No WebKit complexity, no headless browsers to manage.
Installation
- 1No external dependencies — uses Foundation URLSession
- 2Get your API key from the dashboard
- 3Set the X-KEY header in your URLRequest
Authentication
Include your API key in the X-KEY header with every request:
var request = URLRequest(url: url)
request.setValue("your-api-key", forHTTPHeaderField: "X-KEY")Swift Screenshot Example
Capture a screenshot or create a scrolling GIF animation with a simple GET request:
import Foundation
let url = URL(string: "https://api.scrnpix.com/screenshot?url=https%3A%2F%2Fexample.com&width=1280&height=720&format=png")!
var request = URLRequest(url: url)
request.setValue("your-api-key", forHTTPHeaderField: "X-KEY")
let (data, _) = try await URLSession.shared.data(for: request)
try data.write(to: URL(fileURLWithPath: "screenshot.png"))import Foundation
let url = URL(string: "https://api.scrnpix.com/animate?url=https%3A%2F%2Fexample.com&scroll_duration=3000&scroll_easing=ease-in-out")!
var request = URLRequest(url: url)
request.setValue("your-api-key", forHTTPHeaderField: "X-KEY")
let (data, _) = try await URLSession.shared.data(for: request)
try data.write(to: URL(fileURLWithPath: "animation.gif"))Response Format
On success, the API returns the image binary data directly in the response body.
| Status Code | 200 OK |
| Content-Type | image/png, image/jpeg, or image/gif |
| Body | Binary image data (Data) |
| Error Response | Error message with 4xx/5xx status |
Key Features
Zero Setup
No need to configure WebKit or manage browser instances. Just use the native URLSession API.
Production Ready
Built on Cloudflare Workers with global edge network. Handles concurrency and browser lifecycle automatically.
Swift Integration
Native async/await support. Integrates seamlessly with SwiftUI, UIKit, Vapor, or any Swift framework.
Rich Features
Custom viewport sizes, full page capture, PNG/JPEG formats, scrolling GIFs with 15 easing functions.
Frequently Asked Questions
Do I need to install any browser dependencies for Swift?
No. Scrnpix runs browsers on our infrastructure. You only need Foundation's URLSession to make HTTP calls.
Can I use this with SwiftUI or Vapor?
Yes. Scrnpix works with any Swift environment — iOS, macOS, tvOS, watchOS apps, or server-side Swift with Vapor.
How do I handle errors in Swift?
Check the HTTPURLResponse status code. A 200 status means success with image data in the body. Use Swift's do-try-catch for error handling.
What Swift version is required?
Swift 5.5+ is recommended for async/await support. The API is a simple HTTP GET request.
Ready to capture screenshots in Swift?
Get your API key and start rendering screenshots in seconds. Free tier includes 50 screenshots per month.
Start Free