Phone charging while using as security camera

I read that you can and should keep your Android (or any phone) plugged into a USB while using as a security camera. I assumes that means into a computer USB.

I have a USB plugged into the wall socket while using because the cord is short and the wall socket is close by while the PC is not. Does anyone know if this is safe and will not harm the battery or camera?

I’ve kept this Android plugged in (without using it while charging) and the battery eventually it swelled up and I had to replace it.

Does anyone know for sure?