Inspiration

Most of us have paid for a free trial we forgot about, or found a $4.99 add-on on a receipt that was ticked by default. The information is usually on the page, in small grey text under the button. In its final click-to-cancel rule (Oct 2024) the FTC wrote that it gets tens of thousands of complaints a year about these subscription practices, and that rule was vacated in July 2025. So reading the fine print is still on the person paying.

An AI model could read it for you, but a checkout page is the worst page to paste into a chatbot. It has your name, email, address and card on it. That is why this is a hybrid app: the private page is meant to be read on your device, and only public text goes to the cloud.

What it does

Before You Pay is a Chrome side panel. On a checkout or signup page you press Check this page and get:

  • The first-year cost, added up. On the demo store, "$0.00 due today" becomes "$355.39 in your first year, plus tax". Every line is a verified quote from the page, the billing period is read from the words next to each price, and the math is plain code. Pattern matching alone gets to $277.63; the model finds an add-on whose price sits outside its checkbox and a $2.49 charge that never says "fee".
  • A cancel-by date. The trial end date and first bill come from the checkout page. The notice period and refund rule come from the store's public terms page, read by Gemini in the cloud. The two are joined in the browser: "Cancel by Fri, Dec 4, or pay $31.44, and the terms say no refunds." Add to calendar builds an .ics file locally.
  • What left this device. Every read is listed with its mode, size and a fingerprint. Cloud rows show the exact text that was sent, with [email] and [card ending] marked in red where they were removed.
  • Cards for what is due today, when a trial turns into a charge, add-ons that were already ticked, extra fees, auto renewal and the cancel link, plus a one line summary on top.

Every card quotes the page word for word. Code checks each quote and amount against the page before it is shown, and anything that fails is marked "Not confirmed" instead of shown as fact. Dates and totals are worked out in code, never by the model. Click a card and the words light up on the page.

How I built it

Everything goes through Firebase AI Logic, and the mode is chosen per request based on how private the text is:

Text Mode Why
Checkout page (name, email, card) ONLY_ON_DEVICE, Gemini Nano through the Chrome Prompt API, JSON schema via responseConstraint It should not leave the laptop
Public terms page ONLY_IN_CLOUD, Gemini Flash Lite with a JSON schema Long legal text, nothing private
Checkout page when there is no Nano ONLY_IN_CLOUD, only after the user says yes, on a copy with emails, card numbers, phones and addresses removed Fallback with consent

I do not use PREFER_ON_DEVICE, because on a machine without Nano it would quietly send the checkout page to the cloud, which is the one thing this app must not do. Cards are labeled ON DEVICE or IN CLOUD from the inferenceSource AI Logic returns.

Gemini Nano has a small context, so the app measures each prompt with measureInputUsage against inputQuota, splits long pages at sentence ends (keeping the start and end of the page, where fine print lives), shows download progress, and has a Stop button.

Other Firebase pieces:

  • App Check with reCAPTCHA Enterprise and limited-use tokens on every cloud AI call
  • Anonymous Auth + Firestore for saved offers, with owner-only, create-only rules that check every field (emulator tests in the repo)
  • Remote Config for the cloud model, an on-device kill switch, page size, reminder timing and spacing between cloud calls
  • Hosting for the panel, a fake demo store and a public eval page

Extension pages cannot load reCAPTCHA, so the side panel hosts the web app in an iframe with allow="language-model" (which passes the Prompt API into the frame), and both sides check each other's exact origin.

Does it work

  • 10 real public plan pages (streaming, news, software, storage; logged out, nothing typed): the cloud read got 5 of 6 free trials right, pattern matching alone got 1 of 6. Amount precision and recall 0.93 / 0.93. Labels were drafted with an AI assistant and committed before any run.
  • 22 made-up test pages, 6 of them held out with labels committed before any model saw them. Held-out cloud read: precision 1.00, recall 0.93, and the code caught two intro prices the model called free trials.
  • Every mistake is listed in the README, for example reading "$0 for 3 months" as a $0 charge.
  • Anyone can rerun the test pages at /eval.html.

Real Gemini Nano run. My own machine cannot run Gemini Nano, so on Nov 24 I used a free Kaggle notebook machine (4 CPU cores, 31 GB RAM, no GPU) with Chrome 158 stable and the Prompt API on. A script opened the live panel, pressed "Try the demo store" and "Check this page", and recorded the screen. Nano downloaded, reported "available", and read the checkout page on the machine with 0 requests to Gemini during the read. Over six runs a read took 60 to 144 seconds. The first run only added up $277.63, because Nano left amounts empty and called ticked add-ons plain charges. Later runs each found a new way to get an amount wrong: an add-on quoted together with its price, "unknown" as an amount, and the $2.49 per-bill line listed twice. I fixed each one in code that only uses the page, never a guess, and gave Nano three extra lines about amounts. After the first fix, 7 of 10 reads added up the same $355.39 as the cloud read, including both reads on the final code. The saved raw Nano answers from runs 2 to 6 are a unit test now, and all of them add up to $355.39 with the current code. The answers, logs and the screen recording are in the repo under eval/nano-real.

What is not tested: Nano accuracy over many pages and Nano speed on a GPU laptop. The real runs are one page on one CPU machine, Nano is not consistent from read to read, and one to two minutes is too slow for a real checkout. The eval numbers above are cloud only.

Challenges I ran into

  • App Check needs reCAPTCHA, which extension pages cannot load. An iframe with pinned origins on both sides solved it.
  • Models read intro prices as free trials, and "No automatic renewal." as a renewal. A quote check cannot catch that because the sentence is real, so the code now checks what the words around it say.
  • The free plan has a low cloud rate limit. Cloud answers are cached per text hash, calls are spaced out, and the demo store ships labeled saved answers from real cloud reads. If a fresh read fails on the demo store, the saved answer stays and the panel says why.
  • Running Gemini Nano without a machine that supports it. I tested the routing with a stand-in model first, then ran the real model in headed Chrome on a Kaggle CPU machine. Each real run showed a new way Nano got an amount wrong, which I fixed in code and ran again, six runs in all.

Accomplishments that I'm proud of

  • The cancel-by date only exists because of the hybrid split: private facts from one page, public rules from another, joined on the device.
  • The receipt makes the privacy claim checkable instead of asking people to trust it.
  • Nothing the model says is shown as fact until code has found it on the page.

What I learned

Hybrid is not only about falling back when the device is weak. Choosing the mode per request, based on how private the text is, made the product safer and easier to explain.

What's next

  • Measure Nano on a GPU laptop and over the whole test set, next to the cloud numbers
  • Use Nano's image input to spot ticked boxes drawn as images
  • Sync saved offers and reminders to a phone
  • More languages for the basic check

Built With

  • chrome
  • chrome-prompt-api
  • cloud-firestore
  • firebase-ai-logic
  • firebase-app-check
  • firebase-authentication
  • firebase-hosting
  • firebase-remote-config
  • gemini
  • gemini-nano
  • puppeteer
  • recaptcha-enterprise
  • typescript
  • vite
  • vitest
Share this project:

Updates

Submission history