Skip to content

Commit a882195

Browse files
committed
Remove Node.js-specific checks when using the Fetch API
Given that Node.js has full support for the Fetch API since version 21, see the "History" data at https://nodejs.org/api/globals.html#fetch, it seems unnecessary for us to manually check for various globals before using it. Since our primary development target is browsers in general, and Firefox in particular, being able to remove Node.js-specific compatibility code is always helpful. Note that we still, for now, support Node.js version 20 and if the relevant globals are not available then Errors will instead be thrown from within the `PDFFetchStream` class.
1 parent f72f240 commit a882195

1 file changed

Lines changed: 7 additions & 25 deletions

File tree

src/display/api.js

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -462,32 +462,14 @@ function getDocument(src = {}) {
462462
if (!url) {
463463
throw new Error("getDocument - no `url` parameter provided.");
464464
}
465-
let NetworkStream;
466-
467-
if (
468-
typeof PDFJSDev !== "undefined" &&
469-
PDFJSDev.test("GENERIC") &&
470-
isNodeJS
471-
) {
472-
if (isValidFetchUrl(url)) {
473-
if (
474-
typeof fetch === "undefined" ||
475-
typeof Response === "undefined" ||
476-
!("body" in Response.prototype)
477-
) {
478-
throw new Error(
479-
"getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`."
480-
);
481-
}
482-
NetworkStream = PDFFetchStream;
483-
} else {
484-
NetworkStream = PDFNodeStream;
485-
}
486-
} else {
487-
NetworkStream = isValidFetchUrl(url)
488-
? PDFFetchStream
465+
// eslint-disable-next-line no-nested-ternary
466+
const NetworkStream = isValidFetchUrl(url)
467+
? PDFFetchStream
468+
: typeof PDFJSDev !== "undefined" &&
469+
PDFJSDev.test("GENERIC") &&
470+
isNodeJS
471+
? PDFNodeStream
489472
: PDFNetworkStream;
490-
}
491473

492474
networkStream = new NetworkStream({
493475
url,

0 commit comments

Comments
 (0)