Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert CSS in Chrome Extension

I know that it's possible to add CSS to a page with Content_Scripts, but I want to use the InsertCSS function in a JS file.

I have:

chrome.tabs.insertCSS(null, {code: "adfree.css"});

But it doesn't change anything of a webpage. I gave the permissions:

"permissions": [
    "tabs", "*://*"
],

Why doesn't it work?

Edit:

chrome.tabs.insertCSS({file: "adfree.css"});

or

chrome.tabs.insertCSS(null, {file: "adfree.css"});

doesn't work also...

like image 323
THWIT Avatar asked Aug 05 '26 18:08

THWIT


1 Answers

You are passing it a file name, but using the code key, when you should be using the file key:

chrome.tabs.insertCSS(null, {file: "adfree.css"});

See the documentation for more info.

like image 94
Joseph Silber Avatar answered Aug 07 '26 09:08

Joseph Silber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!