Demo video: https://youtu.be/9MjVhaGmOus

Inspiration

Our team makes Lucido, a mobile app for scanning and translating documents, built around one rule: photos and documents stay on the phone. In the browser the same people hit the same wall every day. A lease clause in German, a hospital portal in English, a tax notice, a scanned letter posted as an image. The quick fix is to paste it into a chatbot, which sends private content to a server without a second thought.

Chrome now ships Gemini Nano, and Firebase AI Logic can route one request to either Nano or cloud Gemini. We wanted to see if that could make "private by default, cloud by consent" a real product behavior instead of a settings page promise.

What it does

  • Right-click selected text, or an image, and choose Translate and explain. Or press Alt+Shift+L and drag over any part of a page: a chart, a scanned form, text inside a picture.
  • The side panel returns a translation, a 2 to 4 sentence plain-language explanation, and up to five key terms with meanings, in one of 11 languages.
  • Every answer is labeled with where it ran: Processed on this device (Gemini Nano) or Processed in the cloud (Gemini through Firebase AI Logic), plus the model and the time taken.
  • Three privacy modes:
    • On-device only: nothing leaves the device, ever. If Nano is missing it offers the download instead of falling back.
    • Ask before using the cloud (default): when a request needs the cloud, a consent card says why (for example "On-device AI is not available for this language") and exactly what will be sent ("The selected text (55 characters) will be sent to Gemini through Firebase AI Logic"). Use once, always allow, or cancel.
    • Use the cloud when needed: Firebase AI Logic's PREFER_ON_DEVICE decides.
  • An on-device chain for languages Nano cannot output yet. In our tests Chrome's Nano reports English as available and Korean as unavailable. Instead of sending Korean users to the cloud, Lucido Lens asks Nano in English and converts the answer with Chrome's on-device Translator API. The answer is still private, and it is labeled Gemini Nano + Chrome Translator.
  • The same product on iPhone and Mac. A SwiftUI app runs Apple's on-device Foundation Models first and Gemini second through the Firebase AI Logic Apple SDK. Paste text, choose a photo or drop an image; on the Mac, select text in any app and use Services > Translate and explain with Lucido Lens. Images are read on the device with Apple's Vision framework and never leave it; if a request needs the cloud, only the recognized text is sent, with consent. Manga pages work too: vertical columns are put back into speech bubbles in reading order, Apple's Translation framework translates each bubble on device, and Apple's model explains it.
  • The consent card names the exact reason the device could not answer: Apple Intelligence is off, the model is downloading, the language is not supported, the text is longer than the model's context (11,993 of 8,192 tokens), or Apple's on-device safety rules declined it.
  • English and Korean UI on both platforms.

How we built it

  • Chrome extension, Manifest V3, TypeScript, Vite and esbuild. A service worker handles the context menu, the keyboard shortcut and area capture (captureVisibleTab, cropped and downscaled locally with OffscreenCanvas). The side panel holds the UI and all AI calls. Permissions are contextMenus, sidePanel, storage, activeTab, scripting; no host permissions and no content script on every page.
  • Firebase AI Logic hybrid inference. We do not hand every request to PREFER_ON_DEVICE. A small pure function, decideRoute, combines the privacy mode, the Prompt API's LanguageModel.availability() for this exact request (target language, text or image) and the user's saved consent. Its result picks the InferenceMode: ONLY_ON_DEVICE, ONLY_IN_CLOUD or PREFER_ON_DEVICE. The same JSON schema is passed to both sides (responseConstraint on device, responseSchema in the cloud), so one parser serves both. response.inferenceSource drives the label.
  • Firebase App Check is initialized before any AI call. MV3 extension pages cannot load the reCAPTCHA script, so the extension uses a CustomProvider with a registered debug token for development and judging; the web build of the same panel can use ReCaptchaV3Provider.
  • Firebase Remote Config holds the cloud model name and input limits, with in-app defaults.
  • iPhone and Mac app: SwiftUI, one multiplatform target. decideRoute is ported to Swift with the same cases and tests. Its inputs are Apple's checks for the exact request: SystemLanguageModel.availability, supportedLanguages, and tokenCount(for:) against contextSize. The route picks the Firebase AI Logic provider for generativeModelSession: .systemModel, .geminiModel, or .hybridModel(primary:secondary:). One @Generable Swift struct is the schema on both sides (guided generation on device, responseSchema in the cloud), and rawResponse.modelVersion drives the source label. App Check uses the debug provider with a registered token; Remote Config shares the extension's keys.
  • Tests: Vitest for the router (including "on-device only never reaches the cloud" for every device state), parsing and crop math. Playwright runs the panel headless with a fake Prompt API and Translator, counts requests to the Gemini endpoint (zero on every on-device path), and makes real text and image calls through Firebase AI Logic with App Check.

Measured on a MacBook Pro with Chrome 158 (real Gemini Nano, headless Chrome driven over CDP): English text on device in about 3.5 to 15 s, Korean through the Nano plus Translator chain in 3.5 s, a captured sign image on device in 6.6 s, cloud answers in 2 to 8 s.

