# A TOTP authenticator browser extension, per profile

> The companion extension in each Mosaic profile shows its own TOTP codes, read from a QR code or a pasted key. Four faults we found by driving it over CDP.

Source: https://mosaicbrowser.com/blog/authenticator-in-the-profile

## An authenticator inside the profile, and four faults

The companion extension in each Mosaic profile shows its own TOTP codes, read from a QR code or a pasted key. Four faults we found by driving it over CDP.

![4: One authenticator per profile, not one for all](https://mosaicbrowser.com/covers/authenticator-in-the-profile.webp)

A TOTP authenticator in a browser extension keeps two-factor codes next to the account they belong to. In Mosaic that extension is the companion, which runs inside every profile's browser, and since 29 September 2026 it has had an Auth panel. Codes are saved on the profile, read from a QR code or a pasted key, and the setup key can always be read back out. Building it turned up four faults, and every one was found by driving the popup over CDP and reading what it actually did. None of them shows in the source.

![The companion's Auth panel with live two-factor codes for one profile](https://mosaicbrowser.com/shots/companion.png)
*The Auth panel: this profile's codes and nobody else's*

## Why the TOTP authenticator lives in the profile

The usual set-up is one authenticator app on a phone with every account in it. You look at the phone and type six digits by hand, many times a day. For people running several accounts they are entitled to run, it also leaves one shared object holding all of them, which is what the rest of the product works to avoid.

So each profile keeps its own. The [logins and 2FA](https://mosaicbrowser.com/features/logins-and-2fa) vault is per profile, the secret is sealed on disk under the vault's key, and the page never receives it. A code is filled into the page as real keystrokes. If the current code is about to expire, the fill waits for the next one rather than typing a dead code. (What a [TOTP](https://mosaicbrowser.com/glossary/totp) code is, and how the 30-second window works, is in the glossary.)

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: Logins and 2FA codes](https://mosaicbrowser.com/features/logins-and-2fa)

## Getting a key in without a library

`BarcodeDetector` is native in our engine, Tesseract Chrome. We checked that `qr_code` is in `getSupportedFormats()`, with macOS supplying the implementation. So a QR code can arrive by drag and drop, by paste, from a file, or from a capture of the tab you are looking at, and nothing about the image leaves the computer.

A scan fills the form instead of saving. QR codes come off screenshots at the wrong scale, and now and then off the wrong QR code on a busy page, so what is about to be stored is on screen first.

## Fault 1: a startup call ran before its code existed

The popup chose its opening panel from `?tab=`, near the top of the file. `showPanel` reaches into the panel it opens, and the code timer sits next to `const authRows`, several hundred lines further down. The call threw `Cannot access 'authRows' before initialization` at the top level, which stops the rest of the script: no tools panel, no notes wiring, a blank page.

The full-screen button always navigates to `?full=1&tab=<panel>`, so full screen had been dead from every tab, the new one included. The file parses, so nothing reported it. `check:companion` now asserts the panel selection comes after every top-level `const` it could reach. With the fault put back, it failed and named six bindings.

## Fault 2: a key checked only where it was read

The base32 decoder threw on a bad setup key, but only when somebody asked for a code. So `not a key!!` was accepted, encrypted and stored, and rendered as a row reading `--- ---` for ever, under a toast that said "Saved to this profile." The check moved to where the value is written, in the store method the window, the REST API and MCP all go through. The next post in this series tells that one in full.

## Fault 3: a timer that threw away what you opened

The panel rebuilt every row once a second. Revealing a setup key swapped the row's second line for the key, and the next tick, at most a second later, drew a fresh row without it. The secret flashed and vanished.

A tick now updates the digits and the countdown ring in place, and rebuilds a row only when the list's shape changes. Which key is shown is remembered by credential id, so it survives a reload of the list as well.

## Fault 4: icons that rendered as nothing

`icon()` answers an unknown name with an empty fragment, so the `plus` on the Add button and the `trash` on every row's Remove had been drawing nothing. The loop that adds icons read `.seg-btn, .ghost-btn`, which was the complete set of icon-carrying classes when it was written and was not one class later. It reads `[data-icon]` now: the attribute is the request, and a list of classes that happen to make it was a second description of one fact.

## And the generated file, twice more

The companion's `popup.js` is built inside a template literal, so a backtick in a comment ends the string. That cost three parse failures in this one session. The other half is worse because the file still parses: backslashes are consumed too. `\s` becomes `s`, a regex arrives as a different regex, and `'\n\n'` becomes a literal line break inside a string. Everything bound for the generated file doubles its backslashes, and `check:companion` caught all four cases.

The popup talks to Mosaic with a token that reaches only its own profile, which is the subject of [the companion's old API key](https://mosaicbrowser.com/blog/companion-api-key). For running codes across many client accounts, [managing 2FA codes for multiple accounts](https://mosaicbrowser.com/guides/manage-2fa-codes-for-multiple-accounts) has the set-up.

## Questions

### Is it safe to keep TOTP codes in a browser extension?

It moves the second factor onto the same computer as the password, which is a trade you should make knowingly. In Mosaic the secret is sealed on disk under the vault's key and never sent to the page; the extension shows codes for its own profile only.

### Can the Mosaic companion read a QR code from a screenshot?

Yes. It reads a QR code from a dropped or pasted image, a file, or a capture of the tab you are on, using the browser's built-in BarcodeDetector. Nothing about the image leaves the computer.

### Can I see the setup key again after saving it?

Yes. Each code row can reveal its setup key, so you can move the account to another authenticator later. The key stays on screen until you hide it.

### Why keep two-factor codes per profile instead of in one phone app?

Because one authenticator holding many accounts is a shared thing the profiles otherwise avoid, and it means typing codes by hand. Per profile, each account's codes sit with its own logins and are filled with real keystrokes.

## Related

[2FA codes per browser profile, with a login vault each](https://mosaicbrowser.com/features/logins-and-2fa): Mosaic keeps 2FA codes per browser profile: each profile has its own login vault with TOTP codes, shown with a countdown and typed with real keystrokes.

[TOTP: how a six-digit code is made from a secret and the clock](https://mosaicbrowser.com/glossary/totp): TOTP is the time-based one-time password behind authenticator apps: an HMAC of a shared secret and the 30-second step, cut to six digits. RFC 6238.

[How to manage 2FA codes for multiple accounts](https://mosaicbrowser.com/guides/manage-2fa-codes-for-multiple-accounts): Keep each account's 2FA secret next to its login, back the secrets up somewhere you control, and save recovery codes before you need them.

[The companion held a full-power API key](https://mosaicbrowser.com/blog/companion-api-key): Our in-browser extension used a full API key kept in a file. Now each launch gives it a token in memory that reaches its own profile and nothing else.









[Chrome sync quietly joins accounts you meant to keep apart](https://mosaicbrowser.com/blog/chrome-sync-joins-accounts): Chrome sync saves to the one Google account a profile is signed in to, so a second account used in that profile has its history synced under the first.

[Ghostwriting on LinkedIn without logging in as the client](https://mosaicbrowser.com/blog/linkedin-ghostwriter-access): LinkedIn's terms forbid using another member's account, shared logins and copied cookies included. A ghostwriter drafts; the client or a Page role posts.

## Mosaic, on your own computer

The browser this blog is about: its own Chromium, fingerprints from real machines and a proxy IP per profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
