From 740f2cab0cd390d5b7e8a70b6211090f891207e2 Mon Sep 17 00:00:00 2001 From: Jerome Wu Date: Wed, 25 Sep 2019 22:48:17 +0800 Subject: [PATCH] Add isBrowser to resolve DOMException undefined issue in node --- src/common/workerUtils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/workerUtils.js b/src/common/workerUtils.js index 86c3f12..5d582d0 100644 --- a/src/common/workerUtils.js +++ b/src/common/workerUtils.js @@ -13,6 +13,8 @@ const dump = require('./dump'); const { defaultParams } = require('./options'); const { OEM, PSM } = require('./types'); +const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; + /* * Tesseract Module returned by TesseractCore. */ @@ -230,7 +232,7 @@ const handleRecognize = ({ .then(() => ( loadLanguage({ langs, params, options }, res) .catch((e) => { - if (e instanceof DOMException) { + if (isBrowser && e instanceof DOMException) { /* * For some reason google chrome throw DOMException in loadLang, * while other browser is OK, for now we ignore this exception