Skip to content

Instantly share code, notes, and snippets.

@baptx
baptx / webrtc_video_blob_record.js
Last active March 2, 2025 18:51
WebRTC and video blob record (compatible with DRM and any videos like Facebook / Instagram stories)
/* Customized code to allow WebRTC record on existing page or HTML5 video blob download (based on https://github.com/webrtc/samples/blob/409d5631f38f2bdc4dafb5275d1bc77738fbb1ba/src/content/getusermedia/record/js/main.js)
* Recording will start when executing this script and you will have to execute manually startDownload() function when needed in web console with or without stopRecording()
* Recording should ideally start before playing video manually and in case controls are hidden, you can record from the start with a command like document.getElementsByTagName("video")[0].currentTime = 0
* By default, the script targets the first video element document.getElementsByTagName("video")[0] but you can change the code if needed.
*/
// If there is an error due to DRM, capture the stream by executing the following 2 lines before playing / loading the video:
var video = document.getElementsByTagName("video")[0];
var stream = video.captureStream ? video.captureStream() : video.mozCaptureStream();