Browning onions takes patience: the heat must be relatively low, and you must remember to stir the onions from time to time in order for them not to brown too quickly.
Patience, unfortunately, is not my strongest virtue. I tend to hike up the heat, add more oil, and then get upset when the onions burn.
A colleague named Edward taught me to add a bit of water to the pan as soon as I think the onions are browning too quickly. The water not only prevents the onions from sticking and burning, but also cools the pan by lowering the temperature. (Plus, adding water instead of oil keeps the calories down.)
You can also apply this technique to cooking garlic, Brussels sprouts or any other vegetables.