Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
Importing tesseract.js in chrome extensions

Im developing this chrome extensions and I want to use the tesseract.js library to recognize text in an image. Only im clueless on how to import the library. I am using manifest V3 so importing using the CDN link is not possible (as far as I read in the documentation). So I installed the library locally using npm --save, and then webpacked it with npx webpack, but I still cant get any off the functions imported.

I tried the options given by the tesseract.js documentation, which are:

import Tesseract from 'tesseract.js';

Tesseract.recognize(
  'https://tesseract.projectnaptha.com/img/eng_bw.png',
  'eng',
  { logger: m => console.log(m) }
).then(({ data: { text } }) => {
  console.log(text);
})

and

import { createWorker } from 'tesseract.js';

const worker = createWorker({
  logger: m => console.log(m)
});

(async () => {
  await worker.load();
  await worker.loadLanguage('eng');
  await worker.initialize('eng');
  const { data: { text } } = await worker.recognize('https://tesseract.projectnaptha.com/img/eng_bw.png');
  console.log(text);
  await worker.terminate();
})();

But neither work, because tesseract.js is not a valid file according to the service worker. As said above, I also tried importing it using the CDN link, but because of the CSP regulations, chrome can't import non-local libraries in Manifest V3 using links. in this image you can see the file structure. I copied some of the tesseract files from the node_modules folder into the services folder for easier access.

Can anyone explain to me how I am supposed to import tesseract.js on a chrome extension. Apparently its not as easy as just using import Tesseract from 'tesseract.js';

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I don't know if this is what @wOxxOm meant with his reply,

Service worker can't create nested workers, crbug.com/1219164. You'll have to do it in a visible html page.

but when I run the tesseract.min.js AS an content script, either by mentioning it in the manifest, or using chrome.scripting.executeScript(), Tesseract becomes a global variable for all content scripts on that page, and thus I can actually use it in my script. Either way thank you for your help

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda