Use preferredDoc instead of window.document.