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.
This commit is contained in:
parent
f72f240699
commit
a882195e9b
@ -462,32 +462,14 @@ function getDocument(src = {}) {
|
||||
if (!url) {
|
||||
throw new Error("getDocument - no `url` parameter provided.");
|
||||
}
|
||||
let NetworkStream;
|
||||
|
||||
if (
|
||||
typeof PDFJSDev !== "undefined" &&
|
||||
PDFJSDev.test("GENERIC") &&
|
||||
isNodeJS
|
||||
) {
|
||||
if (isValidFetchUrl(url)) {
|
||||
if (
|
||||
typeof fetch === "undefined" ||
|
||||
typeof Response === "undefined" ||
|
||||
!("body" in Response.prototype)
|
||||
) {
|
||||
throw new Error(
|
||||
"getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`."
|
||||
);
|
||||
}
|
||||
NetworkStream = PDFFetchStream;
|
||||
} else {
|
||||
NetworkStream = PDFNodeStream;
|
||||
}
|
||||
} else {
|
||||
NetworkStream = isValidFetchUrl(url)
|
||||
? PDFFetchStream
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
const NetworkStream = isValidFetchUrl(url)
|
||||
? PDFFetchStream
|
||||
: typeof PDFJSDev !== "undefined" &&
|
||||
PDFJSDev.test("GENERIC") &&
|
||||
isNodeJS
|
||||
? PDFNodeStream
|
||||
: PDFNetworkStream;
|
||||
}
|
||||
|
||||
networkStream = new NetworkStream({
|
||||
url,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user