
AI in the Browser: A Practical Guide to Chrome’s Built‑in AI, Prompt API Experiments, and Local Inference
A deep dive into running AI directly inside the browser, including Chrome’s built-in AI experiments, browser-managed models, and practical client-side patterns for private summarization, classification, rewriting, and semantic search.
Adding AI to a web app used to mean calling a cloud API or shipping a model and managing its runtime. Browser-managed models provide another option. Chrome’s built-in APIs and app-managed WebGPU/WASM inference can support local features where data locality matters, provided the user’s browser and hardware can run them. This is a capability to detect, not a default to assume for every visitor.
This post is a technical deep dive into what’s happening, how to reason about the architecture, and how to build real features (summarization, classification, rewriting, semantic search) without sending user data to your servers.
Why AI in the browser is suddenly practical
The browser is a surprisingly good runtime for certain AI workloads because it sits at the intersection of:
- Data locality: user content is already there (DOM, form inputs, local files, IndexedDB).
- Privacy constraints: many apps want to avoid shipping user text to a server for compliance, cost, or trust reasons.
- Latency: local execution removes a network round trip, but model download, loading, and generation can still take seconds.
- Distribution: the browser is the universal app platform—no installers, no GPU driver headaches, no per-OS packaging.
Historically, the blockers were straightforward: models were too big, inference was too slow, and the web platform didn’t expose enough acceleration.
Now we have:
- WebGPU for GPU-accelerated compute in the browser.
- Better WASM performance and SIMD support for CPU paths.
- Rapidly improving model quantization (int8, int4) that makes “good enough” models small and fast.
- And importantly, early-stage browser-managed AI: the browser itself can provide an API that abstracts model provisioning, permissions, and execution.
This last piece is where Chrome’s built-in AI work is pointing.
Browser-managed models vs. “you ship the model”
Before discussing Chrome’s Prompt API experiments, it’s helpful to separate two approaches:
1) You ship the model (app-managed inference)
You bundle or download a model and run it via:
- WebGPU (e.g., transformer inference kernels)
- WASM (CPU fallback)
- A library like
onnxruntime-web,transformers.js, or custom kernels
Pros
- Works in more environments (not tied to one browser’s experimental APIs).
- Full control over model choice, prompting, tokenization, and upgrade cadence.
- Can be made offline-first if you cache artifacts.
Cons
- Shipping weights is hard: bandwidth, caching, integrity, and versioning.
- Hardware variability is brutal (slow CPUs, limited memory, flaky mobile GPUs).
- You own safety/abuse mitigations if your app exposes generation to users.
2) Browser-managed models (browser-provided AI)
Here, the browser exposes an API like “summarize this” or “generate text,” and the browser decides:
- which model to use,
- how to store it,
- how to execute it efficiently,
- what permissions and policies apply.
Pros
- Drastically simpler integration for common tasks.
- Better chance of consistent performance across devices.
- Potentially stronger privacy posture by default (data stays local under browser governance).
- Easier model updates (browser updates, not app redeploys).
Cons
- Less control: capabilities and quality are bound to what the browser offers.
- Feature availability is gated by browser version, flags, origin trials, and platform constraints.
- The API surface may evolve (experiments change).
Chrome’s built-in AI efforts sit squarely in (2), with an “API-first” approach rather than requiring every developer to become an inference engineer.
For the underlying distinction between architectures, model roles, and application patterns, see the AI model-family guide. Here, the additional decision is who supplies and operates the runtime.
Chrome’s built-in AI: what it is (and what it isn’t)
Chrome provides APIs at different release stages, rather than one uniformly experimental feature. Its current status table lists the Prompt API for web pages from Chrome 148 and extensions from Chrome 138; sampling options on the web have a separate origin trial. Summarizer, Translator, and LanguageDetector have their own capability checks. Check the specific API rather than inferring support from the Chrome version alone. Chrome’s API status table
Hardware requirements checked October 13, 2026: the foundation-model APIs support eligible desktop systems, not Android or iOS. Chrome currently requires 22 GB free profile-volume space and either more than 4 GB GPU VRAM or a CPU with at least four cores and 16 GB RAM. Windows 10/11, macOS 13+, Linux, and eligible Chromebook Plus devices are listed. Those free-space requirements are not the model’s download size. An initial model download needs an unmetered connection; availability can later change. Chrome’s setup requirements
The most talked-about piece is the Prompt API experiments: a way to request language-model-style generation from the browser environment.
A key thing to internalize: this is not “a JavaScript library from Google.” It’s a browser API surface, which implies:
- capability detection,
- permissions and policy hooks,
- standardization potential (eventually),
- and strong constraints around user protection.
The practical implication is that “AI features” may become like SpeechRecognition or WebAuthn: you don’t ship the model, you code against the API, and the browser handles the rest.
The Prompt API mental model
At a high level, a prompt API usually implies:
- You provide instructions and input (prompt content).
- You can request output as streaming tokens or a full response.
- Generation controls depend on the API and context. Do not assume a cloud-style
max_tokensparameter. Chrome’s default web Prompt API does not exposetemperatureortopK; extension parameters and the web sampling-mode trial differ. - You must handle capability checks and fallbacks.
Even if the exact names and shapes change, the integration pattern is stable:
- Check availability (is the API present? is the model available?).
- Request a session / context (optionally with system instructions).
- Send prompts and consume output (ideally streaming).
- Handle cancellation (user navigates away, closes modal, changes input).
- Fail gracefully (fallback to non-AI UX, or remote service if policy allows).
A concrete Prompt API wrapper (TypeScript)
A small adapter keeps the application independent of its inference backend. The current global is LanguageModel, not ai.prompt.createSession. Use @types/dom-chromium-ai where your TypeScript DOM library does not yet include it. Run creation from an explicit user interaction if a download is needed, expose download progress in the UI, and offer a non-AI fallback when unavailable. This example uses an already downloaded English-text model so it does not silently trigger a large download. Prompt API reference
export interface TextGenerator {
generate(input: string, opts?: { signal?: AbortSignal }): Promise<string>;
destroy(): void;
}
export async function createBrowserGenerator(): Promise<TextGenerator> {
if (typeof LanguageModel === 'undefined') {
throw new Error('Use the non-AI editor on this browser.');
}
const options = {
expectedInputs: [{ type: 'text' as const, languages: ['en'] }],
expectedOutputs: [{ type: 'text' as const, languages: ['en'] }],
};
const availability = await LanguageModel.availability(options);
if (availability !== 'available') {
throw new Error(`Model is ${availability}; show setup or fallback UI.`);
}
const session = await LanguageModel.create(options);
return {
generate: (input, opts) => session.prompt(input, { signal: opts?.signal }),
destroy: () => session.destroy(),
};
}
Call destroy() when the component or feature closes. For streaming, session.promptStreaming() returns a ReadableStream of text chunks; consume it with a reader or supported async iteration, pass an abort signal, and render text safely. Sessions retain earlier interactions, so use a fresh session or a controlled clone for independent documents; otherwise unrelated text can leak into later answers. Chrome’s session-management guidance
Privacy-preserving use cases that benefit immediately
When AI stays on-device (or at least in-browser), entire categories of features become easier to justify:
Private summarization (notes, tickets, docs, emails)
For selected notes or tickets, local inference can avoid sending prompt content to a model server. Your analytics, crash reporting, output saving, and fallback code must preserve that boundary too; using a local API alone is not a compliance determination. Chrome documents a dedicated Summarizer API for this task.
Design tip: offer “summarize this selection” to keep scope clear and computation bounded. Shorter input can omit needed context, so evaluate factual accuracy rather than assuming fewer hallucinations.
Example prompt structure for reliable summaries:
Summarize the text for a busy professional.
Constraints:
- 5 bullets max
- Include dates, numbers, and action items
- If unsure, write "Unclear" rather than guessing
Text:
<<<
{user_text}
>>>
Local classification (tags, routing, moderation)
Classification tends to be short-output and high-value. You can run:
- intent detection (support category),
- topic tagging,
- “is this a question or a statement?”,
- priority detection.
If you can keep classification local, you avoid sending raw content to servers. In many apps, classification is also easier to validate: you can show the predicted label and let the user correct it.
A robust pattern is to ask for structured output:
Classify the text into exactly one category:
- Billing
- Bug
- Feature Request
- Account Access
Return JSON: {"category":"..."}
Text:
<<<
{ticket_text}
>>>
Then parse and validate the allowed category, with a fallback if validation fails. A model’s self-reported confidence is not a calibrated probability. Do not use an on-device classifier as the sole authorization, moderation, or safety decision: client results are alterable by the user.
Rewriting (tone, clarity, translation-lite)
Rewriting is perfect for on-device because it’s personal: users are editing their own drafts, and they often don’t want that content leaving their machine.
Typical flows:
- “Make this more concise”
- “Rewrite for a friendly tone”
- “Fix grammar, preserve meaning”
- “Convert to bullet points”
A practical safeguard is to require “diff-friendly” output: ask the model not to introduce new facts, and keep the structure close.
Semantic search and “AI find” with embeddings
Semantic search is where local AI becomes a product differentiator. Instead of “search exact words,” you get “search meanings,” and you can do it across:
- saved notes,
- offline docs,
- browser history within an app,
- local knowledge bases.
You don’t need a generative model for this; you need an embedding model (text → vector). Then:
- store vectors in IndexedDB,
- compute cosine similarity at query time,
- retrieve top-k snippets,
- optionally run a local summarizer over the retrieved snippets.
This is an app-managed embedding pipeline, not an embedding endpoint supplied by Chrome’s Prompt API. Index size, vector dimensions, and device memory determine whether retrieval remains fast. Keep the model identifier and chunking version with stored vectors so incompatible embeddings are rebuilt.
Architectural patterns for in-browser AI
Pattern A: “Prompt-only” (generation for everything)
This is simplest: one API for summarization, classification, rewriting.
When it works
- Your tasks are mostly short.
- You can accept variable latency.
- You don’t need deterministic outputs.
Downsides
- Classification via generation is less stable than a dedicated classifier.
- Costs are “time costs” (latency) rather than dollars.
Pattern B: Hybrid: embeddings + lightweight generation
This is the sweet spot for many apps:
- embeddings for indexing and retrieval,
- generation only for final answers (RAG-like UX), or not at all.
Benefits
- Faster and more predictable.
- Better grounding: retrieval reduces hallucinations.
- Often smaller models.
Pattern C: Task-specific small models (when you ship inference)
If you manage models yourself, you can choose:
- a tiny summarizer,
- a sentiment classifier,
- a domain-specific tagger.
This can outperform generic prompting on speed and determinism.
Implementing semantic search locally (a practical sketch)
Below is a realistic architecture that works today, even without built-in browser AI:
- Split documents into chunks (e.g., 300–800 tokens or ~1–3 paragraphs).
- For each chunk:
- compute embedding vector,
- store
{docId, chunkId, text, embedding}in IndexedDB.
- On query:
- embed the query,
- compute similarity against stored vectors,
- return top-k chunks.
Chunking and storage strategy
Chunking is not glamorous, but it’s half the quality. Aim for:
- chunks that stand alone (include headings),
- stable boundaries (don’t re-chunk on every small edit),
- metadata: title, lastUpdated, tags.
IndexedDB schema idea:
chunksstore: key{docId}:{chunkId}textembedding: Float32Array(store as ArrayBuffer)meta: { title, url, updatedAt }
Similarity search in the browser
If your dataset is small (a few thousand chunks), brute-force cosine similarity is fine. If it’s larger, consider approximate nearest neighbor libraries compiled to WASM, but keep it simple until you need it.
function cosineSim(a: Float32Array, b: Float32Array): number {
if (a.length === 0 || a.length !== b.length) {
throw new Error('Embeddings must have matching, nonzero dimensions.');
}
let dot = 0, na = 0, nb = 0;
for (let i = 0; i < a.length; i++) {
dot += a[i] * b[i];
na += a[i] * a[i];
nb += b[i] * b[i];
}
return dot / (Math.sqrt(na) * Math.sqrt(nb) + 1e-8);
}
Then select top-k with a small heap or partial sort.
Retrieval-augmented summarization (entirely local)
Once you have top-k chunks, you can summarize only what matters:
Using only the context below, answer the user’s question.
If the answer is not in the context, say you don’t know.
Question: {query}
Context:
- {chunk1}
- {chunk2}
- {chunk3}
This keeps computation bounded and can improve relevance. It can also miss evidence or retrieve the wrong chunks. Show the retrieved sources and test questions with known answers; prompting the model to admit uncertainty does not enforce that behavior.
Performance engineering: make progress and cancellation visible
Use streaming output whenever possible
For generation tasks, streaming is not just a nice-to-have. It masks latency and makes the UI feel alive.
UI pattern:
- show first token ASAP,
- allow cancel,
- keep the text editable after completion.
Cache model assets and intermediate results
For app-managed models, cache weights and intermediates deliberately. Chrome controls its built-in model cache; an application cannot assume it will remain available forever. In both approaches:
- cache embeddings per chunk (don’t recompute on every page load),
- cache results for repeat queries,
- cache compiled WASM modules and GPU pipelines when feasible.
Use Web Workers where the runtime supports them
App-managed embedding, chunking, and similarity search are good worker candidates. Do not assume a browser-managed API is exposed in workers just because its methods are asynchronous. Keep its calls in the supported context and move your own heavy computation off the main thread.
- Use a Dedicated Worker for your AI engine.
- Communicate via
postMessage, transferring ArrayBuffers to avoid copies. - Consider a “job queue” with cancellation.
Be honest about device constraints
In-browser AI is device-dependent. Design adaptive behavior:
- if low memory, reduce chunk size, reduce top-k
- if slow device, disable “live” features and offer “run now” buttons
- use timeouts and fallbacks
A practical rule: if the feature takes more than ~300–700ms, show progress and let users cancel.
Security and privacy: local doesn’t mean risk-free
Keeping data off your servers helps, but the browser environment still has risks:
- Prompt injection: if you feed untrusted text into prompts (web pages, emails), it can manipulate outputs. Treat the model as an untrusted component and constrain instructions.
- Data exfiltration via output: even locally, sensitive data can be surfaced in UI in unintended contexts (e.g., summarizing a hidden field). Be explicit about what text is included.
- Cross-origin constraints: never let arbitrary pages access your app’s local AI index. Enforce origin isolation and store data per origin.
- Permissions and user expectations: if a feature analyzes local files, make the UI clear about what is processed and when.
A good safety pattern is “explicit scope”:
- summarize selected text, not the whole page,
- embed only documents the user imported,
- show which sources were used for an answer.
Product design: where client-side AI actually wins
Client-side AI isn’t primarily about replacing cloud LLMs. It’s about unlocking features that are hard to justify otherwise:
- Offline mode: field work, travel, restricted networks.
- Sensitive drafts: local processing can reduce disclosure, subject to your application’s storage, access, telemetry, and retention requirements.
- Cost control: eliminate per-token cloud spend for common actions.
- Latency-sensitive UX: short-input classification or rewriting, after measuring whether the supported device can meet the interaction budget.
A realistic product roadmap often looks like:
- Start with classification + rewriting (small inputs, big UX win).
- Add semantic search with embeddings (sticky feature).
- Layer summarization and “explain this” on top of retrieval.
- Keep a server-side fallback only where needed (e.g., high-quality long-form generation), gated by user choice.
A pragmatic adoption checklist
If you’re evaluating Chrome’s built-in AI experiments and local inference, these are the questions that decide whether you’ll succeed:
- Capability detection: What do you do when the API isn’t available?
- Quality targets: Is “good enough” acceptable, or do you need top-tier model output?
- Latency budget: What’s the max time before the UX breaks?
- Data scope: What exact text is processed, and how do users control it?
- Storage limits: How large can your local index get before you need pruning?
- Observability: Can you measure latency and failures without collecting user text?
- Upgrade strategy: How do you handle model/API changes over time?
Answer those up front and the implementation becomes an engineering exercise instead of an open-ended experiment.
Closing thoughts: treating the browser as an AI runtime
The web platform has been inching toward native capabilities for decades: media, crypto, ML, GPU. Built-in AI makes models a browser-managed resource. The opportunity is to build features with explicit local-processing boundaries—summaries on a selection, classification in a compose window, and semantic search over an offline corpus. Measure responsiveness on supported devices instead of promising instant results.
The teams that win here will be the ones who treat in-browser AI like any other performance-sensitive web feature: tight UX loops, careful caching, worker-based execution, explicit user scope, and graceful fallbacks.
