Skip to main content
In a screen session, the browser sends two things on one WebSocket: images of the shared screen, and microphone audio. The agent answers out loud about what it sees.
If you only need an agent on your site, the embed widget already supports screen share.

Before you start

  • An agent. Screen share is on by default.
  • An API key.
  • A token endpoint on your server.
  • An HTTPS page, or localhost. Screen capture does not work on plain HTTP.
Three mistakes break most screen-share apps. None of them shows an error. The socket stays open and the agent never speaks.
  1. Screen capture does not include the microphone. The audio from getDisplayMedia is the computer’s sound, not the user’s voice. You must ask for the microphone separately.
  2. Images alone never get a reply. The agent only takes a turn when it hears speech.
  3. The browser may ignore your audio sample rate. The audio then arrives at the wrong speed and the agent cannot hear it.
The client library handles all three.

Build it with the library

1

Create screen sessions on your server

Use the token endpoint from Voice in the browser. The library adds ?source=screen to the request, and the endpoint passes it on.
2

Start the session

Pass source: "screen" and a <video> element for the preview. The library opens the screen picker, asks for the microphone, and merges the two.
Here is the whole app:
screen.html
The library also watches for the browser’s own Stop sharing button. When the user clicks it, the session ends. To ask the agent about the screen without speaking, call session.sendText("What am I looking at?"). The agent replies right away.

Build it without the library

Read Media format first. The audio rules are strict, and mistakes fail with no error.
1

Get the screen and the microphone

Ask for the screen with audio: false, then ask for the microphone separately. Merge them into one stream.
If the user blocks the microphone, stop and tell them. A session without it never replies.
2

Create the session, then connect

Get the media first, then create the session. The screen picker can stay open for a long time, and the token expires after 60 seconds. If you create the session first, it may expire before the user picks a window.
3

Send images

Draw the video onto a canvas, encode it as JPEG, and send the base64 data. Remove the data:image/jpeg;base64, prefix.
4

Send audio

Send microphone audio on the same socket. The order of audio and images does not matter. The audio code is the same as a voice session. See Voice in the browser.
5

Handle messages

6

Clean up

Stop every stream: the merged one, the screen and the microphone. Otherwise the browser’s sharing bar stays up.

How often the agent sees the screen

The server passes at most one image per second to the agent. If you send more, it keeps the newest one and drops the rest.
  • Sending extra images is safe. It costs bandwidth, but the agent always gets the latest screen.
  • Send one about every second for the freshest view. The library sends one every 2 seconds by default. Set frameIntervalMs: 1000 to match the server.
The agent sees a series of still images, not video. It can read code, a dashboard or a form. It cannot follow a moving cursor or an animation. After the user switches tabs or scrolls, wait a few seconds before asking about the new screen.
The server has no limit on image size or quality. The only hard limit is 16 MiB per WebSocket message. A longest side of 1280 px at quality 0.8 keeps text readable and images small.

Errors you are likely to see

The session stays open after both. See Errors and close codes for the full list.

Turn screen share on or off

Screen share is on by default. Change it with enable_screen_share:
This setting also controls the embed widget’s Share Screen button. When it is off, creating a screen session fails with 403 and code screen_share_disabled. A token created before the change closes with code 4003 when it connects.

Keep a record

Walkthrough and training apps often need the conversation afterwards. Save each final transcript to your own storage as it arrives. Do not wait until the end, or a closed tab loses the session. You can also register a webhook to get the full transcript when the session ends.

Next steps

Media format

The exact audio and image formats.

Troubleshooting

The agent connects but never speaks.