Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!