Ready-to-copy Elixir code for capturing website screenshots, generating PDFs, and processing pages at scale. Uses Req.
The simplest way to capture a screenshot. Just a URL and your API key.
{:ok, resp} = Req.get("https://api.screenshotdev.com/v1/screenshot",
params: [url: "https://example.com", access_key: "YOUR_ACCESS_KEY"]
)
File.write!("screenshot.png", resp.body)Complete working script with options for viewport, format, full page capture, and error handling.
defmodule Screenshot do
@api_key "YOUR_ACCESS_KEY"
@base_url "https://api.screenshotdev.com/v1/screenshot"
def take(url, opts \\ []) do
params = [
url: url,
access_key: @api_key,
format: Keyword.get(opts, :format, "webp"),
width: Keyword.get(opts, :width, 1280),
full_page: Keyword.get(opts, :full_page, false),
dark_mode: Keyword.get(opts, :dark_mode, false)
]
case Req.get(@base_url, params: params) do
{:ok, %{status: 200, body: body}} ->
{:ok, body}
{:ok, %{status: status, body: body}} ->
{:error, "Screenshot failed (#{status}): #{body}"}
{:error, reason} ->
{:error, "Request failed: #{inspect(reason)}"}
end
end
end
{:ok, img} = Screenshot.take("https://example.com", format: "webp", width: 1440, full_page: true)
File.write!("screenshot.webp", img)
IO.puts("Saved screenshot.webp (#{byte_size(img)} bytes)")PDF generation, batch processing, webhooks, CSS/JS injection, and S3 upload.
{:ok, resp} = Req.get("https://api.screenshotdev.com/v1/pdf",
params: [
url: "https://example.com",
access_key: "YOUR_ACCESS_KEY",
format: "a4",
landscape: false,
margin: "20px"
]
)
File.write!("page.pdf", resp.body)urls = [
"https://example.com",
"https://github.com",
"https://news.ycombinator.com"
]
urls
|> Task.async_stream_nolink(fn url ->
{:ok, img} = Screenshot.take(url, format: "webp")
host = URI.parse(url).host
filename = "#{host}.webp"
File.write!(filename, img)
{filename, byte_size(img)}
end, max_concurrency: 5)
|> Enum.each(fn {:ok, {name, size}} ->
IO.puts(" #{name} (#{size} bytes)")
end){:ok, resp} = Req.post("https://api.screenshotdev.com/v1/screenshot",
json: %{
url: "https://example.com",
access_key: "YOUR_ACCESS_KEY",
webhook_url: "https://your-app.com/api/webhooks/screenshot",
format: "webp",
full_page: true
}
)
IO.puts("Job queued: #{resp.body["id"]}"){:ok, resp} = Req.get(@base_url,
params: [
url: "https://example.com",
access_key: @api_key,
inject_css: "body { font-family: 'Inter', sans-serif; } .ad { display: none; }",
inject_js: "document.querySelectorAll('[data-cookie-banner]').forEach(el => el.remove())",
block_ads: true
]
)
File.write!("clean.webp", resp.body)# 1. Capture
{:ok, img} = Screenshot.take("https://example.com", format: "webp")
# 2. Upload with ExAws
ExAws.S3.put_object(
"my-screenshots",
"captures/example-com.webp",
img,
content_type: "image/webp"
)
|> ExAws.request!()Test the API in the interactive playground — pre-filled with Elixir snippets.
Install the HTTP library used in the examples above.
{:req, "~> 0.5"}Uses Req. Any HTTP client that supports GET requests will work.
100 free API calls per month. No credit card. First screenshot in under 30 seconds.