Update cookie to try harder to send headers

If the page dies early or if we somehow miss the event we try and write the cookies on destruct.