Skip to content

Commit 6a6c54e

Browse files
authored
Merge pull request #5627 from flexion/load-legacy-pdfjs-if-legacy-browser
10531: Load legacy pdfjs if legacy browser
2 parents ec9f483 + 8bafb04 commit 6a6c54e

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

web-client/src/applicationContext.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,39 @@ const reduce = ImageBlobReduce({
363363

364364
let user;
365365
let broadcastChannel;
366+
const clientSupportsES2022 = (() => {
367+
try {
368+
// Check Object.hasOwn (introduced in ES2022)
369+
// @ts-ignore
370+
if (typeof Object.hasOwn !== 'function') {
371+
return false;
372+
}
373+
374+
// Check Array.prototype.at
375+
if (!Array.prototype.at) {
376+
return false;
377+
}
378+
379+
// Check private fields
380+
class TestPrivateFields {
381+
#privateField: boolean;
382+
constructor() {
383+
this.#privateField = true;
384+
}
385+
hasPrivateField() {
386+
return this.#privateField;
387+
}
388+
}
389+
const instance = new TestPrivateFields();
390+
if (!instance.hasPrivateField()) {
391+
return false;
392+
}
393+
394+
return true;
395+
} catch (e) {
396+
return false; // Any failure indicates lack of support
397+
}
398+
})();
366399

367400
let forceRefreshCallback: () => {};
368401

@@ -671,9 +704,19 @@ const applicationContext = {
671704
},
672705
}),
673706
getPdfJs: async () => {
674-
const pdfjsLib = (await import('pdfjs-dist')).default;
675-
const pdfjsWorker = (await import('pdfjs-dist/build/pdf.worker.entry'))
676-
.default;
707+
const pdfjsLib = (
708+
await import(
709+
clientSupportsES2022 ? 'pdfjs-dist' : 'pdfjs-dist/legacy/build/pdf'
710+
)
711+
).default;
712+
const pdfjsWorker = (
713+
await import(
714+
clientSupportsES2022
715+
? 'pdfjs-dist/build/pdf.worker.entry'
716+
: 'pdfjs-dist/legacy/build/pdf.worker.entry'
717+
)
718+
).default;
719+
677720
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker;
678721
return pdfjsLib;
679722
},

0 commit comments

Comments
 (0)