Merge pull request #19945 from Snuffleupagus/NetworkStream-rm-Node-Error

Remove Node.js-specific checks when using the Fetch API
This commit is contained in:
Tim van der Meij 2025-05-18 12:05:13 +02:00 committed by GitHub
commit f6e4b1cf4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,