> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cleariflow.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Синхронний скриншот

> Ендпоінт `screenshot` запускає сесію браузера, виконує JavaScript і повертає зображення в base64 в одному синхронному запиті.

## Початок роботи

### Базовий URL

```
https://screenshot.cleariflow.com/v1/screenshot
```

### Приклад запиту

```bash theme={"system"}
curl -X POST 'https://screenshot.cleariflow.com/v1/screenshot' \
  -H 'Content-Type: application/json' \
  -d '{
    "api_key": "YOUR_UNIQUE_API_KEY",
    "url": "https://cleariflow.com",
    "capture_full_page": true,
    "export_format": "jpeg"
  }'
```

Успішний запит повертає скриншот у base64 і метадані:

```json theme={"system"}
{
  "ok": true,
  "image_base64": "/9j/4AAQSkZJRg...",
  "content_type": "image/jpeg",
  "meta": {
    "elapsed_ms": 4521
  }
}
```

Декодуйте `image_base64`, щоб отримати сирі байти JPEG або PNG.

### Параметри рендерингу

Об'єкт `render` керує тим, як браузер завантажує сторінку перед захопленням скриншота. Усі поля необов'язкові — якщо їх не передати, застосовуються серверні значення за замовчуванням.

```json theme={"system"}
{
  "render": {
    "wait_until": "networkidle",
    "timeout_ms": 60000,
    "post_load_wait_ms": 2000,
    "ignore_https_errors": false,
    "full_page": true,
    "screenshot_format": "jpeg",
    "user_agent": "Mozilla/5.0 ...",
    "viewport": {
      "width": 1365,
      "height": 768
    }
  }
}
```

| Поле | Тип | За замовчуванням | Опис |
| - | - | - | - |
| `wait_until` | String | `domcontentloaded` | Коли вважати навігацію завершеною. `domcontentloaded` — швидше; `networkidle` — якщо сторінка догружає дані через XHR/fetch після початкового HTML. |
| `timeout_ms` | Integer | `60000` | Максимальний час очікування завантаження сторінки (мс). |
| `post_load_wait_ms` | Integer | `0` | Додаткова затримка (мс) після `wait_until` перед захопленням. Корисно для анімацій або lazy-load контенту. |
| `ignore_https_errors` | Boolean | `false` | Якщо `true`, ігнорує помилки TLS-сертифіката цільової сторінки. |
| `full_page` | Boolean | `true` | Якщо `true`, захоплює всю прокручувану висоту сторінки. |
| `screenshot_format` | String | `jpeg` | Формат виводу: `jpeg` або `png`. |
| `user_agent` | String | — | Користувацький User-Agent для сесії браузера. |
| `viewport` | Object | `1365×768` | Розмір viewport через `width` і `height` у пікселях. |

### Зручні поля

Ці поля верхнього рівня — аліаси, що об'єднуються в `render` і `actions` для зворотної сумісності та простіших запитів:

| Поле | Відповідає | Опис |
| - | - | - |
| `capture_full_page` | `render.full_page` | Перемикач повносторінкового захоплення. |
| `width` / `height` | `render.viewport` | Розміри viewport у пікселях. |
| `delay` | `render.post_load_wait_ms` | Затримка в **секундах** перед захопленням. |
| `export_format` | `render.screenshot_format` | `jpeg` або `png`. |
| `user_agent` | `render.user_agent` | Користувацький User-Agent. |
| `css_injection` | дія `inject_css` | CSS, що ін'єктується перед захопленням, якщо дія `inject_css` відсутня. |

Приклад із плоскими полями:

```bash theme={"system"}
curl -X POST 'https://screenshot.cleariflow.com/v1/screenshot' \
  -H 'Content-Type: application/json' \
  -d '{
    "api_key": "YOUR_UNIQUE_API_KEY",
    "url": "https://cleariflow.com",
    "width": 1280,
    "height": 720,
    "delay": 2,
    "export_format": "png"
  }'
```

### Параметри ресурсів

