Use spectroscopy as a form of analysis. According to Kirchoff's 2nd and 3rd
Laws, a gas which is either glowing, or one which is absorbing light from
a background, will show spectral lines which are characteristic of
the gas, i.e. hydrogen, helium, carbon, etc.
Transparency of Kirchoff's Laws.
There is actually a lot to this type of analysis; the prominence of the lines depends on the temperature as well as the chemical composition, but you can deduce the ``recipe'' for a gas via spectroscopy.
The results for the Sun are something of a surprise. In the
case of the Earth, most of the mass is in the form of ``heavy duty'' elements
like iron, silicon, magnesium, oxygen, etc.
The recipe for the Sun is given in the Table shown
It is shown in graphical form in Figure 16-15 on p375 of the text.
Almost all of the mass of the Sun is in the form of hydrogen and
helium, the simplest elements. This is also true of all the other stars.
It is the Earth that is the chemical oddball.