Video record HTML5/JS animation and exporting it to mp4?

I have a website where users can create short animations. Currently, the only way to playback the created animation is via a "watch" URL, the animation includes audio.

I'm trying to let users export their animation into mp4 video, it should run in the background on the server without interaction from the user, my backend is .NET C#, my question is: how to programmatically video record (with audio) an animation from a website and save it as mp4?