After testing this project with Unity 2023, 2022, and 2021, the issue does not happen there. I then tested it with 2020.3 and did indeed repro it. It seems that between 2020.3 and the next versions the profiler sends data faster and the buffer is enough.
A workaround I tried for my 2020.3 test that succeeded is to follow the error message in the console that says:
"Please use Profiler.maxUsedMemory API or -profiler-maxusedmemory command line parameter to increase maximum allowed memory usage."
I did that by modifying the Module object in the build's loader.js file and setting the flag with a larger value as an argument like this:
var Module = {
arguments: ['-profiler-maxusedmemory', 100000000],
canvas: canvas,
webglContextAttributes: { ... }
}