In 2017, a multimessenger era started with the first gravitational wave detection from the merger of two neutron stars (GW170817) and the rich electromagnetic follow-up. The most exciting electromagnetic counterpart was the kilonova. This provides an answer to the long-standing question of how and where heavy elements are produced in the universe. The neutron-rich material ejected during the neutron star merger undergoes an r-process (rapid neutron capture process) that produces heavy elements and a kilonova. Moreover, observations of abundances from the oldest stars reveal an additional r-process contribution of a rare and fast event, which could be core-collapse supernovae with strong magnetic fields, so called magneto-rotational supernovae. Now we can use neutron star mergers and core-collapse supernovae as cosmic laboratories to test nuclear physics under extreme conditions and to understand the origin and history of heavy elements. We combine hydrodynamic simulations of neutron star mergers and supernovae including state-of-the-art microphysics, with nucleosynthesis calculations involving extreme neutron-rich nuclei, and forefront observations of stellar abundances in the Milky Way and in orbiting dwarf galaxies. This opens up a new frontier to use the freshly synthesized elements to benchmark simulations against observations. The nucleosynthesis depends on astrophysical conditions (e.g., mass of the neutron stars) and on the microphysics included (equation of state and neutrino interactions). Therefore, comparing calculated abundances based on simulations to observations of the oldest stars and future kilonovae will lead to ground-breaking discoveries for supernovae, mergers, the extreme physics involved, and the origin of heavy elements.