From fa0e559fe28e44245505a3cdb836b123faf7f67b Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Tue, 14 Feb 2017 15:00:52 -0600 Subject: [PATCH] New node.js check to protect from webpack. --- src/core/worker.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/worker.js b/src/core/worker.js index adbb6137e..fd7cc159b 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* globals module */ +/* globals process, __pdfjsdev_webpack__ */ 'use strict'; @@ -1012,9 +1012,16 @@ function initializeWorker() { handler.send('ready', null); } +function isNodeJS() { + // The if below protected by __pdfjsdev_webpack__ check from webpack parsing. + if (typeof __pdfjsdev_webpack__ === 'undefined') { + return typeof process === 'object' && process + '' === '[object process]'; + } + return false; +} + // Worker thread (and not node.js)? -if (typeof window === 'undefined' && - !(typeof module !== 'undefined' && module.require)) { +if (typeof window === 'undefined' && !isNodeJS()) { initializeWorker(); }