求教~ Chrome Extension 开发框架 Plasmo 的注入 UI 的 bug, tailwindcss 高度不生效 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
请不要在回答技术问题时复制粘贴 AI 生成的内容
shaun0

求教~ Chrome Extension 开发框架 Plasmo 的注入 UI 的 bug, tailwindcss 高度不生效

  •  
  •   shaun0 Sep 28, 2024 2301 views
    This topic created in 578 days ago, the information mentioned may be changed or developed.

    PlasmoCSUI h-full 不生效

    用过 plasmo 的大佬,帮看看问题~

    我在页面中,想向一串 list 的尾部(一排水平的按钮),再注入一个我自己的元素(按钮),想保持和他们一样的按钮高度,但是我发现我自己的元素使用 h-full 不生效,无法充满父节点。有了解这个问题的吗?

    如下图

    import cssText from "data-text:~style.css" import type { PlasmoCSConfig, PlasmoGetInlineAnchorList } from "plasmo" export const getStyle = () => { const style = document.createElement("style") style.textCOntent= cssText.replaceAll(":root", ":host") return style } export const config: PlasmoCSCOnfig= { matches: ["*://*.x.com/*", "*://*.twitter.com/*"] } export const getInlineAnchorList: PlasmoGetInlineAnchorList = async () => { const elements = document.querySelectorAll('[role="tablist"]:last-child') return Array.from(elements).map((el) => ({ element: el, insertPosition: "beforeend" })) } const PlasmoCSUI = () => { return ( <div className="my-auto flex items-center justify-center" style={{ height: 'var(--twitter-tab-height)' }}> <div className="my-auto w-9 h-full flex items-center justify-center ml-1 bg-red-500"> tag </div> </div> ) } export default PlasmoCSUI 
    8 replies    2024-09-29 10:34:24 +08:00
    isa
        1
    isa  
       Sep 28, 2024
    你得确认下 tailwind 的 css 有没有被注入到页面中
    renmu
        2
    renmu  
       Sep 28, 2024 via Android
    你注入不好说会不会修改到原来的功能,手动写写得了
    nagisaushio
        3
    nagisaushio  
       Sep 28, 2024
    去看具体的 CSS 呀,看是不是有什么优先级更高的
    molvqingtai
        4
    molvqingtai  
       Sep 28, 2024
    有没有可能被原网页的 CSS 样式给覆盖了
    molvqingtai
        5
    molvqingtai  
       Sep 28, 2024
    我使用的 wxt ,不过两个框架使用方式都差不多

    需要防止注入的页面继承宿主页面的一些样式,比如文字大小和颜色等,特别是使用 tailwindcss,如果宿主页面的 rem 设置比较小的话,会导致你的页面整体缩小,你需要取消继承,然后呢将 rem 全部转换为 px

    https://github.com/molvqingtai/WebChat/blob/e764f334d14caaafbe17fa326d3187d3105a7304/src/assets/styles/tailwind.css#L81

    https://github.com/molvqingtai/WebChat/blob/master/.postcssrc

    刚新鲜踩的坑,希望对你有帮助
    axina
        6
    axina  
       Sep 29, 2024
    @molvqingtai #5 感谢兄弟,解决了我存在很久不知道怎么解决的一个问题
    codehz
        7
    codehz  
       Sep 29, 2024
    扩展注入的话建议还是别用这样的框架了(
    不过现在不是流行注入一个 shadow dom 进去吗,样式相互隔离
    shaun0
        8
    shaun0  
    OP
       Sep 29, 2024
    感谢各位。解决了,框架是用的影子 dom ,会自动生成两层 div 容器节点,我在网页检查器里找到这两个的节点 id ,然后在 style.css 中手动添加了 height: 100% 就行了。如下:
    ```
    #plasmo-shadow-container {
    height: 100%;
    }

    #plasmo-inline {
    height: 100%;
    }
    ```
    ![]( https://cdn.discordapp.com/attachments/946290204904390690/1289776999052607588/image.png?ex=66fa0def&is=66f8bc6f&hm=bd02c26b95b963cd881de7a7033678d716d7fbde10f453e5dd2c11639609a157&)
    About     Help     Advertise     Blog     API     FAQ     Solana     5466 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 62ms UTC 03:18 PVG 11:18 LAX 20:18 JFK 23:18
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86