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

253
Vistas
Run Content Script on tabs opened from background script

So I have a small project where I have an extension that when I press its icon it opens some tabs using a background Script with a certain URLs that I will be updating

chrome.browserAction.onClicked.addListener(buttonClicked)
function buttonClicked (tab){
chrome.tabs.create({
    url:"https://google.com/h",
    active : false
  },callback)

}

now I need to to run a content script only on those tabs and I cant figure out how .. I have tried multiple things but cant seem to be able to do so

I am a new programmer so any advice of even guidelines would be appreciated

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

0

First things first, if you want to run content script on certain web-pages only than you can use Match Patterns (https://developer.chrome.com/docs/extensions/mv3/match_patterns/) in manifest.json file to run content script on matching URLs only. If that doesn't solve your problem than follow bellow approach:

When you create new tabs using background script you should append custom query parameters in the url, for example:

background.js

chrome.browserAction.onClicked.addListener(buttonClicked)
function buttonClicked (tab){
chrome.tabs.create({
    url:"https://google.com/h?customAction=1",
    active : false
  },callback)

then in the content script you can identify this query parameter by using window.location.href like this:

content.js

if (window.location.href.indexOf('customAction=1') >= 0) {
   // Call custom function from here
   someFunction();
}
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