How sharks and other animals evolved electroreception to find their prey

Many creatures can use electric fields to communicate, sense predators or stun their prey with powerful electric shocks, but how this ability came about was a mystery.