Inspiration
Everyone has lost an episode to a thumbnail. Keyword blockers make you type every name, then hide half your feed anyway, and they still miss "THAT ending 😳" or a gravestone in a thumbnail. Spoilers are about meaning and about where you are in a story. That is a constant, private judgement: the kind of job a small model sitting next to your feed is built for.
What it does
You tell it where you are: "Hollow Tide, watched up to season 1 episode 4", or "Marrow Bay FC vs Harbor City, watching later".
- On YouTube, Reddit and X every item is blurred first and revealed once it is judged safe.
- Plain rules clear everything unrelated instantly, with no AI. Posts about your show go to the model in batches.
- A spoiler stays behind a card that says where the spoiler is ("Talks about events after S1·E4"), never what happens, with Show and Not a spoiler.
- Thumbnails get their own check.
- On a page about your show (a hashtag, a fan forum), posts that never name the show are judged too.
- Knows what you're watching: open an episode and it asks whether to move your spoiler line there. One tap, never automatic.
- Safe to read now: posts it hid are kept in your browser. When you move your line they are checked again, and the ones that are safe now are listed, so you can read the reactions you skipped.
- Air night: when a new episode came out in the last three days, it offers once to hide everything that names the show for 48 hours, with no AI. Watching the episode ends it.
- Match mode hides scores, goals and red cards until you mark the match watched.
- Where was I? writes a recap of the episodes you have already seen.
- A live panel on the page shows what was checked, where, how long it took and how many bytes of your feed left the computer.
How I built it
Hybrid is the architecture, not a toggle. I split the work by how often it happens and how private it is.
Frequent and private → InferenceMode.PREFER_ON_DEVICE. Judging posts (batches of 12, JSON verdicts via responseConstraint), thumbnails (image input) and "What am I watching?" run on Chrome's built-in model (Gemma 4 with a flag, otherwise Gemini Nano), with Gemini in the cloud as fallback.
Escalation by confidence. On the device nothing is shown on one answer. After the batch verdict, ONLY_ON_DEVICE second looks (strict, reasoned, and grounded in the synopsis sentences closest to the post) must agree. If they don't, or the on-device call fails or times out, the post is unsure: ONLY_IN_CLOUD decides that single post if the viewer allowed it; otherwise it stays hidden. Firebase AI Logic already picks device or cloud by what the browser has; I added one more reason: doubt.
Rare, needs knowledge or long context → InferenceMode.ONLY_IN_CLOUD. The spoiler profile (names to watch for and concrete facts after your episode) is built once per show from Wikipedia episode summaries split at your progress. Recaps are written from watched episodes only. Match profiles list teams, players and the kinds of facts that spoil a result.
response.inferenceSourcedrives the per-card "Checked on this device / in the cloud" label, the live panel and the counters.initializeDeviceModel()starts the model download from a click.- Firebase App Check with reCAPTCHA Enterprise protects AI Logic. reCAPTCHA needs a web origin, so the extension's offscreen document embeds the engine page from Firebase Hosting in an iframe with
allow="language-model", the offscreen + iframe pattern Firebase documents for Auth in Chrome extensions. - Consent gate: without an on-device model, feed content goes to the cloud only after "Allow cloud checks". With one, only unsure posts go, after a separate "Allow for unsure posts". I check this myself because the SDK sends every mode to the cloud when the browser has no
LanguageModelAPI at all. - Chrome MV3 content scripts with per-site selectors, blur-first CSS, a fail-closed queue (a failed check keeps the item hidden and is asked again) and hedged cloud calls across two models.
Does it work?
I tested it on a real drama the code had never seen: 113 real video titles, labelled by hand and committed before the first run (viewer at S2·E3, ambiguous titles left out). The labels are mine.
| Safe titles wrongly hidden (of 81) | |
|---|---|
| Keyword blocker | 78 |
| Gemma 4 on device only | 41 |
| Gemma 4 + Gemini as referee | 2–5 |
With the referee it caught 30–31 of 32 spoilers (keyword blocker: 30), and 60 of the 113 titles never left the computer (two runs). With the cloud as the only judge it caught 29–30 of 32 and hid 0–2 safe titles (three runs). On the made-up Hollow Tide set it caught 8–9 of 9 over six runs and hid 0–1 of 15 safe items.
Challenges I ran into
- Keeping recall high without over-hiding: fans write a first name or a community handle, not the full character name. I added fan-style names to the profile and let long names match inside words.
- Getting App Check to work from an extension (hosted engine in an offscreen iframe).
- A small on-device model is unsteady: the same question gave very different answers on repeat runs, and once it ran for five minutes. I added length and time limits, two-sided checks and a cloud referee, and measured the difference.
- Free-tier rate limits (15 requests/min) and transient 503s: batching, viewport-first queues, hedged calls, retries and, on the demo feed only, recorded verdicts (labelled as such) when the cloud is down.
- Reddit's shadow DOM, where a child overlay never renders.
Accomplishments that I'm proud of
A full loop that runs on real YouTube pages (a shield at S2·E4 of a real show keeps E4 clips and trailers visible and hides endings, later episodes and finale scenes), a reproducible eval page with a keyword-blocker baseline, and a live panel that shows on screen where each check ran and how many bytes left the computer.
What I learned
Hybrid works best when each side does the job it is good at: the cloud for knowledge and generation, done rarely; the device for the constant, private stream, with the cloud as referee only when the device is unsure.
What's next
Better on-device accuracy without the referee (on its own it still over-hides), more sites, community-shared show profiles, and Android once Firebase AI Logic hybrid inference there leaves preview.
Built With
- chrome
- chrome-prompt-api
- esbuild
- firebase-ai-logic
- firebase-app-check
- firebase-hosting
- gemini-api
- gemini-nano
- gemma
- manifest-v3
- recaptcha-enterprise
- typescript
- wikipedia-api