Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10531: Load legacy pdfjs if legacy browser #5627

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading