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
Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': #851
Comments
Please complete the first part of the issue template asking what version of Tesseract.js you are using. Additionally, please post the error message (if any) that occurs when you leave The I have personally used Cypress with the latest version of Tesseract.js for another project, so am disinclined to believe that Tesseract.js is incompatible with Cypress. |
I am using latest version teseracct.js v5.0.3, below is the error while I am using default configuration. (uncaught exception)Error: Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://cdn.jsdelivr.net/npm/tesseract.js@v5.0.3/dist/worker.min.js' failed to load. |
I do not know why If the issue persists and you want me to look further, I would need to be provided a reproducible example repo that I can clone and run. As noted above, I am able to use Cypress with the latest version of Tesseract.js on my system and it works as expected. |
Also, you should delete the |
thanks for responding, after I change setting workerBlobURL: false, the address changed to an invalid address below. |
Browsers are categorically disallowed from accessing files on your local file system--any path starting with Instead, if you want to always access the |
have tried according to above suggestions, I am not able to make script working in Cypress environment, so we can get the conclusion that Tesseract.js is incompatible with Cypress, right? if so, do you have plan to make tesseract.js officially support Cypress testing, which I think it will do great help to visualization testing. thanks! |
especially, if there are canvas components, to verify message in canvas, tesseract.js should make a big difference. |
As I stated above, Tesseract.js can be used with Cypress. I personally use Cypress with a project that uses the latest version of Tesseract.js. It sounds like there is something wrong with your testing environment, your Cypress configuration, or the specific version of Cypress you are using is bugged. The error you report above is that If you create a repo with a minimal reproducible with Cypress + Tesseract.js, then I can clone and look into this further. However, without something I can clone and run, there is nothing further I can do to help with this. |
I zipped my project, and the issue could be reproduced, hope this can help to figure out the problem. |
seems like the zipped file has problem, I have upload my cypress code to following github location, could you pls have a look? thanks! |
find info for the error: Refused to load the script 'http://localhost:63292/node_modules/tesseract.js/dist/worker.min.js' because it violates the following Content Security Policy directive: "script-src 'unsafe-eval'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback. so how to avoid this restriction? |
I looked at your repo, and it does not look like you have a website for Cypress to test. Rather, it looks like you're trying to run recognition within the Cypress should be used to test a website. The JavaScript code that contains the Cypress tests should only contain the testing code. It should not attempt to run application code (in this case, recognition). Separate from the testing code, you should have a website that recognizes an image using Tesseract.js. The examples in this repo can be used for a basic example. Then, you can write a Cypress script that interacts with the website to run recognition. |
I actually run this to test a web and encounter problems, in order to make it simple, so I create this repo. This error happens while in tesseract initial state. So I think not test web is not the reason. anyway, I will update this repo to test web later. |
Closing this issue as I believe Tesseract.js does work with Cypress and any issues are due to a particular project configuration. We can reopen if a reproducible example repo of Cypress failing to work with the basic example code is provided. |
Tesseract.js version (version number for npm/GitHub release, or specific commit for repo)
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
import { createWorker } from "tesseract.js";
const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
const OPTIONS = {
cachePath: './tests/assets/traineddata',
corePath: '../node_modules/tesseract.js-core',
...(IS_BROWSER ? { workerPath: '../../../node_modules/tesseract.js/dist/worker.min.js' } : {}),
};
let worker;
async function performOCR(imagePath) {
const image = path.resolve(__dirname, imagePath || './ocr_demo.png');
console.log(
Recognizing ${image}
);worker = await createWorker('eng',1, OPTIONS);
await worker.reinitialize('eng');
// Perform OCR
const { data: { text } } = await worker.recognize(image);
console.log(text);
// Terminate the worker
await worker.terminate();
return text;
}
module.exports = {
performOCR,
};
2. create method in command.js
const { performOCR } = require('../../cypress/e2e/demo/ocrUtils');
Cypress.Commands.add('performOCR', (imagePath) => {
return performOCR(imagePath);
});
cy.performOCR( './in_img.jpg').then((ocrText) => {
// Use the OCR text in your Cypress test
cy.log(
OCR Text: ${ocrText}
);});
});
Please attach any input image required to replicate this behavior.
performOCR./in_img.jpg
(uncaught exception)Error: Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://localhost:57232/node_modules/tesseract.js/dist/worker.min.js' failed to load.
Error
Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://localhost:57232/node_modules/tesseract.js/dist/worker.min.js' failed to load.
Expected behavior
String on image could be recognized.
Device Version:
Additional context
No matter set the workerPath to local or a CDN path, it's failed with above error. Once upon a time, tesseract.js could work with Cypress automation framework normally, now it's not working.
The text was updated successfully, but these errors were encountered: