The Mishna at Sanhedrin 6:2 says that anyone who confesses his sins before dying has a share in the World to Come. The Kitzur Shulchan Aruch at 193:13 says that when visiting a sick person who is near death, the visitor should engage the patient in conversation and encourage him to "recite the confession" (i.e. the vidui), and assure the patient that doing so does not assure his death, as many have recited the vidui and recovered. If he can only speak a bit, one is to have the patient say, "May my death be an atonement for all my sins," and that he should request forgiveness from any person he has wronged.
But I have seen patients who were unconscious before death and unable to confess their sins, so loved ones would recite the vidui for them. How can another person, even a close relative, confess the sins of the patient? Is there an implied agency? Where is that recognized?