I am trying to record a video from a canvas, even when the user navigates from the tab (either by clicking another tab or minimizing the window). I am using a timer that runs even when the user has the tab blurred to render the canvas (I know this timer fires when the tab is blurred because I've tested it). But when I attach the MediaStream
from canvas.captureStream()
to the MediaRecorder
object, the BlobEvent
from the ondataavailable
callback has length 0.
Below is an example of what I'm trying to do.
let canvas = document.getElementById('canvas');
// ...Assume that I'm rendering some kind of video/animation to the canvas here...
let stream = canvas.captureStream();
let mediaRecorder = new MediaRecorder(stream, { mimeType: 'video/webm; codecs="opus,vp8"' });
mediaRecorder.start();
mediaRecorder.ondataavailable = (event) => {
// This event's data is length 0 when the tab is blurred
console.log(event);
}
I understand that ondataavailable
does not normally fire when the tab is backgrounded, I've gotten it to by using the requestData
function on MediaRecorder
, please assume that it does.