Docs › The <video-piper-recorder> web component
The <video-piper-recorder> web component
Let people record their screen, camera or both, or pick a file, right on your site. It uploads straight to your account while they record, so processing starts the moment they stop. Your API key stays on your server: the page gets a one-video upload token instead.
// 1. Your server: an endpoint that makes a token (POST /upload-tokens with your API key)
app.post("/api/upload-token", async (req, res) => { // check the user is signed in, as you need
const r = await fetch(`${API}/upload-tokens`, { method: "POST",
headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ expiresIn: 300, maxSeconds: 600, metadata: { userId: String(req.user.id) } }) });
res.status(r.status).json(await r.json()); // { uploadToken: "vpu_…", … }
});
// Program.cs (ASP.NET Core 8+). The API key stays on your server: set VideoPiper__ApiKey (or appsettings.json).
using System.Collections.Concurrent;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text.Json;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpClient("videopiper", client =>
{
client.BaseAddress = new Uri("https://api.videopiper.dev/v1/");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", builder.Configuration["VideoPiper:ApiKey"]);
});
var app = builder.Build();
// A one-video upload token for <video-piper-recorder token-url="/api/upload-token">.
app.MapPost("/api/upload-token", async (ClaimsPrincipal user, IHttpClientFactory http) =>
{
var userId = user.FindFirstValue(ClaimTypes.NameIdentifier) ?? "anonymous";
using var response = await http.CreateClient("videopiper").PostAsJsonAsync("upload-tokens", new
{
expiresIn = 300, maxSeconds = 600, metadata = new Dictionary<string, string> { ["userId"] = userId },
});
return Results.Content(await response.Content.ReadAsStringAsync(), "application/json", statusCode: (int)response.StatusCode);
}); // add .RequireAuthorization() so only your signed-in users get tokens
app.Run();
<!-- 2. Your page: the recorder asks token-url for a fresh token when someone starts -->
<script src="https://videopiper.com/recorder/recorder.js"></script>
<video-piper-recorder token-url="/api/upload-token" max-seconds="600"></video-piper-recorder>
<script>
document.querySelector("video-piper-recorder")
.addEventListener("vp-uploaded", (e) => console.log("uploaded", e.detail.videoId));
</script>
| Attribute | Description |
|---|---|
token-url | Recommended. Your endpoint; the recorder POSTs to it (with your site's cookies) for a fresh token at the moment someone starts recording or picks a file, and expects {"uploadToken": "vpu_…"}. A page left open for hours never starts with an expired token. |
upload-token | Or a token made when the page loads (or set later with element.setToken(token)). Use token-url or this. |
modes | Any of screen+camera, screen, camera, file (default all, in that order; the first is selected). Modes the browser can't do are hidden. |
layout | For screen + camera: the starting layout: pip (default), side-by-side, or a layout object as JSON. People can change it before recording unless you set layouts; the layout they end up with is what the video is made with. |
layouts | Which layouts people may choose in screen + camera mode: pip side-by-side (default: a picker for the camera corner, its size and side by side), just one of them, or none to hide the picker and always use layout. The preview shows the camera where the video will put it. |
background | The camera's starting background (camera and screen + camera): none (default), blur, or a built-in picture, slate, dawn or mint. It is applied in the browser before recording, so the recorded video has it. What someone chose last time is remembered in their browser and takes over. |
backgrounds | What people may choose: blur image (default: None, Blur, the built-in pictures and "Your picture…" to use their own), one of them, or none to hide the picker and always use background. Their own picture is kept in the browser for that visit only. |
background-assets | The effect finds the person with Google's MediaPipe selfie model, downloaded only when someone first picks an effect: by default from jsDelivr (@mediapipe/tasks-vision, a pinned version) and Google's model storage, which your page's Content-Security-Policy must allow (script-src and connect-src for cdn.jsdelivr.net and storage.googleapis.com, plus 'wasm-unsafe-eval'). To host it yourself, set this to a folder (CORS-enabled if it's on another origin) with vision_bundle.mjs, wasm/vision_wasm_internal.js, wasm/vision_wasm_internal.wasm and selfie_segmenter.tflite. Where it can't load, the camera is shown as it is and recording works as usual. |
fullscreen | Opt in to full screen: the recorder fills the screen when someone starts recording, and a Full screen / Exit full screen button (and Esc) leaves and re-enters it. Leaving full screen never stops the recording, and the recorder leaves it by itself when the upload starts, so the page gets its screen back. Where the browser has no full-screen API (iPhone Safari) it fills the page instead. Without this attribute, the recorder never takes over your page. |
max-seconds | Stops recording at this length (the token's maxSeconds also trims it on the server). |
review | "false" uploads as soon as recording stops; otherwise people watch it back, then Upload or Retake. |
wait | Keep checking until the video is processed, then fire vp-ready. |
- Events:
vp-state({state}),vp-progress({loaded, total}),vp-uploaded({videoId}),vp-ready({videoId, status}) andvp-error({message, code}, with a message fit to show).vp-layout-change({layout}, the full layout object) when someone picks another layout.vp-background-change({background}:none,blur,preset:slateand so on, orupload) when someone picks another camera background. The recording's steps have their own events too:vp-start({mode}),vp-pauseandvp-resume({seconds}),vp-stop({seconds}: the take was kept) andvp-cancel({stage}:recordingorreview, thrown away). Your server also gets the usualvideo.readywebhook, with the token'smetadata. - Callbacks: every event has an
on…property that gets its detail:onState,onProgress,onUploaded,onReady,onError,onLayoutChange,onBackgroundChange,onStart,onPause,onResume,onStop,onCancel. - Drive it from your own buttons:
start()(call it in a click or key handler: browsers only allow recording after a gesture),pause(),resume(),stop()(keeps the take: review, or upload withreview="false"),upload()(after review),retake(),cancel()(throws the take away, aborting an upload already under way), andrecordedSeconds.const rec = document.querySelector("video-piper-recorder"); rec.onStart = () => showBanner("Recording…"); rec.onStop = ({ seconds }) => hideBanner(); rec.onUploaded = ({ videoId }) => saveToProfile(videoId); myStopButton.onclick = () => rec.stop(); - Plans: recording (screen, camera, upload while recording) needs Pro or Scale; picking a file works on every plan.
- Try every option live. In the app, Account → Playground (sign in) lets you set up the recorder, run your page in an isolated frame with a stand-in for your server, see its events and errors, and copy the page and server code.
- Styling: it fills its container's width. Theme it with
--vp-accent,--vp-panel,--vp-lineand--vp-text. - Browsers ask people for camera, microphone and screen permission; screen recording works in desktop Chrome, Edge, Firefox and Safari.
Upload tokens
POST /upload-tokens (with your API key, from your server) makes a token that can upload exactly one video. All settings are optional, and the browser can't change them:
{ "expiresIn": 3600, // 60 to 86400 seconds; default 3600
"maxSeconds": 600, // the video is trimmed to this length
"maxBytes": 2147483648, // the largest upload; default your upload limit
"maxHeight": 1080, // top quality
"captions": true, // Pro and Scale
"metadata": { "userId": "42" } } // set on the video, for your webhooks and listings
→ 201 { "uploadToken": "vpu_…", "tokenId": "u-…", "expiresAt": 1790910405, "policy": { … } }
expiresInis the time to start. Once an upload has started, its token keeps working for that upload for 24 hours, so a long recording (or one started just before the token expired) always finishes. Withtoken-url, a few minutes is plenty.- With the token the browser can only create its one upload (without image overlays), send its parts, complete or abort it, and read its status. Anything else answers
403 UPLOAD_TOKEN_SCOPE; a second video,409 UPLOAD_TOKEN_USED. Aborting an unfinished upload (a retake) frees it again. - It's shown once (only a hash is kept), expires on its own, and counts toward your key's rate limits and your plan, like any of your uploads.
- Make one per recording session. Your Account page has these snippets filled in with your addresses, and a place to try the recorder.
Recording links: let a guest record for you
When the person recording isn't on your site at all (a customer sending a testimonial, a candidate answering a question, a colleague without an account), send them a recording link. They open it, record their screen, camera or both in the browser (or pick a file), and the video lands in your account with their name and email in its metadata. Nothing to install and no account on their side. Make one in the app (Videos → Request a recording, or the Recording links page) or with your API key:
POST /recording-links
{ "title": "Record a short intro", // the page heading (up to 120 characters)
"message": "Two minutes about yourself.", // shown under it (up to 1000)
"modes": ["screen+camera", "camera"], // what they may record: screen+camera, screen, camera, file; default all four
"askName": true, "askEmail": true, // asked before recording (default true); kept as guestName / guestEmail
"maxRecordings": 1, // default 1: the link stops after it; up to 1000, or null for no limit
"expiresIn": 604800, // how long the link works: 60 s to 30 days; default 7 days
"maxSeconds": 600, "maxHeight": 1080, // the upload-token limits above, plus captions, autoRedact, metadata
"metadata": { "campaign": "spring" } }
→ 201 { "recordingLinkId": "r-…", "url": "https://<site>/record/vpr_…", "status": "active", "modes": [ … ],
"askName": true, "askEmail": true, "maxRecordings": 1, "recordings": 0, "expiresAt": 1794000000, "createdAt": "…" }
- Send the
url. The page shows your title and message, asks for what you chose, and records with the same recorder as above, within the link's limits. When the recording is in, it thanks them. - Every video made through a link carries
metadata.recordingLink(the link's ID),guestNameandguestEmail, with any metadata you set, so yourvideo.readywebhook and listings can tell them apart. statusisactive,full(every recording taken) orexpired.GET /recording-linkslists yours, newest first;GET /recording-links/{id}shows one;DELETE /recording-links/{id}stops it at once (recordings already made stay).- Recording in the browser needs Pro or Scale (a link that offers only
fileworks on every plan). Recordings count toward your plan like your own uploads; a test key makes test links, which make test videos. The SDKs haverecordingLinks/recording_links, and the MCP servercreate_recording_link.