Screen capture with HTML annotation tools in one canvas
The picture is one 2D canvas with two drawable children: a <div> that holds a <video>, and a layer of annotations made of DOM.
Draw on it with a finger, a pen or a mouse. The magnifier, the spotlight and the redact box change the video pixels under them.
The video can be the test clip, the screen or the camera, and the canvas goes out as one stream.
Capture options for the Screen button, and controls for a running capture
The clip is the video. Screen and This tab call getDisplayMedia(). Each call and its result is written here.
Nothing sent or recorded yet. A live source can't use the frame-by-frame export of /overlay/: a screen or a camera can't be seeked.
Show the code a video, DOM annotations that change it, one stream out
- The markup. Two
drawablechildren: one holds the video, one holds the annotations. - The CSS. The glow, the fade animation and the annotation boxes.
- The paint handler. The frame with
drawElementImage(), then the spotlight, the magnifier and the redaction withdrawImage(video, sx, sy, …)andctx.filter, then the layer with a seconddrawElementImage(). - A stroke. One SVG
<path>. IfPointerEvent.pressurevaries, the path is a ribbon whose width follows it. - The glow colour. The mean colour of the video under the stroke's points.
- The annotations. Each one is an element with its place in
el.geo. - Pointer events. One set of handlers on the canvas for touch, pen and mouse.
- The screen as the video.
getDisplayMedia()with its options, thencropTo(),restrictTo()and theCaptureControllercalls. - Out as one stream.
canvas.captureStream()into a peer connection, or intoMediaRecorder. - The whole module.
How it works
- The canvas buffer is 640 by 360 on every screen. Both children are laid out at that size and drawn with
drawElementImage(el, 0, 0, canvas.width, canvas.height), which scales their hit boxes with their pictures. - Every annotation is an element in the layer: an SVG
<path>for a stroke or an arrow, a<div>with a<textarea>for a note, a<div>for a step marker, a spotlight, a magnifier and a redact box. - The paint handler reads the boxes of the spotlight, magnifier and redact elements. Between the two
drawElementImage()calls it draws regions of the same<video>again withdrawImage(): grey and dark outside a spotlight, 2.2 times larger inside a magnifier, 14 px cells, a blur or black inside a redact box. - The handler has no render loop. The video raises
paintfor each frame, and a DOM change or a CSS animation in the layer raises it too. - A screen capture is a
MediaStreamin the video'ssrcObject. Nothing else on the page changes when the source changes. - The outgoing stream is
canvas.captureStream(30). The redaction is made in the canvas, so no reader of the stream gets the pixels under the box.
Live checks
Each check builds its own canvas in a corner of the window. Its "screen" is the captureStream() of a second canvas, so no check asks for a permission. The picture above isn't touched.
| Result | Experiment | Detail |
|---|
Findings
Measured on 2026-11-21. The canvas, the tools and the stream: Chromium 157 headless with software rendering. A real capture of a tab: Chromium 153 with a window, because the headless build can't start one. The rows above say what your browser does.
- Works: a display capture as the video. A
getDisplayMedia()stream insrcObjectis drawn bydrawElementImage()and bydrawImage(video)like any other video. The canvas isn't tainted:getImageData()andcaptureStream()work on it. - Works: annotations as DOM. A stroke is an SVG
<path>, and a note is a<textarea>that takes a tap, a caret and typing inside the canvas. Twodrawablechildren drawn with a size each keep their own hit boxes, so the layer takes the pointer events and nothing else is needed. - Works: annotations that change the video. The paint handler draws regions of the video between the two element draws. The magnifier is drawn from the video's own pixels, not from the 640 px canvas. The redaction is in the canvas pixels, so it is in the recording and in the WebRTC stream.
- Needed: redact inside the magnifier too. The magnifier reads the video, not the canvas. The paint handler therefore redacts a second time inside each lens. The fourth live check counts 0 pixels of a redacted mark under a lens.
- Works: fading with no script. A CSS opacity animation on a path raised 28
paintevents in the 450 ms in which the opacity changed, and none while the keyframes held it at 1. - Works: pressure. Touch points sent with a rising force gave a path that is a ribbon of varying width. Points that all carry one pressure give a plain stroked line.
- Works: capturing the tab that holds the canvas. With
preferCurrentTabthe video shows the page with the canvas in it, and the picture repeats inside itself. No crash. - Limit: a capture cropped to the canvas is a closed loop. After
track.cropTo()ortrack.restrictTo()with the canvas as the target, the video holds only the canvas, which draws only the video. The picture from before the crop stayed, and each annotation was drawn over its own copy on every frame. Crop to another element, not to the canvas. - Limit:
cropTo()andrestrictTo()are for this tab only. On a capture of another tab both threwNotAllowedError: Invalid target. On a monitor capture the track is a plainMediaStreamTrackwith neither method. - Limit: scroll and zoom of the captured tab need a tab and a permission.
forwardWheel()andincreaseZoomLevel()threwNotSupportedErroron a monitor capture. On a tab capture both stayed pending in the automated browser, which is what an unanswered permission prompt does. - Limit: Chrome on Android. This page reads
navigator.mediaDevices.getDisplayMediaand turns the Screen and This tab buttons off when it's missing. The clip and the camera use the same canvas and tools. - Limit: the canvas has to be on screen. A recording made while the canvas was scrolled out of the window was 0 kB.
- Not verified here: a real stylus, touch on a phone, the picker and sharing bar of a real desktop Chrome,
setFocusBehavior()with a visible window switch, and the frame rate of a 4K capture. The first live check lists what your browser has, and the log under the source buttons writes what each call did.