Skip to content

Commit

Permalink
Merge branch 'staging' into 10525-story
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlerza authored Dec 4, 2024
2 parents 6845d3b + 6a6c54e commit 1465425
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions web-client/src/applicationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {};

Expand Down Expand Up @@ -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;
},
Expand Down

0 comments on commit 1465425

Please sign in to comment.