diff --git a/web-client/src/applicationContext.ts b/web-client/src/applicationContext.ts index a23143e4caa..a7d48508406 100644 --- a/web-client/src/applicationContext.ts +++ b/web-client/src/applicationContext.ts @@ -363,6 +363,39 @@ 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 Array.prototype.at + if (!Array.prototype.at) { + 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: () => {}; @@ -671,9 +704,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; },