From dc4eb997d49befa16054fa3b1565ec7a79cedb21 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Mon, 18 Nov 2024 15:24:54 -0500 Subject: [PATCH 1/2] conditionally load pdfjs legacy build --- web-client/src/applicationContext.ts | 44 ++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/web-client/src/applicationContext.ts b/web-client/src/applicationContext.ts index a9cf426f7de..fc114a43ab4 100644 --- a/web-client/src/applicationContext.ts +++ b/web-client/src/applicationContext.ts @@ -362,6 +362,34 @@ const reduce = ImageBlobReduce({ let user; let broadcastChannel; +const clientSupportsES2022 = (() => { + try { + // Check Object.hasOwn (introduced in ES2022) + // @ts-ignore + if (typeof Object.hasOwn !== 'function') { + return false; + } + + // Check private fields + class TestPrivateFields { + #privateField: boolean; + constructor() { + this.#privateField = true; + } + hasPrivateField() { + return this.#privateField; + } + } + const instance = new TestPrivateFields(); + if (!instance.hasPrivateField()) { + return false; + } + + return true; + } catch (e) { + return false; // Any failure indicates lack of support + } +})(); let forceRefreshCallback: () => {}; @@ -669,9 +697,19 @@ const applicationContext = { }, }), getPdfJs: async () => { - const pdfjsLib = (await import('pdfjs-dist')).default; - const pdfjsWorker = (await import('pdfjs-dist/build/pdf.worker.entry')) - .default; + const pdfjsLib = ( + await import( + clientSupportsES2022 ? 'pdfjs-dist' : 'pdfjs-dist/legacy/build/pdf' + ) + ).default; + const pdfjsWorker = ( + await import( + clientSupportsES2022 + ? 'pdfjs-dist/build/pdf.worker.entry' + : 'pdfjs-dist/legacy/build/pdf.worker.entry' + ) + ).default; + pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker; return pdfjsLib; }, From e435a56499f29584d7cbeb36d6dd4b994661e580 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 21 Nov 2024 11:32:24 -0500 Subject: [PATCH 2/2] load-legacy-pdfjs-conditionally: add another feature in the feature check list --- web-client/src/applicationContext.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web-client/src/applicationContext.ts b/web-client/src/applicationContext.ts index fc114a43ab4..905ee493393 100644 --- a/web-client/src/applicationContext.ts +++ b/web-client/src/applicationContext.ts @@ -370,6 +370,11 @@ const clientSupportsES2022 = (() => { return false; } + // Check Array.prototype.at + if (!Array.prototype.at) { + return false; + } + // Check private fields class TestPrivateFields { #privateField: boolean;