Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda