Documentation

Guides and API reference for uploads, image transforms and video.

npm install @cd2/fileboy-react
API https://api.fileboy.io

Screen recorder

<fileboy-recorder> lets the people using your app record their screen or camera in the browser. It uploads while they record, so the link exists from the moment they start, and becomes an ordinary Fileboy video: streaming, the player, captions, privacy and webhooks all work with no extra code.

How it works

The recorder is a web component with no dependencies (about 28 KB gzipped). It asks for the screen with getDisplayMedia and the camera and microphone with getUserMedia, and records with the browser's MediaRecorder: WebM (VP9 or VP8 with Opus) in Chrome, Edge and Firefox, MP4 (H.264 and AAC) in Safari.

The person sees a countdown and can pause, resume, restart or cancel. The recording goes up while they record, as an open-ended upload session, so stopping only sends the last few seconds, and the link exists from the start (see Instant link). Where that isn't possible it uploads when they stop, after a preview, with a single POST /videos/upload for storage that can't take parts. It marks the video source: "recording", which moves it ahead of your app's bulk uploads in the processing queue (see Upload and process).

To record without writing any code, open your app's Videos page in the dashboard and press Record (or Record a video when the app has no videos yet). It opens this recorder in a dialog, records into that app as you, and opens the new video's page once it has uploaded. Choose Screen and camera (your camera in a bubble over the screen, the default when you have a camera), Screen or Camera before you start; on a phone or tablet, which can't share its screen, it records your camera. Any member of the app can record, Viewers included: a Viewer manages their own recordings, not anyone else's (see Team members and roles). To record from any tab, there is also Fileboy for Chrome, from the Chrome Web Store.

Browser recordings are awkward files: a WebM from MediaRecorder has no length in its header and a variable frame rate. Fileboy rewrites such a file before reading it (without re-encoding), so its length, trims, seek previews and renditions come out right.

Add it to a page

Load the script once and put the element where the recorder should be. Pin the version in production.

HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script type="module" src="https://cdn.jsdelivr.net/npm/@cd2/fileboy-recorder@0.5/dist/fileboy-recorder.js"></script>

<fileboy-recorder
  public-key="YOUR_PUBLIC_KEY"
  mode="screen"
  max-duration="300"
  label="feedback"
></fileboy-recorder>

<script>
  document.querySelector("fileboy-recorder").addEventListener("fileboy:recorded", e => {
    const { videoId, fileId, watchUrl, embedUrl } = e.detail
    // Save videoId with your record, or share watchUrl
  })
</script>

Or from npm:

npm
1
2
3
4
yarn add @cd2/fileboy-recorder

// Registers <fileboy-recorder>. Safe to import during server rendering.
import "@cd2/fileboy-recorder"
Add the page's origin to your app's allowed origins, as for any public-key upload. Recordings use the same key, origins and plan limits as uploads: there is nothing new to set up.

Attributes

Attributes

public-key string

Your app's public key. Recordings upload with it, held to the app's allowed origins and plan limits like any upload.

upload-token string, optional

The URL of your endpoint that answers { "token": "..." }, to upload with a short-lived upload token instead (signed uploads). The uploadToken property takes a function too.

mode string, optional, default is screen

"screen" (a screen, window or tab, with the microphone), "camera" (the camera and microphone) or "screen camera". modes is the same attribute. See Modes.

max-duration number, optional

Seconds. Recording stops by itself when it reaches this; pauses don't count. No limit when left out.

countdown number, optional, default is 3

Seconds counted down before recording starts. 0 starts at once.

name string, optional

The video's name. Default "Recording" and the date and time. The original is stored as the name plus .webm or .mp4.

label string, optional

Saved as a tag on the video, to find recordings later (GET /videos?tags=...).

metadata JSON, optional

A JSON object saved as the video's metadata, like {"pupilId": "42"}. Values are saved as strings.

api-url string, optional, default is https://api.fileboy.io

