From 2dececf4450e14bb25710ba7b2890b7bfb9baa53 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 14 Feb 2022 12:01:30 +0100 Subject: [PATCH 1/2] Remove the `typeof navigator`-checks in the `web/app_options.js` file Given that the `Navigator` interface has been available since "forever", please see https://developer.mozilla.org/en-US/docs/Web/API/Navigator#browser_compatibility, it's somewhat difficult to see why these checks are actually necessary since the viewer is only intended for usage in browsers. Looking at the history of the code, this functionality was originally placed in the general `src/shared/compatibility.js` file which could thus run in e.g. worker-threads and Node.js environments (where the `Navigator` interface isn't available). --- web/app_options.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/web/app_options.js b/web/app_options.js index f4b58d2c2..dfb83a01a 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -15,12 +15,16 @@ const compatibilityParams = Object.create(null); if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { - const userAgent = - (typeof navigator !== "undefined" && navigator.userAgent) || ""; - const platform = - (typeof navigator !== "undefined" && navigator.platform) || ""; - const maxTouchPoints = - (typeof navigator !== "undefined" && navigator.maxTouchPoints) || 1; + if ( + typeof PDFJSDev !== "undefined" && + PDFJSDev.test("LIB") && + typeof navigator === "undefined" + ) { + globalThis.navigator = Object.create(null); + } + const userAgent = navigator.userAgent || ""; + const platform = navigator.platform || ""; + const maxTouchPoints = navigator.maxTouchPoints || 1; const isAndroid = /Android/.test(userAgent); const isIOS = @@ -278,7 +282,7 @@ if ( }; defaultOptions.locale = { /** @type {string} */ - value: typeof navigator !== "undefined" ? navigator.language : "en-US", + value: navigator.language || "en-US", kind: OptionKind.VIEWER, }; defaultOptions.sandboxBundleSrc = { From 996396a9144ac9deb3d7bcdc82ba4363a31e2c25 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 14 Feb 2022 12:13:30 +0100 Subject: [PATCH 2/2] Change `PasswordPrompt.close` to an `async` method This is consistent with the `open` method, and it actually *ever so slightly* reduces the size of the file. --- web/password_prompt.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/web/password_prompt.js b/web/password_prompt.js index 442cdb809..6631783c7 100644 --- a/web/password_prompt.js +++ b/web/password_prompt.js @@ -81,10 +81,9 @@ class PasswordPrompt { ); } - close() { - this.overlayManager.close(this.overlayName).then(() => { - this.input.value = ""; - }); + async close() { + await this.overlayManager.close(this.overlayName); + this.input.value = ""; } #verify() {