From eb288fb885b0bb8a56e17b0e9396414df6713032 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Mon, 19 Aug 2019 18:00:10 +0200 Subject: [PATCH] Add option not to use a blob: URL for the worker source --- src/browser/index.js | 5 +++-- src/common/TesseractWorker.js | 1 + src/common/options.js | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/browser/index.js b/src/browser/index.js index c9fd31b..06e62ab 100644 --- a/src/browser/index.js +++ b/src/browser/index.js @@ -124,10 +124,11 @@ exports.defaultOptions = { * @param {object} instance - TesseractWorker instance * @param {object} options * @param {string} options.workerPath - worker script path + * @param {boolean} options.preventBlobURL - do not use a blob: URL for the worker script */ -exports.spawnWorker = (instance, { workerPath }) => { +exports.spawnWorker = (instance, { workerPath, preventBlobURL }) => { let worker; - if (Blob && URL) { + if (Blob && URL && !preventBlobURL) { const blob = new Blob([`importScripts("${workerPath}");`], { type: 'application/javascript', }); diff --git a/src/common/TesseractWorker.js b/src/common/TesseractWorker.js index 01d5090..af2d082 100644 --- a/src/common/TesseractWorker.js +++ b/src/common/TesseractWorker.js @@ -43,6 +43,7 @@ class TesseractWorker { * @param {string} [options.cachePath=.] - @see {@link https://github.com/jeromewu/tesseract.js-utils/blob/master/src/loadLang.js} * @param {string} [options.cacheMethod=write] - @see {@link https://github.com/jeromewu/tesseract.js-utils/blob/master/src/loadLang.js} * @param {string} [options.dataPath=.] - @see {@link https://github.com/jeromewu/tesseract.js-utils/blob/master/src/loadLang.js} + * @param {boolean} [options.preventBlobURL=false] - do not use a blob: URL for the worker script * */ constructor(options = {}) { diff --git a/src/common/options.js b/src/common/options.js index 36a9239..df55425 100644 --- a/src/common/options.js +++ b/src/common/options.js @@ -8,6 +8,7 @@ module.exports = { * of 20 MB. */ langPath: 'https://tessdata.projectnaptha.com/4.0.0', + preventBlobURL: false, }, /* * default params for recognize()