The Fileboy API.

site-url string, optional, default is https://fileboy.io

Where watchUrl and embedUrl point.

bubble-position string, optional, default is bottom-left

Where the camera bubble starts in screen camera mode: bottom-left, bottom-right, top-left or top-right, or two numbers from 0 to 1 (or percentages) across then down, like "0.5 1" for the bottom middle. Changing it while recording moves the bubble.

bubble-shape string, optional, default is circle

circle or square (a square with rounded corners). The person can switch it while recording.

bubble-size number, optional, default is 25

The bubble's size, as a percentage of the video's shorter edge, from 10 to 50. A number under 1 is a fraction, as fileboy:bubble gives it (0.3 is 30%).

drawing boolean, optional

Adds a pen and highlighter for drawing on the recorder's live preview. What is drawn is recorded. See Drawing.

drawing-fade number, optional, default is 3

Seconds a finished stroke stays before it fades out. 0 keeps strokes until the person presses Clear.

drawing-color string, optional, default is #e5484d

The pen's first colour, as a hex colour. Red, yellow, green and blue are offered as well.

click-highlights boolean, optional

Draws a ripple at each click when the person shares the tab the recorder is in (Chrome and Edge). See Click highlights.

live-upload boolean, optional, default is on

Uploads while recording, with the link from the moment recording starts. "false" keeps the 0.2 behaviour: a preview when the person stops, and the upload when they press Upload. See Instant link.

recovery boolean, optional, default is on

Keeps each recording in the browser (IndexedDB) until Fileboy has it, and offers to resume one that didn't finish after a crash or a closed tab. "false" keeps nothing. See Recovering a recording.

recovery-scope string, optional

Who recordings are kept for, besides the key: the signed-in user's id, say. Every upload token shares one scope without it, so set it where people share a browser, and no one is offered another person's recording.

Events

Events bubble and cross shadow roots, so you can listen on the element or any parent.

Events

fileboy:link { videoId, watchUrl, embedUrl } | null

The recording's links, as soon as there are any: when recording starts, uploading live (a moment after, once its upload session is made). Until the upload completes the watch page says the recording is still uploading. Without a live upload it comes just before fileboy:recorded. A restart starts a new take, with a new link. null when a live upload is refused part way: its reserved video goes, and the take gets a new link once it is uploaded.

fileboy:recorded { videoId, fileId, watchUrl, embedUrl }

The recording uploaded and is now a Fileboy video, with the same id and links as fileboy:link. fileId is its stored original. The watch link usually plays within seconds, from the recording itself, while its qualities are made (see Playable in seconds); the video.playable and video.ready webhooks say when.

fileboy:recoverable { recordings }

Recordings of this key that didn't finish uploading were found in the browser (or the list changed): each { id, name, duration, bytes, recordedAt, videoId }. The recorder offers them itself. See Recovering a recording.

fileboy:state { state, previous }

Every change of state: idle, countdown, recording, paused, preview, uploading, done.

fileboy:error { code, message, error }

Something went wrong. The recorder shows the error screen itself; code is one of the codes under Permissions and errors.

fileboy:warning { code, message }

Something the person should know that doesn't lose the recording; the recorder shows the message itself (part warning). stopped-early: the browser's recorder failed part way, and what was recorded up to then is kept and uploaded, as if Stop had been pressed. mic-stopped: the microphone ended (unplugged or switched off) and recording goes on without its sound. mic-muted: no sound has come from the microphone for 3 seconds (muted by the computer or another app); the message goes when it comes back.

fileboy:bubble { x, y, size, shape }

The person moved, resized or reshaped the camera bubble. x and y run from 0 to 1, size is a fraction of the video's shorter edge. Save it to start the bubble in the same place next time (bubble-position, bubble-size and bubble-shape).

Methods and properties

The buttons call these; your own controls can too. Each does nothing in a state it doesn't apply to.

