且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Chrome扩展程序插入CSS

更新时间:2023-12-05 20:09:34

注入代码很简单

chrome.tabs.insertCSS(tabId, {
 file : "mystyle.css"
});

确保清单中列出了mystyle.css

Make sure that mystyle.css is whiletlisted in the manifest

 "web_accessible_resources": [
    "mystyle.css"
  ],

使用Chrome Devtools检查注入是否成功.我有一个问题,我以为没有注入我的CSS.经调查,确实如此,但我的选择器不正确.我最终在许多样式中都添加了!important.

Use Chrome Devtools to check if the injection succeeded. I had a problem where I thought my CSS wasn't being injected. On investigating, it was, but my selectors were incorrect. I ended up adding !important to many of the styles.