Menu

Why your browser extension UI looks broken on half the web (and how a small Shadow DOM wrapper fixes it)
📰

Why your browser extension UI looks broken on half the web (and how a small Shadow DOM wrapper fixes it)

DEV Community: css·Emir Mrkaljević·3 days ago
#uz9Q2prg
#devtocss#devto#dev#id#host
Reading 0:00
15s threshold

When you inject a small badge or overlay into a third-party website from a browser extension content script, it works fine on your test page. Then you open a real shop and your badge is giant, transparent, stuck in the bottom-left corner, or missing its close button.

I hit this on Monoprix while testing ShrinkWatch EU , an open-source extension that shows unit prices (per kg, per litre or per piece) and shrinkflation warnings on European supermarket web shops.

What the host page does to your DOM

Supermarket frontends are ten years of CSS resets, utility classes and aggressive global selectors piled on top of each other:

div { position: relative } or div { box-sizing: content-box }

button { all: unset } or button { width: 100%; background: green !important }

span { display: block; color: inherit }

Global font-size: 62.5% on html , which shrinks every rem -sized rule in your stylesheet

Even if you prefix every class name with sw- , bare element rules ( div , span , button ) and inherited properties (…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.