Building a WhatsApp Web extension with no server: a Manifest V3 bridge, a deleted-message vault and what broke
MadarWA is a WhatsApp Web toolkit with three goals: blur chats when someone is looking over your shoulder, keep a local copy of messages that are deleted after you received them, and never send any of that to a server you do not control.
The third goal shaped everything. This post covers how MadarWA works: a Manifest V3 Chrome extension that runs entirely inside the browser, and the engineering problems that "no server" creates.
The constraint: no backend, no remote code
MadarWA has no relay server, no telemetry and no remote code. Settings, the message vault and the logs live in chrome.storage.local. Media lives in IndexedDB. The extension CSP is script-src 'self'; object-src 'self'; base-uri 'none', and every script is bundled at build time.
That sounds like a slogan until you try to do something useful with it. WhatsApp Web does not give extensions an API. So the first decision was how to reach WhatsApp's internals at all.
Reaching the internals without scraping the DOM
Scraping WhatsApp's DOM breaks every time the class names change. Instead MadarWA bundles @wppconnect/wa-js (pinned to 4.7.2) locally and uses the WPP interfaces it exposes. That code has to run in the page's own JavaScript context, which Manifest V3 allows with world: "MAIN".
So the extension is split in two worlds:
| Layer | Runs in | Job |
|---|---|---|
preload.js, wppconnect-wa.js, injected.js | MAIN world (page JS) | Turn analytics off, wait for WPP.loader.onReady, listen to new messages, revokes and presence changes |
content.js | ISOLATED world | React UI inside a Shadow DOM, settings, vault, campaigns |
background.js | Service worker | Webhook delivery, badge, notifications, daily maintenance |
The Shadow DOM matters more than it looks. WhatsApp's styles are aggressive and change often, and an isolated style boundary keeps the panel from being broken by them, and keeps the panel from breaking WhatsApp.
The bridge between the two worlds
The MAIN world is page code, so anything in it can be reached by other scripts on the page. The two halves talk through CustomEvents, and I wanted that channel to reject tampering and replays:
- the isolated side creates an ephemeral 32-byte session key and a random session id
- every envelope carries a namespace, the session id, a monotonic sequence number, the payload and a keyed checksum
- the MAIN side rejects wrong sessions, altered payloads and any sequence number it has already seen
I should be precise about what this is. It is transport hardening, not secrecy. Code running in the MAIN world can always observe its own traffic, and the README says so. What the bridge buys is that a stray script cannot forge commands or replay old ones.
The anti-delete vault
When someone deletes a message "for everyone", WhatsApp tells your client to remove it. By then the text is usually gone. The vault has to act earlier.
MadarWA keeps a bounded cache of message text and metadata as messages arrive. For media, it downloads the decrypted file with WPP.chat.downloadMedia right away (up to 25 MB) and stores the blob in IndexedDB with an LRU limit of 150 items. When a chat.msg_revoke event arrives, it looks up the original by id and stanza id, writes a vault entry, and replaces the deleted bubble with an interactive element in the chat: text with copy and timestamps, photo with a lightbox, playable video and voice notes, and downloadable documents.
Two details took longer than the feature itself:
Revokes arrive in more than one shape. Sometimes WhatsApp sends a revoke event. Sometimes it inserts a new row of type revoked through a normal add. The vault listens to add, change:type and chat.msg_revoke, and resolves the original key through a chain of fallbacks. There are tests for the chained resolution and for group message ids that have four parts.
WhatsApp redraws constantly. An earlier version restored deleted messages, but when you switched to another chat and came back, the restored elements were gone and stayed gone. In a chat with 9 deleted messages, nothing was covered even after 12 seconds. After the fix, all nine were covered in under a third of a second: two restored copies and seven short notes saying why no copy exists. That last part matters. If MadarWA never received the message, or the deletion is older than when saving started, the bubble says so instead of leaving you wondering. A deletion 134 days old correctly showed "older than when saving started".
And deletions that WhatsApp reports again after a page reload used to fire a second alert and a second webhook. They no longer do.
Privacy mode, one element at a time
Blurring the whole page is easy and useless. MadarWA tags exact elements (names, phone numbers, previews, avatars, message text, the composer box, media) and reveals only the one under the pointer, after 160 ms. The tagger and the CSS rules have their own tests.
There is also a part that is not cosmetic. Hiding typing and recording state, blocking read receipts and private status viewing go through the real WPP.privacy calls. Turning off read receipts changes your actual WhatsApp account setting across devices, and the UI warns you before doing it. Suppressing "audio played" receipts is best effort through wrapped calls and may not work on every WhatsApp build. I would rather write that in the README than discover it in a bug report.
Smaller things that were worth getting right
- PIN lock: PBKDF2-SHA256, 120,000 iterations, a random 16-byte salt, constant-time comparison. It is a UI convenience, not disk encryption. Anyone with DevTools access can bypass it, and the docs say that too.
- Webhooks: delivered from the service worker with an SSRF guard that rejects private and reserved IPv4 and IPv6 ranges,
localhost,.local,.internal, URLs with credentials and single-label hostnames. Redirects are disabled, the timeout is 20 s and the body is capped at 512 KB. Transient failures (network, 429, 5xx) retry with a stable delivery id so the receiver can deduplicate. DNS rebinding is still a residual risk that an extension cannot fully solve, and the README lists it. - CSV and Excel export: UTF-8 with BOM so Arabic opens correctly in Excel, plus protection against formula injection.
- Bilingual UI: Arabic (RTL) and English (LTR), switchable instantly, with a test that the two translation files have matching keys.
Testing
The project has 175 Vitest tests in 23 files, covering the bridge (tampering, replay, timeouts, rejecting foreign origins), SSRF rules, spintax, phone number normalization, the queue, the PIN, receipts, the media vault and the in-chat restore. The current gate is typecheck, tests, build and a build verification step, and all four pass.
What it does not do well
- It depends on WhatsApp's internal modules through a pinned wa-js. A future WhatsApp build may break it until the pin is upgraded.
- It has not had an external security audit. It is verified structurally and functionally, which is not the same thing.
- Campaigns live in memory and do not survive a page reload. Attachments are capped at 4 MB by the bridge.
- The vault keeps up to 1,000 deleted messages and the message cache up to 3,000.
- Bulk sending can get a WhatsApp account restricted. The campaign module exists, with delays, batches and pause on disconnect, but you should treat it carefully.
- The vault stores local copies of message text. Use it only where you have the consent and the legal right to.
Try it
It is not on the Chrome Web Store, so you build it yourself (Chrome 111+, Node 22.12+):
git clone https://github.com/ALSRKAL/MadarWA.git cd MadarWA npm install npm run build npm run verify Then open chrome://extensions, enable Developer mode, choose Load unpacked, and select dist/.
Source and docs, in Arabic and English: github.com/ALSRKAL/MadarWA (MIT).
I wrote about my other tools too: the Bash network script that lied to me and the Android wireless debugging tool. If you work on MV3 extensions and have opinions on the bridge design, I would like to hear them.