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.
manifest.json:
- Invoke the
content_script.js
frombackground.js
. You can whatever kind of listener for this.
background.js:
- Use the
content_script.js
to do changes to the DOM. You can add style classes to DOM nodes which is applied from thecontent_style.css
or add new elements like the ones you want. Write all your new CSS rules incontent_style.css
.
If you have better answer, please add a comment about this, thank you!