Об'єкт `resources` керує типами ресурсів, які браузер завантажує під час захоплення. Блокування важких ресурсів прискорює запити, коли візуальна точність це дозволяє.

```json theme={"system"}
{
  "resources": {
    "block": ["images", "fonts", "media"]
  }
}
```

| Значення | Блокує |
| - | - |
| `images` | Зображення (`<img>`, CSS-фони) |
| `fonts` | Веб-шрифти |
| `media` | Відео- та аудіопотоки |

### Legacy GET-ендпоінт

`GET /v1/` повертає сирі байти зображення (JPEG або PNG) замість JSON. Передавайте параметри як query-рядки:

```
https://screenshot.cleariflow.com/v1/?api_key=YOUR_UNIQUE_API_KEY&url=https://cleariflow.com&capture_full_page=true&export_format=jpeg
```

Підтримувані query-параметри: `url`, `api_key`, `session_id`, `fingerprint`, `capture_full_page`, `width`, `height`, `delay`, `css_injection`, `user_agent`, `export_format`.

### Параметри запиту

**url** `String` *required*

Цільовий URL для захоплення. Має бути публічним HTTP або HTTPS URL. Запити до localhost і приватних IP блокуються SSRF-захистом.

**api\_key** `String` *required*

Ваш унікальний API-ключ.

**session\_id** `String`

Необов'язковий ідентифікатор сесії для повторного використання стану браузера (cookies, local storage) між кількома запитами.

**fingerprint** `String`

Пресет відбитка браузера. Підтримувані значення: `desktop_en_us`, `desktop_ru_ru`, `mobile_en_us`.

**render** `Object`

Параметри рендерингу та захоплення для сесії браузера.

**render.wait\_until** `String`

Коли вважати навігацію завершеною. Значення: `domcontentloaded`, `networkidle`. За замовчуванням: `domcontentloaded`.

**render.timeout\_ms** `Integer`

Максимальний час очікування завантаження сторінки в мілісекундах. За замовчуванням: 60000.

**render.post\_load\_wait\_ms** `Integer`

Додаткова затримка в мілісекундах після події завантаження сторінки перед захопленням.

**render.ignore\_https\_errors** `Boolean`

Якщо `true`, ігнорує помилки TLS-сертифіката цільової сторінки.

**render.full\_page** `Boolean`

Якщо `true`, захоплює всю прокручувану сторінку. За замовчуванням: `true`.

**render.screenshot\_format** `String`

Формат виводу: `jpeg` або `png`. За замовчуванням: `jpeg`.

**render.user\_agent** `String`

Користувацький User-Agent для сесії браузера.

**render.viewport** `Object`

Розмір viewport з `width` і `height` у пікселях.

**resources** `Object`

Керування завантаженням ресурсів.

**resources.block** `Array`

Типи ресурсів для блокування. Підтримувані значення: `images`, `fonts`, `media`.

**actions** `Array`

Впорядкований список дій браузера перед захопленням. Кожна дія — об'єкт із полем `type`.

**actions\[].type** `String` *required*

Тип дії. Підтримувані значення: `wait`, `wait_for`, `click`, `type`, `scroll`, `inject_css`.

**actions\[].selector** `String`

CSS-селектор для дій `wait_for`, `click` або `type`.

**actions\[].text** `String`

Текст для введення в дії `type`.

**actions\[].css** `String`

CSS-рядок для дії `inject_css`.

**actions\[].to** `String`

Ціль прокрутки для дії `scroll` (наприклад, `bottom`).

**actions\[].wait\_ms** `Integer`

Тривалість у мілісекундах для дії `wait`.

**cookies** `Array`

Cookies для ін'єкції перед навігацією. Кожен об'єкт cookie потребує `name` і `value`; необов'язкові поля: `domain`, `path`.

**capture\_full\_page** `Boolean`

Зручний аліас для `render.full_page`.

**width** `Integer`

Зручний аліас для `render.viewport.width`.

**height** `Integer`

Зручний аліас для `render.viewport.height`.

