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 wearer’s face. These sunglasses didn’t 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, as Hollywood stars started wearing them to protect their eyes from the bright studio lights. By 1929, an entrepreneur named Sam Foster had put sunglasses into mass production in America, and was doing a roaring trade through his company, Foster Grant of Atlantic City. In 1936, Polaroid filters were invented, allowing glasses to protect against UV rays for the first time, and making them a desirable item for health reasons as well as for reasons of fashion and comfort useful in World War II, when soldiers had to fight in the French summer. Since then, there have been few developments in sunglasses, with the basic science and materials remaining basically the same for the last seventy years but, like other useful inventions of the period, they remain a big seller.