From c36205f10d8e6dbefeba62fe6d6f2f184135a414 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 9 Sep 2022 10:27:16 +0200 Subject: [PATCH] Don't listen for window resolution changes in old browsers (PR 15319 follow-up) This is a slightly speculative change, based on something that I happened to notice while browsing MDN, to hopefully prevent PDF.js from outright breaking in older browsers. According to the following information on MDN, Safari didn't implement support for the necessary features until version 14: - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#browser_compatibility - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/change_event#browser_compatibility Given the browsers that we currently support only older versions of Safari should be affected, hence it seems reasonable to simply disable the functionality rather than trying to polyfill it. (It's interesting how it's very often Safari which is *much* slower than the other browsers at implementing new features.) --- web/app.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/app.js b/web/app.js index 63eb8a9ce..29eba0fd3 100644 --- a/web/app.js +++ b/web/app.js @@ -1971,6 +1971,13 @@ const PDFViewerApplication = { const mediaQueryList = window.matchMedia( `(resolution: ${window.devicePixelRatio || 1}dppx)` ); + if ( + typeof PDFJSDev !== "undefined" && + PDFJSDev.test("GENERIC && !SKIP_BABEL") && + typeof mediaQueryList.addEventListener !== "function" + ) { + return; // Not supported in Safari<14. + } mediaQueryList.addEventListener("change", addWindowResolutionChange, { once: true, });