Custom Request Context
Some pages require specific cookies, headers, or authentication tokens to render correctly. This guide covers techniques for capturing authenticated and context-dependent pages.
Why Custom Headers Matter
Common scenarios requiring custom request context:
- Authenticated dashboards — Need session cookies to render user-specific data
- Localized content — Accept-Language header determines which language version renders
- A/B testing — Specific cookies control which variant is shown
- Paywalled content — Subscription tokens unlock premium content
Current SnapAPI Capabilities
SnapAPI currently captures publicly accessible URLs without custom headers. For authenticated content, use one of these workarounds:
Workaround: Public Token URLs
Generate temporary public URLs for the content you need to screenshot:
// Generate a time-limited public URL
const token = jwt.sign({ page: 'dashboard', exp: Date.now() + 300000 }, SECRET);
const publicUrl = `https://yourapp.com/public-view?token=${token}`;
// Screenshot the public URL
const res = await fetch(
`https://apisnap.dev/api/screenshot?url=${encodeURIComponent(publicUrl)}`,
{ headers: { Authorization: `Bearer ${process.env.SNAPAPI_KEY}` } }
);Workaround: Dedicated Screenshot Endpoint
Create a server-side endpoint that renders the page HTML directly, bypassing authentication for the screenshot service's IP range. Include rate limiting and IP validation for security.
Accept-Language for Localization
To capture pages in specific languages, append a locale parameter to the URL if the target site supports it (e.g., ?lang=fr or ?hl=es).