diff --git a/README.md b/README.md index cea47bd43..f856e69a0 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Feel free to stop by our [Matrix room](https://chat.mozilla.org/#/room/#pdfjs:mo ### Online demo Please note that the "Modern browsers" version assumes native support for -features such as e.g. `async`/`await`, `ReadableStream`, optional chaining, -nullish coalescing, and private `class` fields/methods. +features such as `async`/`await`, optional chaining, nullish coalescing, +and private `class` fields/methods. + Modern browsers: https://mozilla.github.io/pdf.js/web/viewer.html diff --git a/external/dist/README.md b/external/dist/README.md index 3af42efd8..c3348a54b 100644 --- a/external/dist/README.md +++ b/external/dist/README.md @@ -8,8 +8,7 @@ This is a pre-built version of the PDF.js source code. It is automatically generated by the build scripts. For usage with older browsers or environments, without support for modern -features such as e.g. `async`/`await`, `ReadableStream`, optional chaining, -nullish coalescing, and private `class` fields/methods; please see the `legacy` -folder. +features such as `async`/`await`, optional chaining, nullish coalescing, +and private `class` fields/methods; please see the `legacy/` folder. See https://github.com/mozilla/pdf.js for learning and contributing. diff --git a/gulpfile.js b/gulpfile.js index 387df8f42..8a4b2cd85 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2042,6 +2042,9 @@ function packageBowerJson() { homepage: DIST_HOMEPAGE, bugs: DIST_BUGS_URL, license: DIST_LICENSE, + dependencies: { + "web-streams-polyfill": "^3.2.0", + }, peerDependencies: { "worker-loader": "^3.0.8", // Used in `external/dist/webpack.js`. }, diff --git a/src/core/worker.js b/src/core/worker.js index 08b4eae20..6c4989124 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -133,15 +133,15 @@ class WorkerMessageHandler { // Ensure that (primarily) Node.js users won't accidentally attempt to use // a non-translated/non-polyfilled build of the library, since that would // quickly fail anyway because of missing functionality. - if ( - (typeof PDFJSDev === "undefined" || PDFJSDev.test("SKIP_BABEL")) && - typeof ReadableStream === "undefined" - ) { - throw new Error( + if (typeof ReadableStream === "undefined") { + const partialMsg = "The browser/environment lacks native support for critical " + - "functionality used by the PDF.js library (e.g. `ReadableStream`); " + - "please use a `legacy`-build instead." - ); + "functionality used by the PDF.js library (e.g. `ReadableStream`); "; + + if (isNodeJS) { + throw new Error(partialMsg + "please use a `legacy`-build instead."); + } + throw new Error(partialMsg + "please update to a supported browser."); } } diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index b3bdbb353..6da5c4751 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* globals __non_webpack_require__ */ import { isNodeJS } from "./is_node.js"; @@ -69,21 +70,12 @@ if ( // Support: Node.js (function checkReadableStream() { - if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) { - // The current image decoders are synchronous, hence `ReadableStream` - // shouldn't need to be polyfilled for the IMAGE_DECODERS build target. - return; - } - if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { - // Slightly reduce the size of the Chromium-extension, given - // that `ReadableStream` has been supported since Chrome 43. - return; - } if (globalThis.ReadableStream || !isNodeJS) { return; } - globalThis.ReadableStream = - require("web-streams-polyfill/dist/ponyfill.js").ReadableStream; + globalThis.ReadableStream = __non_webpack_require__( + "web-streams-polyfill/dist/ponyfill.js" + ).ReadableStream; })(); // Support: Firefox<94, Chrome<98, Safari, Node.js<17.0.0