0

I'm trying to run simple script using stack snippets:

var img = document.getElementsByTagName('img')[0];
Tesseract.recognize(img, function(err, result) {
  console.log(result);
});
<script src="http://tenso.rs/tesseract.js" crossorigin="anonymous"></script>
<img src="https://www.w3.org/TR/SVGTiny12/examples/textArea01.png"/>

But got error: Uncaught ReferenceError: Tesseract is not defined, why? when I open http://tenso.rs/tesseract.js it redirect to https://cdn.rawgit.com/naptha/tesseract.js/master/lib/Tesseract.2015.07.26.js and there is the code, but when I include that file instead I got unknown error Script Error because of cross origin. How to resolve this?

jcubic
  • 61,973
  • 54
  • 229
  • 402

1 Answers1

-1

Here just works fine: Working example

https://cdn.rawgit.com/naptha/tesseract.js/master/lib/Tesseract.2015.07.26.js

Just use the cdn url, that way you won't get a crossbrowser exception. (http request over an https server, such as jsfiddle).

Edit: Also you are calling a function not defined yet (You call the function before loading the script that defines it). You can fix this placing the script at the end of the code.

var img = document.getElementsByTagName('img')[0];
Tesseract.recognize(img, function(err, result) {
  console.log(result);
});
  • 1
    It have different exception `Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.` – jcubic Jun 06 '16 at 14:35
  • Check this other post about this issue: http://stackoverflow.com/questions/22097747/getimagedata-error-the-canvas-has-been-tainted-by-cross-origin-data – Victor Perez Jun 06 '16 at 14:48
  • if i run it locally i get tesseract.js:356 Uncaught DataCloneError: Failed to execute 'postMessage' on 'Worker': An object could not be cloned. – Toolkit Oct 24 '16 at 14:14