  We provide a systematic and updated discussion of a research line carried out
by our group over the last few years, in which gravity is modified at
cosmological distances by the introduction of nonlocal terms, assumed to emerge
at an effective level from the infrared behavior of the quantum theory. The
requirement of producing a viable cosmology turns out to be very stringent and
basically selects a unique model, in which the nonlocal term describes an
effective mass for the conformal mode. We discuss how such a specific structure
could emerge from a fundamental local theory of gravity, and we perform a
detailed comparison of this model with the most recent cosmological datasets,
confirming that it fits current data at the same level as $\Lambda$CDM.
  Most notably, the model has striking predictions in the sector of tensor
perturbations, leading to a very large effect in the propagation of
gravitational wave (GWs) over cosmological distances. At the redshifts relevant
for the next generation of GW detectors such as Einstein Telescope, Cosmic
Explorer and LISA, this leads to deviations from GR that could be as large as
$80\%$, and could be verified with the detection of just a single coalescing
binary with electromagnetic counterpart. This would also have potentially
important consequences for the search of the counterpart since, for a given
luminosity distance to the source, as inferred through the GW signal, the
actual source redshift could be significantly different from that predicted by
$\Lambda$CDM. At the redshifts relevant for advanced LIGO/Virgo/Kagra the
effect is smaller, but still potentially observable over a few years of runs at
target sensitivity.