JavaScript
1
2
3
4
5
6
7
8
9
10
11
const recorder = document.querySelector("fileboy-recorder")
await recorder.start() // call from a click: browsers only show the screen picker for one
recorder.pause()
recorder.resume()
recorder.stop() // sends the last part and makes the video (or, without a live upload, shows the preview)
await recorder.upload() // from the preview: resolves with { videoId, fileId, watchUrl, embedUrl }, or null
recorder.state // "idle", "countdown", "recording", "paused", "preview", "uploading" or "done"
recorder.link // { videoId, watchUrl, embedUrl } from when recording starts, uploading live
recorder.recoverable // recordings that didn't finish uploading: [{ id, name, duration, bytes, recordedAt, videoId }]
await recorder.recover(id) // uploads one, as Resume upload does
await recorder.discardRecovery(id) // throws one away, as Discard does

recording is the finished recording as a Blob (in preview), result the uploaded video, restart() throws the take away and counts down again, cancel() throws it away (or, while uploading, stops the upload and keeps the recording) and reset() goes back to the start. Throwing a take away also throws its upload session away, with its reserved video. The element also has a state attribute, for CSS.

fetch (from 0.4.0) replaces the browser's fetch for the recorder's requests to the API: to add a header, say. Set it before recording starts. Part uploads to storage use XMLHttpRequest, for progress, so they don't go through it. Where storage takes no parts, the one-request upload does, and its progress shows only at the end. The React wrapper takes it as the fetch prop (from 0.19.0).

Playable in seconds

Encoding every quality of a recording takes a while (a minute or so for 5 minutes of video, longer when other uploads are ahead of it), so a recording doesn't wait for it. A few seconds after its upload completes, Fileboy makes a playable copy: the recording as it was made, its streams copied into a WebM (VP9 or VP8 with Opus) or an MP4 (Safari's H.264 and AAC) with its length and seek index, with nothing re-encoded. The watch page and <fileboy-player> (1.12.0+) play that copy straight away, while the qualities are made as for any upload. This runs beside the processing queue, so a recording plays even while another upload is encoding.

GET /videos/{id}/data then answers playable: true with a playableSource (its URL and its type with codecs), and the video.playable webhook is sent with playable.from recording. Once every quality is made, video.ready follows and the player switches to them (a viewer already watching carries on with the copy). The copy is deleted an hour later.

For 5-minute 720p recordings we measured the copy at under half a second of work (a 7.6 MB screen-like WebM, a 4 MB Safari MP4 and a 99 MB busy WebM), against roughly 35 to 70 seconds to encode every quality on a processor's half a CPU. So a recording usually plays a few seconds after it stops: the processor looks for recordings every 2 seconds, then downloads, copies and stores the file, which takes longer for a bigger file. These are our measurements, not a guarantee.

The copy plays where the browser can play its format, which the player checks with canPlayType. Safari's MP4 recordings play everywhere. A WebM recording from Chrome, Edge or Firefox doesn't play in older Safari and some iOS versions: there the player shows it processing and plays it once its qualities are made, as before. The copy is one quality, with no quality menu.