The app, measured on the same Mac (macOS 27.2) and the iOS Simulator: a German lease clause to Korean on device in 4.7 to 6.1 s, in the cloud in 2.2 to 2.8 s; sign photos in Japanese, German, Korean and Chinese read on device in 0.2 to 0.4 s each. The app's self-test (-selftest) runs these checks against the real models and prints JSON.

Challenges we ran into

  • A silent cloud fallback in on-device-only mode. Reading the SDK source, we found that the Chrome adapter is only created when window.LanguageModel exists. In a browser without the Prompt API, a model created with ONLY_ON_DEVICE has no adapter and the request goes to the cloud. We added a guard that refuses on-device requests when the API is missing, plus a test that counts network requests.
  • Language support. Nano's availability depends on the declared input and output languages. Korean output is "unavailable" while English is "downloadable" or "available". This pushed us to build the Nano plus Translator chain rather than treat every non-English user as a cloud user.
  • App Check in an extension. reCAPTCHA cannot load in MV3 extension pages. We used a CustomProvider with the debug token flow for this build and documented the gap.
  • Testing on-device AI without a window. Playwright's bundled Chromium only has an echo stub for the Prompt API. We kept fast tests on a fake LanguageModel, and added scripts that start real Google Chrome in headless mode with its own profile, load the extension over a CDP pipe, and run real Gemini Nano requests, including area capture with simulated mouse drags.
  • Nano copying instead of translating. Asked for a JSON object with several fields, Nano sometimes copies the original text into the translation field for Japanese. The app detects this and asks Nano again with a translation-only prompt, still on device.

  • Apple's on-device model left the Korean translation empty. With a field named translation, the model kept returning an empty string or looped until it hit the 8,192-token limit. Renaming the fields (translatedText, explanation), lowering the temperature and capping the output fixed it on device.

  • Apple's safety rules on everyday documents. The default guardrails refused a medical note and a billing notice. The permissive content-transformation guardrails, meant for translating and summarizing user text, fixed those; an insurance denial is still declined, so the app treats "declined" as its own reason and shows it on the consent card instead of a generic error.

  • Reading text in images fast enough. Vision's automatic language detection took 25 s on a Japanese sign, and a Latin recognizer on Chinese text took over a minute and returned garbage. Running Korean and Japanese passes in parallel and choosing by the script found (then Chinese or Latin only when needed) brought it to about 0.3 s, and joining wrapped lines keeps sentences whole for the model.

  • Manga. On a manga page the app read vertical columns left to right and mixed bubbles, so sentences came out reversed, and the ~3B model left names in kanji, turned 逃げろ ("run!") into "stop!" and sometimes explained in Japanese for a Korean reader. We now rebuild bubbles from the column boxes, translate with Apple's Translation framework and keep Apple's model for the explanation, translating it too when it comes back in the wrong language. Vision's language correction also stalled for 30 to 130 s on a few pages, so it now gets 2.5 s before the uncorrected text is used. On a full page Vision also missed short bubbles and read some as horizontal scraps, so the app now finds panels from the gutters and reads each bubble again, cropped and enlarged at three sizes: on 23 test pages the share of characters right went from 91.4 % to 94.1 %.

Accomplishments that we're proud of

  • The privacy promise is enforced in code and tested, not only written in a settings page.
  • Consent tells the user the reason and the size of what would be sent, before anything is sent.
  • Korean and other languages Nano cannot output yet still get a fully on-device answer.
  • One privacy router, two platforms, two on-device models, the same tests.
  • No server, no stored content, no host permissions.

What we learned

  • Hybrid inference is most useful when the app, not only the SDK, owns the routing decision, because the right choice depends on the user's privacy preference, not only on model availability.
  • LanguageModel.availability() must be called with the real request shape (languages, image input); a generic check gives the wrong answer.
  • Chrome's built-in AI APIs compose well: Prompt API plus Translator API covers languages the language model alone does not.

What's next

  • An Android version with Gemini Nano through Firebase AI Logic, sharing the same router logic, inside our Lucido app.
  • Camera capture on iPhone (live text from the camera, on device).
  • A reCAPTCHA bridge page so release builds of the extension get App Check attestation without a debug token.
  • Follow-up questions about the same text ("What should I do next?") in a short on-device chat.
  • PDF viewer support.

Built during the submission period

The repository was created on 2026-11-20 during the submission period and all code was written then. The idea and the "documents stay on the device" rule come from our existing mobile app Lucido; no Lucido code is used. Third-party code: Firebase JS SDK and Firebase Apple SDK (Apache-2.0).

Built With

  • apple-foundation-models
  • apple-vision
  • chrome
  • chrome-built-in-ai
  • esbuild
  • firebase
  • firebase-ai-logic
  • firebase-app-check
  • firebase-remote-config
  • gemini
  • gemini-nano
  • manifest-v3
  • playwright
  • prompt-api
  • swift
  • swift-testing
  • swiftui
  • translator-api
  • typescript
  • vite
  • vitest
  • xcodegen
Share this project:

Updates

Submission history