• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Execute Content Script and associated CSS from Background (Manifest V3) – Chrome Extension

Resolved: Execute Content Script and associated CSS from Background (Manifest V3) – Chrome Extension

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

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 ๐Ÿ™‚
  1. Change the manifest file to something like this.

manifest.json:
  1. Invoke the content_script.js from background.js. You can whatever kind of listener for this.

background.js:
  1. Use the content_script.js to do changes to the DOM. You can add style classes to DOM nodes which is applied from the content_style.css or add new elements like the ones you want. Write all your new CSS rules in content_style.css.

If you have better answer, please add a comment about this, thank you!

chrome-extension-manifest-v3 css google-chrome-extension javascript scripting
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: VBA – Applying border around the areas with value/text

01/04/2023

Resolved: How can I implement a function depending on picked up items?

01/04/2023

Resolved: Azuer Service Bus SDK not receiving the specified messages

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.