naptha / tesseract.js

Pure Javascript OCR for more than 100 Languages 📖🎉🖥
http://tesseract.projectnaptha.com/
Apache License 2.0
34.89k stars 2.21k forks source link

Browser extension Manifest version 3 is experiencing issues with Tesseract.js #961

Open dhineshkoilpitchai opened 6 days ago

dhineshkoilpitchai commented 6 days ago

Tesseract.js version (5.1.1)

Describe the bug In Manifest V3, all of the extension's logic must be part of the extension package. while configuring tesseract.js in my project which is expecting remotely hosted files from cdn (https://cdn.jsdelivr.net/npm/tesseract.js@v5.1.1/dist/worker.min.js)

The call to cdn javascript files is being blocked by Manifest V3

Below is the generated error

aaa463d1-3808-4913-b68b-301dd763c085:1 Refused to load the script 'https://cdn.jsdelivr.net/npm/tesseract.js@v5.1.1/dist/worker.min.js' because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost: http://127.0.0.1:". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

Balearica commented 6 days ago

You can include all files locally rather than using a CDN. This is documented here. Additionally, multiple other users have made browser extensions using Tesseract.js (including one prominently featured in the readme), so you can check what they did to handle this.

dhineshkoilpitchai commented 4 days ago

Thank you for replying, Balearica.

Tesseract.js is performing well with Manifest version 2 for scripts that are requested from both local and CDN.

While migrating the project from Manifest version 2 to Manifest version 3, the "Content Security Policy" does not allow for internal and external script calling. Even though the script is also included in the project.

Below is the generated error after configured Tesseract.js locally

Refused to load the script 'chrome-extension://cfdfhbbeijbeiekpobjehilaniekfaoo/libs/tesseract/worker.min.js' because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost: http://127.0.0.1:". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

Uncaught Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'chrome-extension://cfdfhbbeijbeiekpobjehilaniekfaoo/libs/tesseract/worker.min.js' failed to load.

ab3cd1d9-032a-4451-8885-83c0c1a70c6d:1 Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'chrome-extension://cfdfhbbeijbeiekpobjehilaniekfaoo/libs/tesseract/worker.min.js' failed to load. at ab3cd1d9-032a-4451-8885-83c0c1a70c6d:1:1