tesseract.js icon indicating copy to clipboard operation
tesseract.js copied to clipboard

Reopen the question: will tesseract.js support chrome extension build with MV3

Open ForeverAT opened this issue 2 years ago • 3 comments

The problem now of using tesseract.js in chrome extension with manifestV3 is the unsafe-eval issue. As MV3 separate the CSP for extension page and sandboxed page, the extension page is no longer allow to use unsafe-eval in script-src. May I ask is there any example or method to implement tesseract.js in chrome extension with manifestV3?

ForeverAT avatar Feb 16 '22 04:02 ForeverAT

Any updates on this issue? Looks like chrome are allowing us to set worker-src in the csp for extension_pages. According to this bug here Chrome allowing worker-src link however when using this with tesseract.js in the extension, csp throws an error relating to loading blob url's in the worker. This bug can be seen here Blob: url bug with mv3 and tesseract

@jeromewu @ForeverAT

clarodanesh avatar Apr 25 '22 15:04 clarodanesh

currently no, I have changed to other OCR for my project in this moment. @clarodanesh

ForeverAT avatar Apr 25 '22 18:04 ForeverAT

Hello! any update on this issue . any idea how to make this work using manifest version 3 ?

sanjeev07 avatar May 16 '22 05:05 sanjeev07

I'm the only active maintainer at the moment, and have no experience with developing Chrome extensions. Therefore, I think this would take somebody else developing a fix, or at the very least, providing a detailed description of what part of tesseract.js is problematic and how it would need to be changed.

Balearica avatar Aug 11 '22 03:08 Balearica

Actually I find a method ( and tried) these days, you may inject the file into the website you are browsing and build worker in the website. Most websites are fine but like GitHub, it does not allowed us to create worker (which does not required by other OCR technology). Hope this help you guys. @sanjeev07 @clarodanesh

ForeverAT avatar Aug 11 '22 08:08 ForeverAT

Hey @Balearica,

At @ForeverAT is correct. That is the way i'm able to get it to work.

The more detailed issue is that the Manifest v3 switches the backend script to the serverworker standard and you no longer have access to the document api.

Let me know if I can do anything, as it would be amazing to have the tesseract in the serverworker.

RobertJGabriel avatar Dec 07 '22 01:12 RobertJGabriel

@ForeverAT I was able to add it to Chrome Extension (running in an extension popup page), explained here: https://stackoverflow.com/a/76604454/653457. No idea why there is no documentation/mention of this anywhere though.

datvm avatar Jul 03 '23 11:07 datvm

@datvm thank you, at least I'm getting a new error now:

Refused to compile or instantiate WebAssembly module because neither 'wasm-eval' nor 'unsafe-eval' is an allowed source of script in the following Content Security Policy directive: "script-src 'self'"). Build with -s ASSERTIONS=1 for more info.

felri avatar Jan 29 '24 22:01 felri

@felri You need to add a CSP declaration for wasm.

datvm avatar Jan 30 '24 05:01 datvm