Question:I am coding a chrome extension, and I basically want that when it’s active, a little circle displays on the screen. I NEED CSS for that, so what I’m trying to do is have the background in my manifest, and basically just execute the content script if the icon is clicked. Currently I know the setting is on if the tab url is changed, but I’m testing something out. I need to add the CSS to my content script, but not sure how to. I looked it up, and I saw insertCSS() was a thing, but that is only for a single line of code, I have much more than that. Any ideas please? I’ve reviewed the main google doc for it, and MDN as well. Any help would be appreciated.
Answer:It’s pretty simple 🙂
- Change the manifest file to something like this.
- Invoke the
background.js. You can whatever kind of listener for this.
- Use the
content_script.jsto do changes to the DOM. You can add style classes to DOM nodes which is applied from the
content_style.cssor add new elements like the ones you want. Write all your new CSS rules in
If you have better answer, please add a comment about this, thank you!