How to record the screen in your web app and upload it
To record the screen in a web app and upload it, capture it with the browser's screen capture API and stream the recording to storage as it's made. @rendermate/recorder does both: it records the screen, camera and microphone as separate tracks, uploads each one while it's recording, and saves every track as an asset in your rendermate workspace. The page never holds your API key. Your backend gives it short-lived upload tokens, which can only write under a prefix you choose.
1. Install the SDK
npm install @rendermate/recorder
2. Give the page upload tokens from your backend
Add an endpoint that checks who's asking, then makes an upload token with your API key. Give each person their own prefix, so their token can only write recordings under it. A token lasts 15 minutes unless you set expires_in (60 to 86400 seconds), records at most max_size bytes per file, and never replaces an existing asset.
// app/api/upload-token/route.ts
export async function POST() {
const user = await currentUser(); // your own auth
const response = await fetch("https://api.rendermate.com/v1/upload-tokens", {
method: "POST",
headers: {
authorization: `Bearer ${process.env.RENDERMATE_API_KEY}`,
"content-type": "application/json",
},
body: JSON.stringify({prefix: `recordings/${user.id}/`, max_size: 10 * 1024 ** 3}),
});
return Response.json(await response.json()); // {token, prefix, max_size, project_id, expires_at}
}3. Record in the page
import {createRecorder, resumeUnfinished} from "@rendermate/recorder";
const getUploadToken = () => fetch("/api/upload-token", {method: "POST"}).then((r) => r.json());
const recorder = createRecorder({
getUploadToken,
sources: {screen: {audio: true}, camera: true, microphone: true},
});
recorder.on("progress", ({track, phase, done, total}) => console.log(track, phase, done / total));
// Browsers only let a page capture the screen in answer to a click.
startButton.onclick = () => recorder.start();
stopButton.onclick = async () => {
const assets = await recorder.stop();
// [{track: "screen", asset: {name, sha256, size, …}}, {track: "camera", asset: {…}}]
};
// On page load: upload what a closed or crashed tab left behind.
await resumeUnfinished({getUploadToken});recorder.streams.screen and recorder.streams.camera are the live streams, for a preview in a <video>. pause() and resume() pause every track. The SDK calls getUploadToken again whenever a token expires.
What gets uploaded
Each source is its own track and its own asset; nothing is composited, so you can lay out the screen and camera however you like later.
| Track | What it holds |
|---|---|
screen | What it holdsThe screen, a window or a tab, with the tab's or system's audio when screen.audio is set. Without a camera, the microphone is mixed in |
camera | What it holdsThe camera, with the microphone |
microphone | What it holdsThe microphone alone, when there's neither a screen nor a camera |
Assets are named <prefix><recording id>/<track>.<extension>, such as recordings/u_42/rec_mx6sj6yh2s3m5u/screen.mp4; pass name to createRecorder to choose your own. Chrome, Edge and Safari record H.264 in MP4; Firefox records WebM. The screen is recorded at up to 4K.
Uploads that don't wait for the end
Each track uploads while it's recorded, in 8 MiB parts (5 MiB for audio), straight to rendermate's storage. stop() only sends the last part and records the asset, so a long recording is ready seconds after it ends. Content the workspace already has is stored once.
Closed and crashed tabs
While recording, the SDK writes what it has recorded to the browser's own storage (the origin private file system) every second, so a closed or crashed tab loses at most the last second. resumeUnfinished on the next page load uploads only the parts that weren't up yet. A recording that another tab is still recording or uploading is left to that tab. In a browser without that storage, recorder.durable is false.
After the upload
- Get notified: a webhook endpoint gets
asset.createdfor each track. - Transcribe it: run a transcription model on the screen or camera track for a transcript with word timings; see transcribing a video with word-level timestamps.
- Download it:
GET /v1/assets/{name}returns a download URL, andrendermate synckeeps a local folder in step with the workspace.
The full reference is in the docs: Recording in the browser.
■ questions
How do I record the screen in a web app?
Call the browser's screen capture from a click and record the stream. @rendermate/recorder does this with createRecorder({sources: {screen: true}}) and recorder.start(), and uploads the recording as it's made.
Can I record the screen and the webcam at the same time?
Yes. Set sources: {screen: {audio: true}, camera: true, microphone: true}. The screen and camera are recorded as separate tracks and uploaded as separate assets, with the microphone on the camera track.
How do I upload a recording from the browser without exposing my API key?
Make a short-lived upload token on your backend with POST /v1/upload-tokens and give it to the page. The token only writes assets under its prefix, up to its max_size, for 15 minutes by default, and can't replace an existing asset.
What happens if the user closes the tab while recording?
The SDK saves the recording in the browser's own storage every second. Call resumeUnfinished on the next page load and it uploads the parts that weren't uploaded yet.
What format are browser screen recordings?
With @rendermate/recorder, Chrome, Edge and Safari make H.264 MP4 files and Firefox makes WebM. The screen is recorded at up to 4K.
Does the upload start before the recording ends?
Yes. Each track uploads in 8 MiB parts while it's recorded, so stopping only sends the last part and the asset is ready seconds later.