大网数据广告活动
Web 标准与前端开发

Summarizer: availability() static method

· 52CE 我爱测

The **`availability()`** static method of the Summarizer interface returns an enumerated value that indicates whether the browser AI model supports (or will support) a given `Summarizer` configuration.

Summarizer API

The availability() static method of the Summarizer interface returns an enumerated value that indicates whether the browser AI model supports (or will support) a given Summarizer configuration.

Syntax

Summarizer.availability()
Summarizer.availability(options)

Parameters

  • options
    • : An options object specifying a possible configuration for a Summarizer. Possible values include:
      • expectedInputLanguages
        • : An array of strings equal to BCP 47 language tag specifying the expected languages of the input text. Defaults to ["en"].
      • expectedContextLanguages
        • : An array of strings equal to BCP 47 language tags specifying the expected languages of any provided context strings (either the sharedContext passed to the Summarizer, or a context specified during a Summarizer.summarize or Summarizer.summarizeStreaming call). Defaults to ["en"].
      • format
        • : An enumerated value specifying the text Summarizer.format you want summaries returned in. Defaults to markdown.
      • length
        • : An enumerated value specifying the relative Summarizer.length for the generated summaries. Defaults to short.
      • outputLanguage
        • : A string equal to a BCP 47 language tag specifying the expected language of summaries generated by the Summarizer. Defaults to en.
      • type
        • : An enumerated value specifying the Summarizer.type of summary you want this Summarizer to generate. Defaults to key-points.

Return value

A Promise that fulfills with an enumerated value indicating whether support is available (or will be available) for a given Summarizer configuration, or null if support could not be determined.

Possible values include:

  • available
    • : The browser supports the given configuration and can be used immediately.
  • downloadable
    • : The browser supports the given configuration, but it first needs to download an AI model, or some fine-tuning data for the model.
  • downloading
    • : The browser supports the given configuration, but it needs to finish an ongoing download before it can proceed.
  • unavailable
    • : The browser does not support the given configuration, or the Summarizer API is blocked by a Permissions-Policy/summarizer Permissions-Policy.

Exceptions

  • NotSupportedError DOMException
    • : Thrown if the provided context is not in language the Summarizer supports.
  • UnknownError DOMException
    • : Thrown if the measureInputUsage() call failed for any other reason, or a reason the user agent did not wish to disclose.

Examples

Basic availability() usage

async function getSummarizer() {
  const options = {
    sharedContext: "This is a scientific article",
    type: "key-points",
    format: "markdown",
    length: "medium",
  };

  const availability = await Summarizer.availability(options);
  if (availability === "unavailable") {
    // The Summarizer API isn't usable
    return undefined;
  } else if (availability === "available") {
    // The Summarizer API can be used immediately
    return Summarizer.create(options);
  }
  // The Summarizer API can be used after the model is downloaded
  const summarizer = await Summarizer.create(options);
  summarizer.addEventListener("downloadprogress", (e) => {
    console.log(`Downloaded ${e.loaded * 100}%`);
  });
  return summarizer;
}

Detecting language support

async function langSupport(lang) {
  const availability = await Summarizer.availability({
    expectedInputLanguages: [lang],
  });
  return availability;
}

langSupport("en-US");
langSupport("fr");
langSupport("zh-CN");

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。