Browse Source

Fix documet is not defined issue

pull/265/head
Jerome Wu 6 years ago
parent
commit
71a9cb9210
  1. 2
      src/browser/index.js
  2. 3
      src/browser/worker.js
  3. 6
      src/common/TesseractWorker.js

2
src/browser/index.js

@ -68,7 +68,7 @@ exports.defaultOptions = { @@ -68,7 +68,7 @@ exports.defaultOptions = {
exports.spawnWorker = (instance, { workerPath }) => {
let worker;
if (window.Blob && window.URL) {
const blob = new Blob([`importScripts("${resolveURL(workerPath)}");`]);
const blob = new Blob([`importScripts("${workerPath}");`]);
worker = new Worker(window.URL.createObjectURL(blob));
} else {
worker = new Worker(workerPath);

3
src/browser/worker.js

@ -9,7 +9,6 @@ @@ -9,7 +9,6 @@
*/
const check = require('check-types');
const resolveURL = require('resolve-url');
const workerUtils = require('../common/workerUtils');
/*
@ -27,7 +26,7 @@ workerUtils.setAdapter({ @@ -27,7 +26,7 @@ workerUtils.setAdapter({
getCore: (corePath, res) => {
if (check.undefined(global.TesseractCore)) {
res.progress({ status: 'loading tesseract core', progress: 0 });
global.importScripts(resolveURL(corePath));
global.importScripts(corePath);
/*
* Depending on whether the browser supports WebAssembly,
* the version of the TesseractCore will be different.

6
src/common/TesseractWorker.js

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
* @author Jerome Wu <jeromewus@gmail.com>
*/
const check = require('check-types');
const resolveURL = process.browser ? require('resolve-url') : s => s;
const adapter = require('../node');
const circularize = require('./circularize');
const TesseractJob = require('./TesseractJob');
@ -50,6 +51,11 @@ class TesseractWorker { @@ -50,6 +51,11 @@ class TesseractWorker {
...adapter.defaultOptions,
...options,
};
['corePath', 'workerPath', 'langPath'].forEach((key) => {
if (check.not.undefined(options[key])) {
this.options = { ...this.options, [key]: resolveURL(options[key]) };
}
});
this._currentJob = null;
this._queue = [];
}

Loading…
Cancel
Save