From 44025a3ec12d5d9969a7c2ba1079ba1d196339e0 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Tue, 23 Jan 2018 20:12:03 +0100 Subject: [PATCH 1/2] Explicitly state intended support in compatibility.js Add comments with supported browser versions where missing. Method: - Use MDN compat tables if available. - Otherwise test in Chrome (31+) otherwise. (the Chrome Web Store does not update older versions of Chrome, so probably nobody is interested in even older versions, even though there is an existing comment for Chrome<29 at `document.currentScript`). --- src/shared/compatibility.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index 742d3aa85..a12e93bda 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -75,6 +75,7 @@ PDFJS.compatibilityChecked = true; })(); // Checks if navigator.language is supported +// Support: IE<11 (function checkNavigatorLanguage() { if (typeof navigator === 'undefined') { return; @@ -151,7 +152,7 @@ PDFJS.compatibilityChecked = true; })(); // Provides support for Object.values in legacy browsers. -// Support: IE. +// Support: IE, Chrome<54 (function checkObjectValues() { if (Object.values) { return; @@ -160,7 +161,7 @@ PDFJS.compatibilityChecked = true; })(); // Provides support for Array.prototype.includes in legacy browsers. -// Support: IE. +// Support: IE, Chrome<47 (function checkArrayIncludes() { if (Array.prototype.includes) { return; @@ -169,7 +170,7 @@ PDFJS.compatibilityChecked = true; })(); // Provides support for Math.log2 in legacy browsers. -// Support: IE. +// Support: IE, Chrome<38 (function checkMathLog2() { if (Math.log2) { return; @@ -187,7 +188,7 @@ PDFJS.compatibilityChecked = true; })(); // Provides support for Number.isInteger in legacy browsers. -// Support: IE. +// Support: IE, Chrome<34 (function checkNumberIsInteger() { if (Number.isInteger) { return; @@ -195,6 +196,7 @@ PDFJS.compatibilityChecked = true; Number.isInteger = require('core-js/fn/number/is-integer'); })(); +// Support: IE, Safari<8, Chrome<32 (function checkPromise() { if (globalScope.Promise) { return; @@ -202,6 +204,7 @@ PDFJS.compatibilityChecked = true; globalScope.Promise = require('core-js/fn/promise'); })(); +// Support: IE<11, Safari<8, Chrome<36 (function checkWeakMap() { if (globalScope.WeakMap) { return; @@ -209,6 +212,7 @@ PDFJS.compatibilityChecked = true; globalScope.WeakMap = require('core-js/fn/weak-map'); })(); +// Support: IE, Chrome<32 // Polyfill from https://github.com/Polymer/URL /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ From 5d1c541702bd608d476d62bd4de051bb9b8d6171 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Fri, 26 Jan 2018 12:18:57 +0100 Subject: [PATCH 2/2] Enable some polyfills for compat with Chrome 49 Successfully tested with Chrome 49. --- src/shared/compatibility.js | 28 ++++++++++++++++++---------- src/shared/streams_polyfill.js | 3 --- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index a12e93bda..57d9c47c7 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -18,10 +18,16 @@ // Skip compatibility checks for the extensions and if we already ran // this module. if ((typeof PDFJSDev === 'undefined' || - !PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) && + !PDFJSDev.test('FIREFOX || MOZCENTRAL')) && (typeof PDFJS === 'undefined' || !PDFJS.compatibilityChecked)) { +// In the Chrome extension, most of the polyfills are unnecessary. +// We support down to Chrome 49, because it's still commonly used by Windows XP +// users - https://github.com/mozilla/pdf.js/issues/9397 +if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('CHROME')) { + var globalScope = require('./global_scope'); + const isNodeJS = require('./is_node'); var userAgent = (typeof navigator !== 'undefined' && navigator.userAgent) || ''; @@ -151,15 +157,6 @@ PDFJS.compatibilityChecked = true; }; })(); -// Provides support for Object.values in legacy browsers. -// Support: IE, Chrome<54 -(function checkObjectValues() { - if (Object.values) { - return; - } - Object.values = require('core-js/fn/object/values'); -})(); - // Provides support for Array.prototype.includes in legacy browsers. // Support: IE, Chrome<47 (function checkArrayIncludes() { @@ -865,4 +862,15 @@ PDFJS.compatibilityChecked = true; globalScope.URL = JURL; })(); +} // End of !PDFJSDev.test('CHROME') + +// Provides support for Object.values in legacy browsers. +// Support: IE, Chrome<54 +(function checkObjectValues() { + if (Object.values) { + return; + } + Object.values = require('core-js/fn/object/values'); +})(); + } diff --git a/src/shared/streams_polyfill.js b/src/shared/streams_polyfill.js index e35da6cd9..7c8e85d87 100644 --- a/src/shared/streams_polyfill.js +++ b/src/shared/streams_polyfill.js @@ -31,9 +31,6 @@ if (typeof ReadableStream !== 'undefined') { if (isReadableStreamSupported) { exports.ReadableStream = ReadableStream; } else { - if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) { - throw new Error('ReadableStream polyfill is not found for Chrome bundle'); - } exports.ReadableStream = require('../../external/streams/streams-lib').ReadableStream; }