In Roman times, Emperor Nero liked to watch gladiator fights through emeralds, to avoid the sun getting in his eyes. It is likely that humans in other time periods prior to the invention of sunglasses may also have put various materials over their face to protect their eyes from the brightness of the sun, but little evidence exists for this until we reach the 12th century.
The 12th century is when sunglasses were invented properly, in China. They were using lenses made from imperfection-heavy quartz to block out the light from the sun, and primitive frames to hold them against the wearers face. These sunglasses didnt protect against harmful UV rays or help their wearer to see any better (in fact, they made it very difficult to see), but they provided some relief from having the bright sun constantly shining into their eyes. Only the rich had them, but they found many uses for them Chinese rulers and judges, for example, found that they could use the sunglasses to hide the expression on their face when they were talking to someone, allowing them to seem emotionally detached from situations.
It was not until the 20th century that sunglasses really took off, though,...