diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 3fdff21e591b..755b999e171e 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -538,8 +538,8 @@ function preLoadCss(cssUrl) {
return;
}
- // @ts-expect-error
- if (document.activeElement.tagName === "INPUT" &&
+ if (document.activeElement &&
+ document.activeElement.tagName === "INPUT" &&
// @ts-expect-error
document.activeElement.type !== "checkbox" &&
// @ts-expect-error