Dev.to WebDev 🛠 Dev 👁 2 📖 7 min read

Building a screen-blur extension that doesn't fall apart on React apps

A few weeks ago I shipped BlurDock — live on the Microsoft Edge Add-ons store — a Chrome/Edge extension that blurs sensitive regions of the screen live — before and during a screen share, recording, or screenshot. The pi

A few weeks ago I shipped BlurDock — live on the Microsoft Edge Add-ons store — a Chrome/Edge extension that blurs sensitive regions of the screen live — before and during a screen share, recording, or screenshot. The pitch sounds trivial: draw a box, blur what's under it. It is not trivial, and almost every version I tried before landing on the current approach broke in one specific, humiliating way: the blur worked perfectly on a static page, and then silently disappeared the moment the underlying app re-rendered.

This is the post-mortem on why that happened, what actually fixed it, and the two smaller but equally annoying bugs I hit building the PII-detection engine that ships alongside it.

Constraint #1: no <all_urls>, no backend

Before getting into the bugs, the permission model mattered for how I could even approach this. BlurDock only requests activeTab + scripting + storage. No <all_urls> host permission, no persistent background access to every tab, no network calls at all — the extension has no backend. That's a hard design constraint I set for myself up front: a tool for hiding sensitive information can't itself become a thing with broad standing access to everything you look at.

activeTab means the extension only gets injected into a page when the user explicitly invokes it on that tab. That's good for trust, but it also means no long-lived content script watching a page from load. The blur logic has to attach on demand and survive whatever the page does afterward, with no "come back later" option — if it loses track of its own state, the user has to notice and redraw.

The real problem: blur regions are coordinates, pages are not static

The naive implementation is: user drags a box, you record {top, left, width, height}, you position a <canvas> or a blurred <div> overlay at those coordinates with position: absolute.

This works until the host page does anything React/Vue/Next.js apps do constantly: re-render a subtree. A re-render doesn't necessarily move what a user would call "the layout" — a dashboard polling for new data, a chat UI appending a message, a table re-sorting — but it can detach and replace the DOM nodes your absolutely-positioned overlay was anchored near, or shift everything below a toast notification by a few dozen pixels. The blur region, pixel-correct a second ago, is now either floating over nothing or sitting a few hundred pixels off from the sensitive content it was supposed to cover.

The failure mode is bad specifically because it's silent: no error, no visual glitch while setting it up — the blur quietly stops matching reality while you keep believing it's there, exactly the moment someone screen-sharing a support queue would have a customer's card number slide into view.

What didn't work

My first fix attempt was anchoring the blur region to the specific DOM node it was drawn over, by holding a reference to that element and re-measuring its getBoundingClientRect() on a requestAnimationFrame loop. This works right up until the framework doesn't patch that node in place but replaces it outright — which is common for list items, table rows, and anything keyed by data that changes. The reference goes stale, getBoundingClientRect() either throws or returns a detached rect, and you're back to a floating blur box, just with an extra failure mode on top.

What actually worked: watch, don't assume

The fix was to stop tying the blur region to a specific node's identity, and instead treat "the page might have changed" as the default assumption after every paint. I attach a MutationObserver to the document root watching childList, subtree, and attributes, and on any batch of mutations I re-run a lightweight re-anchor pass: re-resolve the relative position the blur region was drawn at (not a node reference, but a position expressed relative to a stable ancestor landmark captured at draw time — page scroll container, nearest section/article/main, whichever is closest and still present), and re-apply the overlay's coordinates from that.

Debouncing mattered more than I expected. A naive "re-run on every mutation" handler turns into a visible stutter on any page with frequent small updates — a live chat panel or a polling dashboard fires mutations constantly. I batch mutations with a short requestAnimationFrame-aligned debounce — react to the next paint, not to every individual mutation record — which keeps the re-lock invisible instead of janky. I also added a cheap bail-out: if the computed new position is identical to the last one (within a pixel), skip the DOM write, since MutationObserver firing doesn't mean the relevant geometry actually moved.

The honest caveat: this is a heuristic, not a guarantee. A page that aggressively restructures its entire DOM tree on every render (rare, but it exists) can still outpace the re-anchor logic for a frame or two. I'd rather document that plainly than claim the extension handles 100% of possible SPA behavior, which it doesn't.

