# Let readers try WebSocket channels

The **Try it** button on a WebSocket channel opens Replay.
In Replay, readers connect from their browser straight to your server, send the channel's messages, and read the replies.
Because the browser connects directly, the connection works only when your description, your server, and your project allow it.

**Early access**

This is a feature in early access.
It may not be available for your organization yet, and its behavior may change before general availability.

To request access to this feature, contact our [Support team](mailto:team@redocly.com).

## Display the Try it button on WebSocket channels

A channel displays the **Try it** button when your description says that the channel uses WebSocket:

- One of the channel's servers uses the `ws` or `wss` protocol.
  A channel that lists no servers uses every server of the description.
- The description declares no servers, and the channel has a `ws` binding.
  Readers then enter the server address in Replay.

The channel also needs at least one message with a payload or an example.
Other channels, such as Kafka or AMQP channels, have no **Try it** button.

The following example declares a WebSocket channel with one message in a description without servers:

```yaml
channels:
  liveOrders:
    address: /orders/live
    bindings:
      ws: {}
    messages:
      orderReady:
        payload:
          type: object
          properties:
            orderId:
              type: string
```

## Let the browser connect

- Declare the server with `protocol: wss`.
  Browsers block `ws://` connections from docs pages served over HTTPS.
- If your server checks the `Origin` header, allow every domain that serves your docs, including [preview deployments](/docs/platform/project/use-previews).
- If your project sends a `Content-Security-Policy` header, add your server to its `connect-src` directive.

## Declare credentials a browser can send

In a browser, Replay can set only the address and the subprotocols of a WebSocket connection.
It cannot add other headers, cookies, or client certificates.
Declare the credential in one of these forms, and list it in the `security` of your `wss` server or of the channel's operations:

- An API key in the query: a security scheme with `type: httpApiKey` and `in: query`.
- A token sent as a subprotocol: a security scheme with `type: httpApiKey`, `in: header`, and `name: Sec-WebSocket-Protocol`.
  The browser sends subprotocols in the `Sec-WebSocket-Protocol` header.

The following example lets readers connect with either credential:

```yaml
servers:
  production:
    host: live.cafe.example.com
    protocol: wss
    security:
      - $ref: '#/components/securitySchemes/queryKey'
      - $ref: '#/components/securitySchemes/subprotocolToken'
components:
  securitySchemes:
    queryKey:
      type: httpApiKey
      in: query
      name: api_key
    subprotocolToken:
      type: httpApiKey
      in: header
      name: Sec-WebSocket-Protocol
```

## Give each message an example

Replay fills its message editor with the first example of the message the reader picks.
Without an example, Replay generates a payload from the message schema.
Add an example with a `payload` to each message that readers send, so they start from realistic values.

## Hide the Try it button

- On every channel: set the [`hideReplay` option](/docs/platform/config/asyncapi/hide-replay) under `asyncapi` in `redocly.yaml`.
- On one channel: add the [`x-hideReplay` extension](/docs/platform/content/api-docs/asyncapi-extensions/x-hide-replay) to the channel.

## Resources

- **[hideReplay for AsyncAPI](/docs/platform/config/asyncapi/hide-replay)** - Hide the **Try it** button on every channel
- **[x-hideReplay for AsyncAPI](/docs/platform/content/api-docs/asyncapi-extensions/x-hide-replay)** - Hide the **Try it** button on one channel
- **[Response headers](/docs/platform/config/response-headers)** - Set a `Content-Security-Policy` header for your project
- **[Add AsyncAPI descriptions](/docs/platform/content/api-docs/add-asyncapi-docs)** - Add AsyncAPI reference documentation to your project
