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.
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.screen.html
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 If the user blocks the microphone, stop and tell them. A session without it never replies.
audio: false, then ask for the microphone separately. Merge them into one stream.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: 1000to match the server.
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 withenable_screen_share:
screen session fails with 403 and code screen_share_disabled. A token created before the change closes with code 4003 when it connects.