The PII/secret redactor: regex is doing a lot of quiet, careful work

The Pro tier adds a local, client-side scanner that flags emails, Stripe/GitHub/AWS/OpenAI keys, JWTs, credit card numbers, phone numbers, IPv4s, and currency amounts in on-screen text, plus a standalone free web version at blurdock.kintolabs.com/tools/pii-redactor/ for pasted logs and JSON, no extension required. None of it calls out to any model or API — it's an ordered set of regexes with an overlap-exclusion pass (an earlier, higher-priority match "claims" its character span so a JWT segment doesn't later get mis-flagged as three separate tokens) and one piece of real validation logic: Luhn checksums on anything that looks like a card number.

The Luhn check exists because a bare "13-to-19 digit run" regex flags an enormous number of false positives — order numbers, tracking IDs, timestamps concatenated together. Luhn's checksum (alternating doubling from the rightmost digit, subtracting 9 from any result over 9, summing, checking divisibility by 10) is what real card issuers use to catch typos, and repurposing it as a filter cuts false-positive card detection dramatically for almost no code. It's not perfect — it'll still validate some non-card digit runs that pass the checksum by coincidence — but it's a meaningfully better signal than digit-count alone, and I'd rather ship an honest "Luhn-checked, not infallible" scanner than oversell what a handful of regexes can guarantee.

The more embarrassing bug was in the card regex itself. My first version was:

/\b(?:\d[ -]?){13,19}\b/g

which reads as "13 to 19 digits, each optionally followed by a space or dash." It looks right, and it passed every test I'd written — until I ran the live tool in a browser against a real sentence: "card ending in trouble: 4000 0000 0000 0002 was charged $67.00 twice." The redacted output came back as [REDACTED:CARD]was charged, missing the space before "was". The regex engine's \b boundary is satisfiable at more than one candidate position near the end of that match, and the greedy quantifier preferred consuming the trailing space as part of the final (?:\d[ -]?) repetition, because a word boundary still existed right after it. The match wasn't wrong about which digits were a card number — it was wrong about where the match actually ended, swallowing a character of surrounding text that had nothing to do with the card at all.

The fix was to stop letting a separator be the last thing a repeated group can consume:

/\b\d(?:[ -]?\d){12,18}\b/g

Structurally, this can only start and end on a literal digit — separators only ever occur between two digits in the match, never trailing one. None of my original unit tests caught this, because none of them checked the character immediately after a match for correctness; they only checked that the right value got redacted. It took opening the actual page and reading real output text to notice a missing space. That's the lesson I keep re-learning: unit tests check a function's output against what you decided to assert, but UI bugs frequently live in the gap between "the function returned the right value" and "the right value ended up in the right place on the page" — the second thing only a real render will show you.

Deterministic fake data instead of just masking

Masking ([REDACTED:EMAIL], [REDACTED:CARD]) is fine for a one-off screenshot, but it's visibly fake-looking in a live demo — nobody wants their dashboard covered in bracketed tags while presenting to a prospect. The Pro tier adds a "Demo Data Swap" mode that substitutes realistic-looking fake values instead of masking tags: a detected email becomes something like [email protected], a card number becomes a known test-card pattern, and so on.

The requirement that mattered here was determinism within a session: the same original value, appearing twice on screen, has to map to the same fake value both times — otherwise "[email protected]" showing up in both a support ticket and a billing row would get two different fake emails, which looks more broken than no redaction at all. I keep a per-run map from original matched value to assigned fake value, seeded lazily the first time each distinct value is seen, pulling from a small fixed pool per data type — a memoization table, not cryptographic hashing, since the goal is visual consistency, not unguessability.

Where this leaves things

Free tier: manual blur regions, no watermark, works indefinitely. Pro ($15 one-time, not a subscription, three devices): the local PII/secret auto-scanner and Demo Data Swap mode. Get it on Microsoft Edge Add-ons (Chrome-compatible build), or try the redactor as a standalone free page with no extension required, if you just want to clean a log before pasting it somewhere: blurdock.kintolabs.com/tools/pii-redactor/.

If you've solved SPA-persistence for an overlay extension more elegantly than "watch everything and re-anchor on debounce," I'd genuinely like to hear it — that part still feels more like a reasonably good heuristic than a solved problem.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.