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

When the "corePath" or the "workerPath" cannot be downloaded, there is no way to catch the error #528

Closed
FilipKittnar opened this issue Mar 31, 2021 · 4 comments

Comments

@FilipKittnar
Copy link

I want to use the library offline. I followed the tutorial in documentation, configured corePath and workerPath, which lead to JS files deployed locally and they are pre-cached by PWA. So normally, in production, they work. But when I have the application started locally and I simulate the offline state browser's dev tools, it tries to access the JS files via a localhost URL, which doesn't work because of the offline mode and PWA is off for localhost. That's quite understandable, but the problem is that I cannot figure out a way to catch this error and react to it. It seems to happen somewhere between the createWorker call and the worker.load() in the background - somewhere inside of the tesseract library. So no matter what I wrap with catch or if I call catch on the promise coming from the load, it doesn't catch this problem.
It seems kinda strange to me that I cannot react in any way to such a basic and common error - not being able to download the worker scripts.

@ewrayjohnson
Copy link

ewrayjohnson commented Jul 16, 2022

Why have none of the contributors responded to this?
Based on the lack of response to this and other user's issues, I wonder if this package being actively supported?

@Balearica
Copy link
Collaborator

I looked into why an invalid corePath or workerPath does not throw an exception today. For corePath it's a fairly straightforward bug that I will patch shortly. For workerPath the core issue appears to be that when workerBlobURL = TRUE (the default), the workerPath URL is resolved within the worker, after it has been created but (potentially) before any event listeners have been attached to it. Not sure what the best way to catch that is off the top of my head.

if (Blob && URL && workerBlobURL) {
const blob = new Blob([`importScripts("${workerPath}");`], {
type: 'application/javascript',
});
worker = new Worker(URL.createObjectURL(blob));

@Balearica
Copy link
Collaborator

I worked on this further, and unfortunately I think the issue (specifically with an invalid workerPath) is inherent to createWorker being synchronous and workers loading asynchronously. I implemented a fix that changes createWorker to async in the dev/v4 branch (see #662)--however as this is a breaking change it will need to wait until the next major version to be released.

@Balearica
Copy link
Collaborator

Closing as this should be resolved in Version 4.

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

3 participants