diff --git a/README.md b/README.md index a025a1e..f452404 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Or you can grab copies of `tesseract.js` and `worker.js` from the [dist folder]( window.Tesseract = Tesseract.create({ workerPath: '/path/to/worker.js', langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/', - tesseractPath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js', + corePath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js', }) ``` diff --git a/dist/tesseract.js b/dist/tesseract.js index a4c6aaf..377c4b2 100644 --- a/dist/tesseract.js +++ b/dist/tesseract.js @@ -271,7 +271,7 @@ process.umask = function() { return 0; }; var defaultOptions = { workerPath: 'https://cdn.rawgit.com/naptha/tesseract.js/0.1.3/dist/worker.js', - tesseractPath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js', + corePath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js', langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/' }; @@ -328,6 +328,12 @@ function loadImage(image, cb) { xhr.onload = function (e) { return loadImage(xhr.response, cb); }; + xhr.onerror = function (e) { + if (/^https?:\/\//.test(image) && !/^https:\/\/crossorigin.me/.test(image)) { + console.debug('Attempting to load image with CORS proxy'); + loadImage('https://crossorigin.me/' + image, cb); + } + }; xhr.send(null); return; } diff --git a/dist/worker.js b/dist/worker.js index 81960af..136917c 100644 --- a/dist/worker.js +++ b/dist/worker.js @@ -11944,7 +11944,7 @@ global.addEventListener('message', function (e) { exports.getCore = function (req, res) { if (!global.TesseractCore) { res.progress({ status: 'loading tesseract core' }); - importScripts(req.workerOptions.tesseractPath); + importScripts(req.workerOptions.corePath); res.progress({ status: 'loaded tesseract core' }); } return TesseractCore; diff --git a/src/browser/index.js b/src/browser/index.js index 656f4b0..d0172d8 100644 --- a/src/browser/index.js +++ b/src/browser/index.js @@ -1,6 +1,6 @@ var defaultOptions = { workerPath: 'https://cdn.rawgit.com/naptha/tesseract.js/0.1.3/dist/worker.js', - tesseractPath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js', + corePath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js', langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/', } @@ -56,6 +56,12 @@ function loadImage(image, cb){ xhr.open('GET', image, true) xhr.responseType = "blob"; xhr.onload = e => loadImage(xhr.response, cb); + xhr.onerror = function(e){ + if(/^https?:\/\//.test(image) && !/^https:\/\/crossorigin.me/.test(image)){ + console.debug('Attempting to load image with CORS proxy') + loadImage('https://crossorigin.me/' + image, cb) + } + } xhr.send(null) return } diff --git a/src/browser/worker.js b/src/browser/worker.js index d392851..13862b8 100644 --- a/src/browser/worker.js +++ b/src/browser/worker.js @@ -12,7 +12,7 @@ global.addEventListener('message', function(e){ exports.getCore = function(req, res){ if(!global.TesseractCore){ res.progress({ status: 'loading tesseract core' }) - importScripts(req.workerOptions.tesseractPath) + importScripts(req.workerOptions.corePath) res.progress({ status: 'loaded tesseract core' }) } return TesseractCore