Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current CDN Example Not Working #81

Closed
darth-cheney opened this issue Nov 10, 2016 · 15 comments
Closed

Current CDN Example Not Working #81

darth-cheney opened this issue Nov 10, 2016 · 15 comments

Comments

@darth-cheney
Copy link

darth-cheney commented Nov 10, 2016

Hi. I'm trying to conduct a very simple test using just a single HTML file and by including the tesseract.js script using the CDN source in the documentation:

<script src='https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js'></script>

My HTML file is simple:

<html>
    <head>
        <script src='https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js'></script>
        <title>Tesseract Test</title>
    </head>
    <body>
        <label for="fileInput">Choose File to OCR:</label>
        <input type="file" id="fileInput" name="fileInput"/>
        <br />
        <br />
        <div id="document-content">
        </div>
    </body>
    <script>
        document.addEventListener('DOMContentLoaded', function(){
            var fileInput = document.getElementById('fileInput');
            fileInput.addEventListener('change', handleInputChange);
        });

        function handleInputChange(event){
            var input = event.target;
            var file = input.files[0];
            console.log(file);
            Tesseract.recognize(file)
                .progress(function(message){
                    console.log(message);
                })
                .then(function(result){
                    var contentArea = document.getElementById('document-content');
                    console.log(result);
                })
                .catch(function(err){
                    console.error(err);
                });
        }
    </script>
</html>

But if I try to add an image, nothing happens in the console or anywhere else. This is also true if I clone the repository and instead load tesseract.js from the dist directory.

I see that the main (non-github) website for the project uses the CDN version 1.0.7, so I tried using that source instead. It came to life and started reporting back progress, but then threw the following error:

tesseract_example.html:27 Object {status: "loading tesseract core", progress: 0}
tesseract_example.html:27 Object {status: "loading tesseract core", progress: 1}
tesseract_example.html:27 Object {status: "initializing tesseract", progress: 0}
index.js:10 pre-main prep time: 65 ms
tesseract_example.html:27 Object {status: "initializing tesseract", progress: 1}
worker.js:11953 Uncaught DOMException: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': An object could not be cloned.()

(anonymous function)	@	worker.js:11953
respond	@	worker.js:12185
dispatchHandlers	@	worker.js:12205
(anonymous function)	@	worker.js:11952

Am I just doing this wrong somehow?

(Using Chrome 54 in OSX 10.11.)

@antimatter15
Copy link
Member

I just tried running your exact code snippet and it worked for me. Have you tried clearing your browser cache?

@darth-cheney
Copy link
Author

Clearing browser data seems to have improved things, but now I'm still getting the latter error I did when trying to use 1.0.7:

worker.js:8474 Uncaught DOMException: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': An object could not be cloned.()(anonymous function) @ worker.js:8474respond @ worker.js:8706dispatchHandlers @ worker.js:8726(anonymous function) @ worker.js:8473

Additionally, it would be good to understand just why clearing browser data made a difference at all

@iwollmann
Copy link

Appearantly this happens only when you trying access the page directly without a webserver.

@MacroChip
Copy link

MacroChip commented Dec 5, 2016

I am accessing the page directly without a webserver and am having the same issue.
Chrome on Linux Mint
Version 55.0.2883.75 (64-bit)

Object {status: "initializing tesseract", progress: 1}
worker.js:11953 Uncaught DOMException: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': An object could not be cloned.

It works fine on Firefox for Linux Mint
50.0.2

@iwollmann
Copy link

Exactly @MacroChip, that's what i said, you need to access through a web server.

@MacroChip
Copy link

@iwollmann Is that really the solution for Chrome? It works fine in Firefox without a web server.

@iwollmann
Copy link

I really don't know, here I am using with chrome in this scenario... =(

@Giusti
Copy link

Giusti commented Feb 14, 2017

Hey I have exactly the same problem but I am getting another error.

XMLHttpRequest cannot load . Can't create DocumentThreadableLoader

And

cdn.rawgit.com/naptha/tesseract.js/8b915dc/dist/tesseract.worker.js:1 Uncaught DataCloneError: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': An object could not be cloned.

@lgcagithub
Copy link

Maybe you should try to request all the files from web server. For example, Apache, Tomcat.

@a4027971
Copy link

a4027971 commented Aug 3, 2017

I meet the same error by using local file.
Finally, the problem can be solved for me by using Chrome Extension Web Server for Chrome

@TingHsi
Copy link

TingHsi commented Feb 6, 2018

worker.js:8475 Uncaught DOMException: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': Error: Uncaught ReferenceError: require is not defined could not be cloned.
at http://10.0.6.49/naptha/tesseract.js/1.0.9/dist/worker.js:8475:16
at Object.respond (http://10.0.6.49/naptha/tesseract.js/1.0.9/dist/worker.js:8707:9)
at Object.dispatchHandlers (http://10.0.6.49/naptha/tesseract.js/1.0.9/dist/worker.js:8729:17)
at http://10.0.6.49/naptha/tesseract.js/1.0.9/dist/worker.js:8474:17
(anonymous) @ worker.js:8475
respond @ worker.js:8707
dispatchHandlers @ worker.js:8729
(anonymous) @ worker.js:8474

My trouble is same to you, @darth-cheney .
Your program is OK now?

@HuubSmit
Copy link

HuubSmit commented Oct 23, 2018

Anyone found a solution? I still get this message, even when I put it on a webserver. Locally I cannot get this to work but with using a webserver (to circumenvent the Cross Origin errors in my app) to load the files gives me the error that Postmessage Object could not be cloned.

@agardnerIT
Copy link

I see the original error using Chrome Version 69.0.3497.100.
I see a DataCloneError: The object can not be cloned. on Safari Version 12.0 (14606.1.36.1.9) on OS Mojave 10.14.

Using a webserver (or extension) is not a solution to this issue since the official Tesseract.js page states: Tesseract.js can run either in a browser and on a server with NodeJS.

@brendanwilding
Copy link

This is so sad that it doesn't work in chrome. It works in FF.

@jeromewu
Copy link
Member

jeromewu commented Jun 1, 2019

Should be working with latest example. Feel free to reopen with more information. 😄

@jeromewu jeromewu closed this as completed Jun 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests