Examples
OG Image Generation
Generate Open Graph images for social media sharing:
const og = await client.screenshot({
html: `
<div style="width:1200px;height:630px;display:flex;align-items:center;
justify-content:center;background:linear-gradient(135deg,#0f172a,#1e293b);
color:white;font-family:system-ui;">
<div style="text-align:center;">
<h1 style="font-size:48px;margin:0;">My Blog Post Title</h1>
<p style="font-size:24px;color:#94a3b8;">Published on March 13, 2026</p>
</div>
</div>
`,
viewport: { width: 1200, height: 630 },
format: "png",
});
PDF Invoice
Generate PDF invoices from HTML:
const invoice = await client.pdf({
html: `
<style>
body { font-family: system-ui; padding: 40px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; border-bottom: 1px solid #e2e8f0; text-align: left; }
</style>
<h1>Invoice #1234</h1>
<p>Date: March 13, 2026</p>
<table>
<tr><th>Item</th><th>Qty</th><th>Price</th></tr>
<tr><td>API Credits</td><td>1000</td><td>$29.00</td></tr>
</table>
<p><strong>Total: $29.00</strong></p>
`,
format: "Letter",
margin: { top: "2cm", bottom: "2cm", left: "2cm", right: "2cm" },
});
Website Monitoring
Take periodic screenshots for visual regression testing:
// Capture multiple pages
const pages = [
"https://myapp.com/",
"https://myapp.com/dashboard",
"https://myapp.com/settings",
];
const results = await Promise.all(
pages.map((url) =>
client.screenshot({
url,
format: "png",
fullPage: true,
blockAds: true,
blockCookieBanners: true,
})
)
);
Dark Mode Screenshots
Capture a page in both light and dark mode:
const [light, dark] = await Promise.all([
client.screenshot({ url: "https://example.com", darkMode: false }),
client.screenshot({ url: "https://example.com", darkMode: true }),
]);
Mobile Screenshots
Use device presets for mobile screenshots:
const mobile = await client.screenshot({
url: "https://example.com",
device: "mobile",
format: "png",
});
Python Example
import requests
API_KEY = "sk_live_xxx"
BASE_URL = "https://api.rendershot.dev/v1"
def take_screenshot(url, format="png", full_page=False):
response = requests.post(
f"{BASE_URL}/screenshot",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"url": url,
"format": format,
"full_page": full_page,
"block_ads": True,
"block_cookie_banners": True,
},
)
response.raise_for_status()
return response.content
# Usage
image = take_screenshot("https://example.com")
with open("screenshot.png", "wb") as f:
f.write(image)
Go Example
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func takeScreenshot(url string) error {
payload, _ := json.Marshal(map[string]interface{}{
"url": url,
"format": "png",
"block_ads": true,
"block_cookie_banners": true,
})
req, _ := http.NewRequest("POST",
"https://api.rendershot.dev/v1/screenshot",
bytes.NewBuffer(payload))
req.Header.Set("Authorization", "Bearer sk_live_xxx")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
body, _ := io.ReadAll(resp.Body)
return fmt.Errorf("API error %d: %s", resp.StatusCode, body)
}
file, _ := os.Create("screenshot.png")
defer file.Close()
_, err = io.Copy(file, resp.Body)
return err
}