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

161
Visualizações
Why is JavaScript not changing css variable google chrome extension?

I am making a chrome extension, which can be found here. As you can see in it, I need the javascript to change a variable, which changes another variable on the webpage (It sounds redundant but is necessary). In my websiteCss.css file, I have

:root{
  --bg: #00ff00;
}


body.replit-ui-theme-root.light{
  --background-default: var(--bg);
}

And in my JavaScript, I have:

document.addEventListener('DOMContentLoaded', documentEvents  , false);

try{
  document.getElementById('background').value = "#1BFFFF"
}catch (err){
  console.log(err)
}

  
function documentEvents(){
  var r = document.querySelector(':root');
  
  function reload(){
    var color = document.getElementById('background').value
    r.style.setProperty('--bg', color);


    
    document.body.style.backgroundImage = "linear-gradient(to right, #2E3192,  " + color + ")"

    //console.log(getComputedStyle(r).getPropertyValue('--bg'))
    
    if(Math.random(0,1) < .1){
      console.log(color)
    }
    window.requestAnimationFrame(reload)
  }
  
  window.requestAnimationFrame(reload)
}

My website/popup is changing its colors to match the new ones, but the website I am editing isn't. Can someone please tell me why?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It depends on where your Javascript is running. The popup has its own HTML, JS, and CSS; so does the webpage itself.

If you are running this in the context of the popup, it will only affect the popup styles.

If you run this in the content script, you will see the styles change on the webpage.

See https://developer.chrome.com/docs/extensions/mv3/content_scripts/#functionality

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