I'm not sure how lightweight niri is. Maybe try Sway for a bit? (definitely not Hyprland ;D)
With 4GB of RAM, I would suggest to create a SWAP partition and maybe increase swappiness?
Are the crashes happening because you are running out of RAM? If you monitor # journalctl -f, the crashes happen with OOM?
I don't know the answer, but try to find a Firefox clone that is focused on being lightweight. Vanilla Firefox can be a bit RAM-greedy