The properties of gamma-ray bursts (GRBs) and their afterglows are used to investigate the location of star formation activity through the history of the Universe. This approach is motivated by the following: (i) GRBs are thought to be associated with the deaths of massive stars and so the GRB rate ought to follow the massive star formation rate, (ii) GRBs are the final evolutionary phase of these short-lived stars, which do not travel far from their birthplace, and so should be located where the stars formed, and (iii) The differential effects of dust extinction on GRB afterglows between the X-ray and optical wavebands can reveal whether or not large amounts of gas and dust are present in GRB host galaxies. From recent evidence, we estimate that a significant fraction (about 75%) of stars in the Universe formed in galaxies that are brightest at rest-frame far-infrared (IR) wavelengths. This value is marginally consistent with observations: 60 +/- 15% of GRBs have no detected optical afterglow, whereas almost all have an X-ray afterglow. If the X-ray afterglows of a large number of GRBs disappear at soft X-ray wavelengths (<2 keV), then this would provide strong evidence for dominant heavily obscured star-formation activity. Far-IR and submillimetre studies of GRB hosts would also test this idea: about 20% of hosts should be detectable using SCUBA.