[api-major] Remove the fallbackWorkerSrc
functionality in browsers
The user should *always* provide a correct `GlobalWorkerOptions.workerSrc` value when using the PDF.js library in browser environments. Note that the fallback: - Has been deprecated ever since PR 11418, first released in version `2.4.456` over three years ago. - Was always a best-effort solution, with no guarantees that it'd actually work correctly. - With upcoming changes, w.r.t. outputting JavaScript modules, it'd now be more diffiult to determine the correct value.
This commit is contained in:
parent
8158628a90
commit
0a970ee443
@ -45,7 +45,6 @@ import {
|
|||||||
SerializableEmpty,
|
SerializableEmpty,
|
||||||
} from "./annotation_storage.js";
|
} from "./annotation_storage.js";
|
||||||
import {
|
import {
|
||||||
deprecated,
|
|
||||||
DOMCanvasFactory,
|
DOMCanvasFactory,
|
||||||
DOMCMapReaderFactory,
|
DOMCMapReaderFactory,
|
||||||
DOMFilterFactory,
|
DOMFilterFactory,
|
||||||
@ -1984,7 +1983,6 @@ class LoopbackPort {
|
|||||||
|
|
||||||
const PDFWorkerUtil = {
|
const PDFWorkerUtil = {
|
||||||
isWorkerDisabled: false,
|
isWorkerDisabled: false,
|
||||||
fallbackWorkerSrc: null,
|
|
||||||
fakeWorkerId: 0,
|
fakeWorkerId: 0,
|
||||||
};
|
};
|
||||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||||
@ -1993,17 +1991,9 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|||||||
// Workers aren't supported in Node.js, force-disabling them there.
|
// Workers aren't supported in Node.js, force-disabling them there.
|
||||||
PDFWorkerUtil.isWorkerDisabled = true;
|
PDFWorkerUtil.isWorkerDisabled = true;
|
||||||
|
|
||||||
PDFWorkerUtil.fallbackWorkerSrc = PDFJSDev.test("LIB")
|
GlobalWorkerOptions.workerSrc ||= PDFJSDev.test("LIB")
|
||||||
? "../pdf.worker.js"
|
? "../pdf.worker.js"
|
||||||
: "./pdf.worker.js";
|
: "./pdf.worker.js";
|
||||||
} else if (typeof document === "object") {
|
|
||||||
const pdfjsFilePath = document?.currentScript?.src;
|
|
||||||
if (pdfjsFilePath) {
|
|
||||||
PDFWorkerUtil.fallbackWorkerSrc = pdfjsFilePath.replace(
|
|
||||||
/(\.(?:min\.)?js)(\?.*)?$/i,
|
|
||||||
".worker$1$2"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if URLs have the same origin. For non-HTTP based URLs, returns false.
|
// Check if URLs have the same origin. For non-HTTP based URLs, returns false.
|
||||||
@ -2119,7 +2109,7 @@ class PDFWorker {
|
|||||||
// Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
|
// Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
|
||||||
if (
|
if (
|
||||||
!PDFWorkerUtil.isWorkerDisabled &&
|
!PDFWorkerUtil.isWorkerDisabled &&
|
||||||
!PDFWorker._mainThreadWorkerMessageHandler
|
!PDFWorker.#mainThreadWorkerMessageHandler
|
||||||
) {
|
) {
|
||||||
let { workerSrc } = PDFWorker;
|
let { workerSrc } = PDFWorker;
|
||||||
|
|
||||||
@ -2308,19 +2298,10 @@ class PDFWorker {
|
|||||||
if (GlobalWorkerOptions.workerSrc) {
|
if (GlobalWorkerOptions.workerSrc) {
|
||||||
return GlobalWorkerOptions.workerSrc;
|
return GlobalWorkerOptions.workerSrc;
|
||||||
}
|
}
|
||||||
if (
|
|
||||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
|
||||||
PDFWorkerUtil.fallbackWorkerSrc !== null
|
|
||||||
) {
|
|
||||||
if (!isNodeJS) {
|
|
||||||
deprecated('No "GlobalWorkerOptions.workerSrc" specified.');
|
|
||||||
}
|
|
||||||
return PDFWorkerUtil.fallbackWorkerSrc;
|
|
||||||
}
|
|
||||||
throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
|
throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
|
||||||
}
|
}
|
||||||
|
|
||||||
static get _mainThreadWorkerMessageHandler() {
|
static get #mainThreadWorkerMessageHandler() {
|
||||||
try {
|
try {
|
||||||
return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
|
return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
|
||||||
} catch {
|
} catch {
|
||||||
@ -2331,7 +2312,7 @@ class PDFWorker {
|
|||||||
// Loads worker code into the main-thread.
|
// Loads worker code into the main-thread.
|
||||||
static get _setupFakeWorkerGlobal() {
|
static get _setupFakeWorkerGlobal() {
|
||||||
const loader = async () => {
|
const loader = async () => {
|
||||||
const mainWorkerMessageHandler = this._mainThreadWorkerMessageHandler;
|
const mainWorkerMessageHandler = this.#mainThreadWorkerMessageHandler;
|
||||||
|
|
||||||
if (mainWorkerMessageHandler) {
|
if (mainWorkerMessageHandler) {
|
||||||
// The worker was already loaded using e.g. a `<script>` tag.
|
// The worker was already loaded using e.g. a `<script>` tag.
|
||||||
|
Loading…
Reference in New Issue
Block a user