Getting Around CORS

I am tinkering with Tesseract.js OCR library which can be used to convert text in an image into text that can be edited. There are two ways to use this library, it can be used by referencing the source code in the script tag or it can be installed using npm. I chose to reference the source code.

After referencing the library, I specified the image on my local machine that want to use for testing purposes in my script. When I run the script I’m getting the following error:

loadImage.js:43 Fetch API cannot load file:///C:/Users/UserZero/Desktop/Website%20Editor/Experimental%20Scripts/Tesseract/test.png. URL scheme must be "http" or "https" for CORS request.

I enabled the Allow-Controll-Allow-Origin Chrome extension but that didn’t do anything. How do I resolve this issue if I don’t want to use any framework or use a webserver? Please see my script here

Web browsers are not allowed to access any old file path on your computer. Serious security problems used to occur when that was allowed.

If you want to test your script on your local computer, that tends to require setting up a local sever.
I like to use live-server myself, which after it’s set up is as simple as running live-server from the command prompt.

I’ll be intersted in other peoples opinions here about the matter.

Hi Paul, thanks for your help. I was hoping to convert an existing web page into an android app and this web app is supposed to be able to access images on the smart phone or on any device that is using this app. Are you saying that this cannot be done due to CORS?

That is beyond my skillset, but we do have a Mobile forum that might have suitable answers for you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.