A video with a watermark (its own or the app's default) gets no copy, since the copy is the recording as it was made: it plays once its watermarked qualities are made. A watermark set while a copy exists stops it being shown or served. Nor is the copy shown or served while the video's downloads are off: it is one file of the whole recording. Privacy is the video's, as for its qualities: where the app requires signed reads, the copy's URL needs the signature, which playableSource.url carries on. An upload that is already H.264 with AAC sound gets the same kind of copy, as an MP4, and its video.playable says from: upload. Other uploads don't get a copy: they play from their first quality, and their video.playable is sent then.

Recovering a recording

Each chunk is kept in the browser's IndexedDB as it is recorded, until Fileboy has the whole recording. If the tab crashes or is closed part way, the next time a recorder with the same key loads on a page of the same site, it offers the recording with Resume upload and Discard. Resuming sends what Fileboy doesn't have yet to the same upload session and completes the same video, so a link already shared works. If the session has expired (after 24 hours), the recording is uploaded again as a new video, with a new link, as long as all of it is still kept.

The same goes for a recorder taken off the page while it records: a route change in a single-page app, a React component unmounting, a modal closing. The take is stopped and kept, with its upload session and link, and the next recorder put on the page offers it straight away. Only Cancel, Restart and Discard throw a take away. If the browser's recorder fails part way, the recording stops early and what was recorded up to then is uploaded, with a warning (fileboy:warning).

A recording that is still going in another tab isn't offered. Storage is bounded: a recording may use at most half the free space the browser reports (and 1 GB), after which the parts Fileboy already has are dropped; at most two recordings are kept, so starting a new one drops the oldest; and kept recordings go when they finish, are discarded, or after a week.

Private browsing windows may not allow IndexedDB, or clear it when they close. There, nothing is kept and nothing is offered: recording and uploading work as usual. The recorder doesn't ask for persistent storage (Firefox would show a prompt), so a browser short of space may clear what it kept.

Modes

screen (the default): the person picks a screen, window or tab in the browser's own picker. Their microphone is recorded too, unless they choose "No microphone". In Chrome and Edge, picking a tab can also record its sound; it is mixed with the microphone.

camera: the camera and microphone, with a camera picker and a live preview. Works on phones and tablets.

screen camera: the screen with the camera drawn over it in a bubble, as one video. The person can move and resize the bubble while recording. See Camera bubble.

Before recording, "Check microphone" starts the chosen microphone to show a level meter (and the camera, in camera mode) and fills the lists with the devices' names, which browsers only give once one is allowed. The meter stays up while recording. The choice is remembered for the next visit.

Camera bubble

In screen camera mode the recorder draws the screen and the camera into one canvas and records that, so the video shows exactly what the person saw: their screen with their face in a circle (or rounded square) in a corner. The microphone and any tab sound are recorded as usual. The camera is mirrored in the bubble, as people expect to see themselves.

While recording (and during the countdown), the recorder shows a live preview of the video. The person drags the bubble to move it and its corner to resize it. With the keyboard, Tab to the bubble, then the arrow keys move it (further with Shift) and + and - resize it. A button switches it between circle and square. The video follows at once, and the next take starts where they left it.

HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<fileboy-recorder
  public-key="YOUR_PUBLIC_KEY"
  mode="screen camera"
  bubble-position="bottom-right"
  bubble-shape="circle"
  bubble-size="25"
  drawing
  click-highlights
></fileboy-recorder>

<script>
  const recorder = document.querySelector("fileboy-recorder")
  // Start the bubble where the person left it last time
  const saved = JSON.parse(localStorage.getItem("bubble") || "null")
  if (saved) {
    recorder.setAttribute("bubble-position", `${saved.x} ${saved.y}`)
    recorder.setAttribute("bubble-size", String(saved.size * 100))
    recorder.setAttribute("bubble-shape", saved.shape)
  }
  recorder.addEventListener("fileboy:bubble", e => {
    localStorage.setItem("bubble", JSON.stringify(e.detail))
  })
</script>

Drawing

With drawing, the person gets a pen and a highlighter, four colours and Clear. They draw on the recorder's live preview, and what they draw is drawn into the video. Each stroke fades out a few seconds after it is finished (drawing-fade), or stays until Clear.

A web page can only draw on itself. The pen works on the recorder's own preview, not over other windows or apps, so when someone records another window they draw on the preview in this tab and the drawing lands in the video at the same place. Drawing on top of any app needs a desktop app or extension.

Click highlights

With click-highlights, each click shows in the video as a ripple, so viewers can follow along. A page only knows about clicks on itself, so this works only when the person shares the tab the recorder is in: the recorder asks Chrome to offer that tab first (preferCurrentTab), then checks that the capture is a tab (displaySurface) and that it is this one (its Capture Handle), and places each click in the video. The person can turn the ripples off while recording.

When the capture is another tab, a window or the whole screen, there are no clicks to show, so the option isn't offered and nothing extra is drawn. It only works in Chrome and Edge, which can tell a capture of the current tab; Firefox and Safari can't share a single tab. Clicks inside iframes on the page aren't seen, and a recorder that is itself in an iframe can't tell.

Performance

Plain screen and camera recordings record the browser's own track, with no extra work. The canvas is only used for the camera bubble, drawing or click highlights.

The canvas is the size of the screen being shared, scaled down to 1920 pixels on its longer side, and is recorded at 30 frames a second. Frames are drawn as the camera delivers them (requestVideoFrameCallback), or with requestAnimationFrame held to 30 a second.

When the recorder's tab is hidden, which is usual when recording another window, browsers stop animation frames and slow timers to once a second. A timer in a small worker runs underneath and draws whenever the page's own frames stop (or the camera stalls), so the recording doesn't freeze. Where workers are blocked (a strict Content Security Policy without worker-src blob:), the page's own timer is used and a hidden tab may record at a lower frame rate.

Drawing a frame is a GPU copy of each video and a few shapes, on the main thread. We chose that over an OffscreenCanvas in a worker, which would mean sending every frame across and only works in Chromium.

Browser support

Chrome and Edge (desktop): screen, window or tab, and a tab's sound. Records WebM.

Firefox (desktop): screen or window. No tab or system sound, only the microphone. Records WebM.

Safari (macOS): screen or window. No tab or system sound. Records MP4.

Phones and tablets: camera mode only. No mobile browser lets a web page capture the screen, and the recorder says so instead of failing.

The camera bubble and drawing work in every desktop browser above: they record a canvas (captureStream). Click highlights work in Chrome and Edge only. A browser that can't record a canvas records the screen on its own.

Recording needs a secure page (https, or localhost while developing). On macOS the browser also needs the Screen & System Audio Recording permission in System Settings; the recorder explains this when the system blocks it.

Permissions and errors

Most recording problems are permissions. Each error has a screen that says what happened and how to fix it in the browser being used, with Try again where it can help. The same code comes in fileboy:error.

Error codes

screen-cancelled

The screen picker was closed without choosing anything. Try again shows it again.

permission-denied

The camera or microphone is blocked. The screen explains where this browser keeps the setting (Chrome and Edge: the icon in the address bar; Firefox: the crossed-out icon; Safari: Settings for This Website).

system-permission-denied

The operating system blocks the browser, usually macOS's Screen & System Audio Recording setting. The browser has to be restarted after allowing it.

no-device

No camera or microphone, or not the one chosen.

device-in-use

Another app is using the camera or microphone.

screen-not-supported

No screen capture here: phones and tablets, or an old browser. Camera mode still works on phones.

not-supported

No MediaRecorder or getUserMedia.

insecure-context

The page isn't https (or localhost). Browsers only allow capture on secure pages.

recording-failed

MediaRecorder failed part way.

upload-failed

The upload was refused or failed (message has the API's reason, such as an origin that isn't allowed or a plan limit). The recording is kept, so the person can try the upload again.

Theming

Set CSS custom properties on the element, and style its parts with ::part(): root, title, button (every button; the main one is also primary, and start and stop), select, meter, status, timer, countdown, camera, preview, progress, error, warning and link. The live preview of a bubble or drawing take is stage (with the canvas in it), the bubble's control is bubble (and its bubble-grip), and the toolbar is tools, with each of its buttons also tool or swatch.

CSS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
fileboy-recorder {
  --fbr-accent: #0f766e;      /* the Upload and Copy link buttons, focus rings */
  --fbr-on-accent: #ffffff;
  --fbr-record: #dc2626;      /* Start, Stop and the recording dot */
  --fbr-background: #ffffff;
  --fbr-surface: #f1f5f9;     /* other buttons, lists, the meter */
  --fbr-text: #0f172a;
  --fbr-muted: #475569;
  --fbr-border: #cbd5e1;
  --fbr-radius: 8px;
  --fbr-font: "Inter", sans-serif;
  max-width: 720px;
}

fileboy-recorder::part(button) { font-weight: 600; }
fileboy-recorder::part(preview) { max-height: 480px; }

Every control is a real button or list, so it works with the keyboard. Focus moves to the main button of each new step, state changes are announced to screen readers, and the countdown and recording dot stop animating for people who ask for reduced motion.

React

FileboyRecorder in @cd2/fileboy-react (0.16.0+) renders the element with props for the attributes and callbacks for the events. It takes the public key, API URL and upload token from a FileboyProvider when you don't give them. It renders as the bare tag on the server, so it is safe with SSR and Next.js; import the element package once on the client. A ref gives you the element, for start() and the other methods.

React
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import "@cd2/fileboy-recorder" // once, on the client: registers the element
import { FileboyProvider, FileboyRecorder } from "@cd2/fileboy-react"

export function Feedback({ pupilId }: { pupilId: string }) {
  return (
    <FileboyProvider publicKey="YOUR_PUBLIC_KEY">
      <FileboyRecorder
        mode="screen"
        maxDuration={300}
        label="feedback"
        metadata={{ pupilId }}
        onRecorded={video => saveFeedback(pupilId, video.videoId)}
        onError={error => console.warn(error.code, error.message)}
        onStateChange={state => setBusy(state === "recording")}
      />
    </FileboyProvider>
  )
}

From 0.17.0 it has props for the camera bubble (bubblePosition, a corner or [x, y]; bubbleShape; bubbleSize; and onBubbleChange), drawing (drawing, drawingFade, drawingColor) and clickHighlights.

React
1
2
3
4
5
6
7
8
9
10
<FileboyRecorder
  mode="screen camera"
  bubblePosition="bottom-right"
  bubbleShape="circle"
  drawing
  drawingFade={5}
  clickHighlights
  onBubbleChange={layout => saveBubble(layout)}
  onRecorded={video => saveFeedback(video.videoId)}
/>

From 0.18.0, onLink gets the link when recording starts and onRecoverable the recordings that didn't finish uploading. liveUpload={false} and recovery={false} turn those off.

Signed uploads

To decide on your server who may record, give an upload-token as the uploaders take: the recorder gets a fresh token before it uploads, and again if one runs out part way. See the uploader docs for making the endpoint.

Upload token
1
2
3
4
5
6
7
<fileboy-recorder upload-token="/api/fileboy-token"></fileboy-recorder>

<script>
  // Or a function that returns a token
  document.querySelector("fileboy-recorder").uploadToken = () =>
    fetch("/api/fileboy-token", { method: "POST" }).then(r => r.json()).then(r => r.token)
</script>

Limits

A recording is held to your plan's upload size and storage limit, like any video (a video's files don't count towards the file limit). On the Free plan its videos are a limit too: with as many as the plan includes (15) a new recording is refused (403 video_limit_reached) until one is deleted or the plan is upgraded, and the Record dialog says so. On the paid plans the video allowance is a guide, and never stops a recording. Use max-duration to keep recordings short: how big a minute is depends on the browser and what is on screen.

A recording uploaded live is held to the same limits as it goes: each part reserves room against your storage limit as it is sent, and a part that would take it past your plan's upload size is refused. The recording is also kept in the browser's memory, for the preview.

The head start in the processing queue is bounded: 10 minutes, for up to 3 of an app's recordings every 10 minutes. More recordings than that queue as ordinary uploads, so other uploads are never held back for long. A recording with its head start that goes first in its app also goes ahead of the other apps' turns, so it waits only for the video being processed (and any earlier recordings); where it can, its quick playable copy plays within seconds meanwhile.

Related guides