Well… that would make sense. But it’s much much easier to just do it preemptively. The browser API to check how much memory is available are quite limited afaik. Also if there are too many elements the browser will have to do more work when interacting with the page (i.e. on every rendered frame), thus wasting slightly more power and in a extreme cases even lagging.
For what it’s worth, I, as a web developer, have done it too in a couple occasions (in my case it was absolutely necessary when working with a 10K × 10K table, way above what a browser is designed to handle).
On Windows: VirtualBox (free and easy to use, but still advanced/powerful) or HyperV (already included if you have Windows Pro).
On Linux: anything based on KVM, my personal favourite is virt-manager, but QEMU is also great.
I would stay away from VMware because the free version is quite limited, and the pro version is not free. The free alternatives are equally good or better, so no reason to use something paid imho.