diff --git a/docs/contents/getting_started/index.md b/docs/contents/getting_started/index.md index 63959edfb..e3c968dcf 100644 --- a/docs/contents/getting_started/index.md +++ b/docs/contents/getting_started/index.md @@ -108,8 +108,7 @@ Note that we only mention the most relevant files and folders. │   ├── display/ - display layer │   ├── shared/ - shared code between the core and display layers │   ├── interfaces.js - interface definitions for the core/display layers -│   ├── pdf.*.js - wrapper files for bundling -│   └── worker_loader.js - used for developer builds to load worker files +│   └── pdf.*.js - wrapper files for bundling ├── test/ - unit, font, reference, and integration tests ├── web/ - viewer layer ├── LICENSE diff --git a/src/display/api.js b/src/display/api.js index 5f6de4de7..b935f4f4c 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2101,7 +2101,12 @@ class PDFWorker { // Some versions of FF can't create a worker on localhost, see: // https://bugzilla.mozilla.org/show_bug.cgi?id=683280 - const worker = new Worker(workerSrc); + const worker = + (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) && + !workerSrc.endsWith("/build/pdf.worker.js") && + !workerSrc.endsWith("/src/worker_loader.js") + ? new Worker(workerSrc, { type: "module" }) + : new Worker(workerSrc); const messageHandler = new MessageHandler("main", "worker", worker); const terminateEarly = () => { worker.removeEventListener("error", onWorkerError); @@ -2289,7 +2294,7 @@ class PDFWorker { return mainWorkerMessageHandler; } if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) { - const worker = await import("pdfjs/core/worker.js"); + const worker = await import("pdfjs/pdf.worker.js"); return worker.WorkerMessageHandler; } if ( diff --git a/src/pdf.worker.js b/src/pdf.worker.js index ee44edd7e..900c0b02a 100644 --- a/src/pdf.worker.js +++ b/src/pdf.worker.js @@ -16,8 +16,10 @@ import { WorkerMessageHandler } from "./core/worker.js"; /* eslint-disable-next-line no-unused-vars */ -const pdfjsVersion = PDFJSDev.eval("BUNDLE_VERSION"); +const pdfjsVersion = + typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0; /* eslint-disable-next-line no-unused-vars */ -const pdfjsBuild = PDFJSDev.eval("BUNDLE_BUILD"); +const pdfjsBuild = + typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0; export { WorkerMessageHandler }; diff --git a/web/app.js b/web/app.js index 096fb61d6..70e150e94 100644 --- a/web/app.js +++ b/web/app.js @@ -304,7 +304,12 @@ const PDFViewerApplication = { const { mainContainer, viewerContainer } = this.appConfig, params = parseQueryString(hash); - if (params.get("disableworker") === "true") { + if ( + (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) && + params.get("workermodules") === "true" + ) { + AppOptions.set("workerSrc", "../src/pdf.worker.js"); + } else if (params.get("disableworker") === "true") { try { await loadFakeWorker(); } catch (ex) { @@ -2143,7 +2148,7 @@ async function loadFakeWorker() { GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc"); if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) { - window.pdfjsWorker = await import("pdfjs/core/worker.js"); + window.pdfjsWorker = await import("pdfjs/pdf.worker.js"); return; } await loadScript(PDFWorker.workerSrc);