Explore Chrome 138’s Gemini Nano: 6 Ready‑to‑Use JavaScript AI APIs

Chrome 138 introduces the on‑device Gemini Nano model and six JavaScript AI APIs—Summarizer, Language Detector, Translator, Prompt, Rewriter, and Writer—allowing web developers to add local AI capabilities such as summarisation, translation, and content generation without relying on remote servers.

Full-Stack Cultivation Path
Full-Stack Cultivation Path
Full-Stack Cultivation Path
Explore Chrome 138’s Gemini Nano: 6 Ready‑to‑Use JavaScript AI APIs

Built‑in AI model: Gemini Nano

Chrome 138 ships with Gemini Nano, an efficient variant of the Gemini large‑language‑model family designed to run locally on most modern desktops and laptops. Because the model runs on‑device, AI tasks such as text summarisation, language detection, translation, text rewriting and writing assistance can be performed without contacting remote servers.

Built‑in JavaScript AI APIs

Starting with Chrome 138, the following APIs are generally available: Summarizer API, Language Detector API, Translator API, Prompt API (usable in extensions), Writer API, Rewriter API, and an experimental Prompt API. These APIs let web pages and extensions call AI functionality directly from JavaScript.

Summarizer API

The Summarizer API extracts key points from long texts and returns concise summaries. It is useful for articles, meeting minutes, chat logs and similar content.

const options = {
  sharedContext: '这是一篇科学文章',
  type: 'key-points',
  format: 'markdown',
  length: 'medium',
};

const availability = await Summarizer.availability();
let summarizer;
if (availability === 'unavailable') {
  return;
}
if (availability === 'available') {
  summarizer = await Summarizer.create(options);
} else {
  summarizer = await Summarizer.create(options);
  summarizer.addEventListener('downloadprogress', e => {
    console.log(`已下载 ${e.loaded * 100}%`);
  });
  await summarizer.ready;
}

const longText = document.querySelector('article').innerHTML;
const summary = await summarizer.summarize(longText, {
  context: '这篇文章面向技术爱好者',
});

Language Detector API

The Language Detector API automatically identifies the language of an input string, enabling downstream translation or language‑specific features.

const availability = await LanguageDetector.availability();
let detector;
if (availability === 'unavailable') {
  return;
}
if (availability === 'available') {
  detector = await LanguageDetector.create();
} else {
  detector = await LanguageDetector.create({
    monitor(m) {
      m.addEventListener('downloadprogress', e => {
        console.log(`已下载 ${e.loaded * 100}%`);
      });
    },
  });
  await detector.ready;
}

const someUserText = 'Hallo und herzlich willkommen!';
const results = await detector.detect(someUserText);
for (const result of results) {
  console.log(result.detectedLanguage, result.confidence);
}

Translator API

The Translator API performs on‑device translation between source and target languages.

if ('Translator' in self) {
  // Translator API is supported
}

const translatorCapabilities = await Translator.availability({
  sourceLanguage: 'zh',
  targetLanguage: 'en',
});

const translator = await Translator.create({
  sourceLanguage: 'zh',
  targetLanguage: 'en',
});

await translator.translate('请问下一个公交站怎么走?');

Rewriter API

The Rewriter API can rewrite, polish, adjust tone, or simplify existing text.

const options = {
  sharedContext: '这是一封关于即将举行活动的电子邮件',
  tone: 'more-casual',
  format: 'plain-text',
  length: 'shorter',
};

const available = await Rewriter.availability();
let rewriter;
if (available === 'unavailable') {
  return;
}
if (available === 'available') {
  rewriter = await Rewriter.create(options);
} else {
  rewriter = await Rewriter.create(options);
  rewriter.addEventListener('downloadprogress', e => {
    console.log(e.loaded, e.total);
  });
}

const result = await rewriter.rewrite(reviewEl.textContent, {
  context: '避免使用任何有毒语言,并尽可能具有建设性',
});

Writer API

The Writer API generates new text from prompts.

const options = {
  sharedContext: '这是一封关于即将举行活动的电子邮件',
  tone: 'casual',
  format: 'plain-text',
  length: 'medium',
};

const available = await Writer.availability();
let writer;
if (available === 'unavailable') {
  return;
}
if (available === 'available') {
  writer = await Writer.create(options);
} else {
  writer = await Writer.create(options);
  writer.addEventListener('downloadprogress', e => {
    console.log(e.loaded, e.total);
  });
}

const result = await writer.write(
  "向银行咨询如何在我的账户上启用电汇功能。",
  { context: "我是一位长期客户" }
);

Reference

https://developer.chrome.google.cn/docs/ai/built-in?hl=zh-cn
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaScriptWeb DevelopmentChromeGemini NanoSummarizerAI APIsTranslator
Full-Stack Cultivation Path
Written by

Full-Stack Cultivation Path

Focused on sharing practical tech content about TypeScript, Vue 3, front-end architecture, and source code analysis.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.