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

297
Views
Chrome Extension to change Style Elements, insertCSS not working. is there a better option?

I have some simple element styles I'd like to change with a Chrome Extension.

I just want to change the width value from 10em to 20em, for example. I would also like to be able to undo the change and or be able to enter the value from the popup.

#mw-panel {
    position: absolute;
    top: 0;
    width: 10em;
    left: 0;
}

I removed the styles.css from the manifest.json file and I also added the css file to the manifest.json file in the hopes of being able to enable/disable the CSS with the popup buttons.

   "web_accessible_resources": [
    {
    "resources": ["styles.css"],
    "matches": ["https://en.wikipedia.org/*"]
    }
    ]

I have a working extension with popup HTML and js files. I tried using insertCSS in the content.js but read that it will not work from there but should from a popup or background js file. I was hoping to also use the removeCSS function.

I also read that with some of the ways you can load a CSS file, the !important modifier will not work. So this may all be for not.

I currently can't get passed this error after clicking the popup button: Error handling response: TypeError: Cannot read properties of undefined (reading 'insertCSS')

    $('.format').click(function() {
    chrome.tabs.query({currentWindow: true, active: true}, function (tabs){
    var activeTab = tabs[0];
            chrome.scripting.insertCSS({
                target: { tabId: activeTab.id },
                file: ["styles.css"]
            });
    /*chrome.tabs.sendMessage(activeTab.id, {"buttonclicked": "wider"});*/
   });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Looks like you need to set file to files

chrome.scripting.insertCSS({
   target: { tabId: activeTab.id },
   files: ["styles.css"]
});
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!