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

# Keyboard Type

> Type text into the currently focused element or a specific selector, with optional clear-first behavior.

## Overview

Dispatches real keydown+keyup events one character at a time against the active page of a browser session. Works with any focused input — if `selector` is provided, the target element is focused (and optionally cleared) before typing.

## Path Parameters

<ParamField path="id" type="string" required={true}>
  Browser session ID (UUID).
</ParamField>

## Body

<ParamField body="text" type="string" required={true}>
  Text to type. UTF-8 supported. Each character fires a native keydown+keyup pair so input/change/autocomplete listeners run.
</ParamField>

<ParamField body="selector" type="string">
  Optional CSS selector to focus before typing. When omitted, keystrokes go to whatever element is currently focused.
</ParamField>

<ParamField body="timeout" type="integer" default="5000">
  How long to wait (ms) for the selector to become visible. Ignored when no selector is given.
</ParamField>

<ParamField body="clear" type="boolean" default="false">
  When true, clears the field's current value before typing. Safe default is `false` so typing appends.
</ParamField>

<ParamField body="delay" type="integer" default="40">
  Base inter-key delay in milliseconds. Capped at 5000.
</ParamField>

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.scrapengine.io/api/v1/browser/sessions/0f2b1f6a-88ac-4d25-bc58-67a6f4b4a001/keyboard/type" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "selector": "#email",
      "text": "alice@example.com",
      "clear": true
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    "https://api.scrapengine.io/api/v1/browser/sessions/.../keyboard/type",
    {
      method: "POST",
      headers: {
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        selector: "#email",
        text: "alice@example.com",
        clear: true,
      }),
    },
  );
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.scrapengine.io/api/v1/browser/sessions/.../keyboard/type",
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
      },
      json={
          "selector": "#email",
          "text": "alice@example.com",
          "clear": True,
      },
  )
  ```
</CodeGroup>

## Response

### Success Response (200)

<ResponseField name="success" type="boolean">
  True when the keystrokes were dispatched successfully.
</ResponseField>

<ResponseField name="charactersTyped" type="integer">
  Number of characters (UTF-8 code points) dispatched.
</ResponseField>

**Example Response:**

```json theme={null}
{
  "success": true,
  "charactersTyped": 18
}
```

### Error Responses

| Status | Description                                                           |
| ------ | --------------------------------------------------------------------- |
| `400`  | Invalid body — missing text, delay out of range, bad parameters.      |
| `401`  | Unauthorized — invalid or missing API key.                            |
| `404`  | Session not found, or selector did not become visible before timeout. |
| `503`  | The browser session is temporarily unreachable.                       |

## Notes

* **Composed input is not supported.** CJK dead-key composition, emoji composition sequences, and similar composed input are typed character-by-character, not as composition events.
* **Existing value is preserved unless `clear: true`.** Typing appends to the field's current value. Set `clear: true` to overwrite.
* **Shadow-root and iframe targets aren't addressable.** If the element is inside a shadow root or cross-origin iframe, the selector must match the shadow host or the endpoint will return 404.
