AI Within Your Browser: Exploring Google Chrome’s New Prompt API

Muthukumaran Navaneethakrishnan
3 min readJun 24, 2024

--

Imagine being able to use a powerful AI directly in your browser, similar to WebGPU but without the hassle — Chrome handles everything for you. You don’t need to rely on external services, set up servers, or download large files.This isn’t about downloading a 600 MB model just to get started; it’s a groundbreaking approach that redefines what you can do directly in your browser.

Google Chrome’s new experimental feature, the Prompt API for Gemini Nano, offers an exciting glimpse into the future of in-browser AI tools. It excels at quick and straightforward tasks like summarizing text, rephrasing sentences, or classifying information — perfect for adding insights on-the-fly to anything you’re reading online. However, it’s important to note that this tool isn’t built for more complex tasks, such as converting code from one programming language to another. While its capabilities are impressive for simpler applications, they are limited when it comes to handling more demanding challenges

Let’s go through how to set it up:

  • Download the latest version of Google Canary
  • Type `chrome://flags` into the address bar.
  • Look for “Prompt API for Gemini Nano” and change its setting to ‘Enabled’.
Prompt API for Gemini Nano — Enabled
  • Also, search for “Enables optimization guide on device” and set it to ‘Enabled’.
Enables optimization guide on device — Enabled
  • Restart the browser by clicking the ‘Relaunch’ button.
  • Once the browser reopens, type `chrome://components/` into the address bar, find “Optimization Guide On Device Model”, and click ‘check for update’.
Optimization Guide On Device Model — Check for Update

You should see it start downloading , Wait until the download completes.

Now, to see everything in action:

  • Open the Developer Tools on any webpage and set up a session to use our prompts:
 const session = await window.ai.createTextSession();
  • Ask a Question
 session.prompt("Tell me a dad joke?").then(console.log);

You’ll get an answer that might just make you smile.

Answer in Dev tools

We can just integrate in our js app with these function

async function getAnswer(question){

try {


const session = await window.ai.createTextSession()

const aiResponse = await session.prompt(question);

return aiResponse

}catch(e){

throw new Error('Error creating session, AI not enabled.')

}

}

A small next js app is available on https://chrome-llm-local-nextjs-git-main-muthukumaran-ns-projects.vercel.app/

Source code on https://github.com/muthuishere/chrome-llm-local-nextjs

Currently, the Prompt API for Gemini Nano is an experimental feature available exclusively on Google Chrome Canary. While it may or may not graduate to broader Chrome releases, this initiative represents a significant step towards more private and efficient web interactions. By enabling AI to run directly within your browser, Google is paving the way for a future where your data doesn’t have to leave your device to generate useful AI-powered insights. This not only enhances privacy but also ensures faster response times. Experimenting with this feature today gives us a glimpse into the potential future of browser capabilities, where local models could revolutionize our daily digital interactions without compromising our data security

--

--

Muthukumaran Navaneethakrishnan
Muthukumaran Navaneethakrishnan

Written by Muthukumaran Navaneethakrishnan

Software Engineer works on Java, Javascript & Clojure

Responses (2)