# Desktop Screenshot

> Capture desktop screenshot.

Source: https://docs.sommatic.ai/en/nodes/io.desktop.screenshot/

- Slug: `io.desktop.screenshot`
- Family: Input and output
- Version: 1.0.0
- Status: Available
- Execution: async

Capture desktop screenshot.

## Configuration

- `filename` (string, optional): Optional filename to save
- `format` (string, optional): Default: `png`. Allowed values: `png`, `jpg`.

## Output ports

- `out` (default): Screenshot captured
- `error`: Capture failed

## Input contract

- `filename` (string, optional)
- `format` (string, optional)

## Output contract

- `buffer` (object, optional): Base64 or buffer
- `path` (string, optional): Path if saved to file

## In expressions

What a later node can read from this node's output with `$("Desktop Screenshot").item.json.<path>` (write your node's label instead of `Desktop Screenshot`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Desktop Screenshot").item.json.buffer` (object): Base64 or buffer **The worker does not return it: reads as undefined.**
- `$("Desktop Screenshot").item.json.path` (string): Path if saved to file **The worker does not return it: reads as undefined.**
- `$("Desktop Screenshot").item.json.image` (string) = `"data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…"` (Not suggested by the editor)
- `$("Desktop Screenshot").item.json.base64` (string) = `"iVBORw0KGgoAAAANSUhEUgAA..."` (Not suggested by the editor)
- `$("Desktop Screenshot").item.json.timestamp` (string) = `"2026-11-26T15:04:05.000Z"` (Not suggested by the editor)


## How it works

Captures the screen of the machine that runs the worker and returns it as a base64 data URI, or saves it to a file and returns the path.

1. Loads the screenshot module; if it is not installed, leaves through `error`.
2. Resolves the config. `format` (default `png`) and `filename` fall back to the same keys of the incoming payload.
3. With `filename`, saves the capture to that path and returns `{ path, timestamp }`.
4. Without `filename`, returns the image in memory as `{ image, base64, timestamp }`: `image` is a `data:image/png` or `data:image/jpeg` URI and `base64` the raw base64 string.

## In a workflow

### Node

```json
{
  "node_id": "node-capture-screen",
  "label": "Capture screen",
  "operator_slug": "io.desktop.screenshot",
  "operator_version": "1.0.0",
  "config": {
    "format": "png"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
    "base64": "iVBORw0KGgoAAAANSUhEUgAA...",
    "timestamp": "2026-11-26T15:04:05.000Z"
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The screen was captured. The shape depends on `filename` (see the operation).

```json
{
  "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
  "base64": "iVBORw0KGgoAAAANSUhEUgAA...",
  "timestamp": "2026-11-26T15:04:05.000Z"
}
```

### `error`

The screenshot module is missing or the capture failed.

```json
{
  "error": "Module screenshot-desktop not available"
}
```

## Behaviour in the code

- `filename`: Switches the output from an in-memory image to `{ path, timestamp }`. The path is on the host that runs the worker.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Module screenshot-desktop not available` | `error` | The screenshot library is not installed in the runtime that executes the worker. |
| `<capture error message>` | `error` | The host has no display to capture, or the target path for `filename` is not writable. |

## Notes and limits

- The output contract declares `buffer`, but the worker never returns it: use `image` or `base64` (no `filename`) or `path` (with `filename`).
- A full-screen capture in base64 can weigh several megabytes and travels in the run state; prefer `filename` for large screens or many captures.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "io.desktop.screenshot",
  "name": "Desktop Screenshot",
  "category": "io",
  "version": "1.0.0",
  "description": "Capture desktop screenshot.",
  "capabilities": [
    "desktop",
    "screenshot",
    "vision"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "filename": {
        "type": "string",
        "description": "Optional filename to save"
      },
      "format": {
        "type": "string",
        "enum": [
          "png",
          "jpg"
        ],
        "default": "png"
      }
    },
    "required": []
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "filename": {
        "type": "string"
      },
      "format": {
        "type": "string"
      }
    },
    "required": []
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "buffer": {
        "type": "object",
        "description": "Base64 or buffer"
      },
      "path": {
        "type": "string",
        "description": "Path if saved to file"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Image Buffer",
      "description": "Screenshot captured",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Capture failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "desktop-agent"
  ],
  "tags": [
    "desktop",
    "vision"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "filename": {
      "type": "string",
      "description": "Optional filename to save"
    },
    "format": {
      "type": "string",
      "enum": [
        "png",
        "jpg"
      ],
      "default": "png"
    }
  },
  "required": []
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "filename": {
      "type": "string"
    },
    "format": {
      "type": "string"
    }
  },
  "required": []
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "buffer": {
      "type": "object",
      "description": "Base64 or buffer"
    },
    "path": {
      "type": "string",
      "description": "Path if saved to file"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Image Buffer",
    "description": "Screenshot captured",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Capture failed",
    "is_default": false,
    "supports_condition": false
  }
]
```
