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

133
Vistas
How to load shared code in a Chrome extension content script?

I have a Chrome extension, that has different scripts for several pages:

{
  "name": "My extension",
  "version": "1.0.0",
  "manifest_version": 3,
  "content_scripts": [{
    "matches": ["https://first/page"],
    "run_at": "document_idle",
    "js": ["first.js"]
  }, {
    "matches": ["https://second/page"],
    "run_at": "document_idle",
    "js": ["second.js"]
  }]
}

I want to use some helper functions in both scripts. How do I load a second file, e.g. lib.js so that functions defined in there are available?

I've tried using chrome.runtime.getURL which gets me a URL to the file, but doesn't allow me to "load" it. I also tried just adding the file to the js property, which makes the file load but when trying to call the functions they are undefined. And I've tried several types of import statement, but haven't gotten them to work either.

So, how can I do this without duplicating the common code into both content script files?

about 4 years ago · Juan Pablo Isaza
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