My games also freeze a lot while recording screen, I wonder what is the reason for this.
Screen recording is typically quite resource intensive, especially on lower powered devices. If you couple this with a game that is also resource intensive, you can expect that the system would stutter while attempting to record.
The best things you can do are reviewing your code, and checking where you can optimize it, or use a more powerful device.
What do you mean by recording the screen? Is this in the browser via some code and library or external with something like OBS, or some other windows app?