**delay** `Integer`

Затримка в секундах перед захопленням. Перетворюється на `render.post_load_wait_ms`.

**css\_injection** `String`

CSS, що ін'єктується через дію `inject_css`, якщо вона відсутня в `actions`.

**export\_format** `String`

Зручний аліас для `render.screenshot_format`. Значення: `jpeg`, `png`.

### Параметри відповіді

Відповідь API повертається в універсальному легкому [JSON-форматі](https://www.json.org/json-en.html).

**ok** `Boolean`

Чи успішно завершено захоплення скриншота.

**image\_base64** `String`

Дані зображення в base64. Декодуйте для отримання сирих байтів JPEG або PNG.

**content\_type** `String`

MIME-тип зображення (`image/jpeg` або `image/png`).

**meta** `Object`

Метадані захоплення, включно з витраченим часом у мілісекундах.

**error** `Object`

Деталі помилки, коли `ok` дорівнює `false`.


## OpenAPI

````yaml openapi/screenshot.json POST /v1/screenshot
openapi: 3.0.3
info:
  title: Cleariflow Website Screenshot API
  version: 1.0.0
  description: Capture website screenshots via GET or POST.
servers:
  - url: https://screenshot.cleariflow.com
security: []
paths:
  /v1/screenshot:
    post:
      summary: Synchronous screenshot (JSON response with base64 image)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScreenshotRequest'
      responses:
        '200':
          description: Screenshot result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScreenshotResponse'
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '429':
          description: Rate limit exceeded
components:
  schemas:
    ScreenshotRequest:
      type: object
      required:
        - url
      properties:
        url:
          type: string
          format: uri
        api_key:
          type: string
        session_id:
          type: string
        fingerprint:
          type: string
        render:
          $ref: '#/components/schemas/RenderOptions'
        resources:
          $ref: '#/components/schemas/ResourceOptions'
        actions:
          type: array
          items:
            $ref: '#/components/schemas/Action'
        cookies:
          type: array
          items:
            $ref: '#/components/schemas/Cookie'
        capture_full_page:
          type: boolean
          description: Convenience alias for render.full_page
        width:
          type: integer
          description: Convenience alias for render.viewport.width
        height:
          type: integer
          description: Convenience alias for render.viewport.height
        delay:
          type: integer
          description: Delay in seconds; mapped to render.post_load_wait_ms
        css_injection:
          type: string
          description: Injects CSS via inject_css action when not already present
        user_agent:
          type: string
          description: Convenience alias for render.user_agent
        export_format:
          type: string
          enum:
            - jpeg
            - png
          description: Convenience alias for render.screenshot_format
    ScreenshotResponse:
      type: object
      properties:
        ok:
          type: boolean
        image_base64:
          type: string
        content_type:
          type: string
        meta:
          type: object
          additionalProperties: true
        error:
          type: object
          additionalProperties: true
    RenderOptions:
      type: object
      properties:
        wait_until:
          type: string
          enum:
            - domcontentloaded
            - networkidle
        timeout_ms:
          type: integer
        post_load_wait_ms:
          type: integer
        ignore_https_errors:
          type: boolean
        full_page:
          type: boolean
        screenshot_format:
          type: string
          enum:
            - jpeg
            - png
        user_agent:
          type: string
        viewport:
          $ref: '#/components/schemas/ViewportOptions'
    ResourceOptions:
      type: object
      properties:
        block:
          type: array
          items:
            type: string
            enum:
              - images
              - fonts
              - media
    Action:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - wait
            - wait_for
            - click
            - type
            - scroll
            - inject_css
        selector:
          type: string
        text:
          type: string
        attr:
          type: string
        to:
          type: string
        wait_ms:
          type: integer
        css:
          type: string
    Cookie:
      type: object
      required:
        - name
        - value
      properties:
        path:
          type: string
        value:
          type: string
        name:
          type: string
        domain:
          type: string
    ViewportOptions:
      type: object
      properties:
        width:
          type: integer
        height:
          type: integer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.