# Screenshots

> Capture high-quality screenshots of any webpage with the Stack0 SDK.

Capture high-quality screenshots of any webpage with full customization options including viewport, format, and blocking unwanted elements.

## Basic Screenshot

Capture a simple screenshot of any URL:

basic-screenshot.tsCopy

```
import { Stack0 } from '@stack0/sdk' const stack0 = new Stack0({  apiKey: process.env.STACK0_API_KEY!}) // Start screenshot capture (async)const { id, status } = await stack0.screenshots.capture({  url: 'https://example.com',  format: 'png',}) // Poll for completionconst screenshot = await stack0.screenshots.get({ id })console.log('Image URL:', screenshot.imageUrl)
```

## Screenshot and Wait

Capture a screenshot and automatically wait for completion:

screenshot-and-wait.tsCopy

```
// This method handles polling automaticallyconst screenshot = await stack0.screenshots.captureAndWait({  url: 'https://example.com',  format: 'png',  fullPage: true,}, {  pollInterval: 1000, // Check every 1 second (default)  timeout: 60000,     // Timeout after 60 seconds (default)}) console.log('Image URL:', screenshot.imageUrl)console.log('Dimensions:', screenshot.imageWidth, 'x', screenshot.imageHeight)
```

## Screenshot Options

Full list of options for capturing screenshots:

| Option | Type | Description |
| --- | --- | --- |
| url | string | URL to capture (required) |
| format | 'png' \| 'jpeg' \| 'webp' \| 'pdf' | Output format (default: png) |
| quality | number | JPEG/WebP quality 0-100 |
| fullPage | boolean | Capture full page scroll |
| deviceType | 'desktop' \| 'tablet' \| 'mobile' | Device viewport preset |
| viewportWidth | number | Custom viewport width in pixels |
| viewportHeight | number | Custom viewport height in pixels |
| deviceScaleFactor | number | Retina scaling (1-3) |
| selector | string | CSS selector to capture specific element |
| clip | object | Capture specific region (x, y, width, height) |

## Blocking Options

Remove unwanted elements from your screenshots:

blocking-options.tsCopy

```
const screenshot = await stack0.screenshots.captureAndWait({  url: 'https://example.com',  format: 'png',  // Block common annoyances  blockAds: true,  blockCookieBanners: true,  blockChatWidgets: true,  blockTrackers: true,  // Block specific URLs  blockUrls: [    '*analytics*',    '*tracking*',  ],  // Block resource types  blockResources: ['image', 'font'], // Faster loading  // Hide specific elements  hideSelectors: ['.popup', '#banner', '.newsletter-signup'],})
```

## Wait for Content

Wait for dynamic content to load before capturing:

wait-for-content.tsCopy

```
const screenshot = await stack0.screenshots.captureAndWait({  url: 'https://example.com/dashboard',  format: 'png',  // Wait for a specific element to appear  waitForSelector: '.chart-container',  // Or wait a fixed amount of time (ms)  waitForTimeout: 2000,  // Click a button first (useful for modals, tabs, etc.)  clickSelector: '.load-more-button',})
```

## Custom Styles & Scripts

Inject custom CSS or JavaScript before capturing:

custom-styles.tsCopy

```
const screenshot = await stack0.screenshots.captureAndWait({  url: 'https://example.com',  format: 'png',  // Enable dark mode  darkMode: true,  // Inject custom CSS  customCss: `    .ads, .popup { display: none !important; }    body { background: #1a1a1a; }  `,  // Execute JavaScript before capture  customJs: `    document.querySelector('.lazy-load')?.click();    window.scrollTo(0, 500);  `,})
```

## Authentication

Access authenticated pages with custom headers or cookies:

authentication.tsCopy

```
const screenshot = await stack0.screenshots.captureAndWait({  url: 'https://app.example.com/dashboard',  format: 'png',  // Set custom headers  headers: {    'Authorization': 'Bearer your-token',    'X-Custom-Header': 'value',  },  // Or set cookies  cookies: [    { name: 'session', value: 'abc123', domain: 'app.example.com' },    { name: 'auth_token', value: 'xyz789' },  ],  // Custom user agent  userAgent: 'CustomBot/1.0',})
```

## Batch Screenshots

Capture multiple URLs in a single batch job:

batch-screenshots.tsCopy

```
// Start a batch jobconst batch = await stack0.screenshots.batch({  urls: [    'https://example.com',    'https://example.org',    'https://example.net',  ],  config: {    format: 'png',    fullPage: true,    blockAds: true,  },}) console.log('Batch ID:', batch.id)console.log('Total URLs:', batch.totalUrls) // Wait for completion with progress updatesconst completedJob = await stack0.screenshots.batchAndWait({  urls: ['https://example.com', 'https://example.org'],  config: { format: 'png' },}, {  pollInterval: 2000,  timeout: 300000, // 5 minutes}) console.log(`Completed: ${completedJob.successfulUrls} success, ${completedJob.failedUrls} failed`)
```

## Scheduled Screenshots

Create recurring screenshot schedules with change detection:

scheduled-screenshots.tsCopy

```
// Create a schedule for daily screenshotsconst schedule = await stack0.screenshots.createSchedule({  name: 'Daily homepage capture',  url: 'https://example.com',  frequency: 'daily', // 'hourly' | 'daily' | 'weekly' | 'monthly'  config: {    format: 'png',    fullPage: true,    blockAds: true,  },  // Detect visual changes between runs  detectChanges: true,  changeThreshold: 5, // % change to trigger notification  // Webhook notification  webhookUrl: 'https://your-app.com/webhook',}) // Toggle schedule on/offawait stack0.screenshots.toggleSchedule({ id: schedule.id }) // List all schedulesconst { items } = await stack0.screenshots.listSchedules({  isActive: true,})
```

## List & Manage Screenshots

Query and manage your screenshots:

manage-screenshots.tsCopy

```
// List screenshots with filtersconst { items, nextCursor } = await stack0.screenshots.list({  status: 'completed',  limit: 20,}) for (const screenshot of items) {  console.log(`[${screenshot.status}] ${screenshot.url}`)  console.log(`  Image: ${screenshot.imageUrl}`)  console.log(`  Size: ${screenshot.imageWidth}x${screenshot.imageHeight}`)} // Get a specific screenshotconst screenshot = await stack0.screenshots.get({ id: 'screenshot-id' }) // Delete a screenshotawait stack0.screenshots.delete({ id: 'screenshot-id' })
```

## Caching

Enable caching to avoid redundant screenshots:

caching.tsCopy

```
const screenshot = await stack0.screenshots.captureAndWait({  url: 'https://example.com',  format: 'png',  // Use a cache key to deduplicate requests  cacheKey: 'homepage-desktop',  // Cache TTL in seconds (default: 3600)  cacheTtl: 86400, // 24 hours}) // Same cacheKey within TTL returns cached result instantlyconst cached = await stack0.screenshots.captureAndWait({  url: 'https://example.com',  format: 'png',  cacheKey: 'homepage-desktop',}) // Returns immediately with cached result
```

### Related

[AI Extraction](https://www.stack0.dev/docs/sdk/extraction)[Screenshot API Reference](https://www.stack0.dev/docs/api-reference/screenshots)[Error Handling](https://www.stack0.dev/docs/errors)

---

Source: https://www.stack0.dev/docs/sdk/screenshots
llms.txt: https://www.stack0.dev/llms.txt
Sitemap: https://www.stack0.dev/sitemap.xml
Documentation: https://www.stack0.dev/docs
OpenAPI spec: https://www.stack0.dev/openapi.json
MCP server: https://api.stack0.dev/mcp
