web api instance method
Summarizer: summarize() method
Limited availabilitySecure context
The summarize() method of the Summarizer interface generates a new summary string.
Syntax
summarize(input)
summarize(input, options)
Parameters
input- : A string representing the text to be summarized.
optionsOptional- : An object specifying configuration options for the
summarize()operation. Possible values include:context- : A string describing the context the input text is being used in, which helps the
Summarizergenerate a more suitable summary.
- : A string describing the context the input text is being used in, which helps the
signal- : An
AbortSignalobject instance, which allows thesummarize()operation to be aborted via the associatedAbortController.
- : An
- : An object specifying configuration options for the
Return value
A Promise that fulfills with a string containing the generated summary.
Exceptions
AbortErrorDOMExceptionInvalidStateErrorDOMException- : Thrown if the current
Documentis not active.
- : Thrown if the current
NotAllowedErrorDOMException- : Thrown if usage of the Summarizer API is blocked by a
summarizerPermissions-Policy.
- : Thrown if usage of the Summarizer API is blocked by a
NotReadableErrorDOMException- : Thrown if the output summary was filtered by the user agent, for example because it was detected to be harmful, inaccurate, or nonsensical.
NotSupportedErrorDOMException- : Thrown if the provided
contextis not in language theSummarizersupports.
- : Thrown if the provided
QuotaExceededError- : Thrown if the summarize operation exceeds the available
inputQuota.
- : Thrown if the summarize operation exceeds the available
UnknownErrorDOMException- : Thrown if the
summarize()call failed for any other reason, or a reason the user agent did not wish to disclose.
- : Thrown if the
Examples
Basic summarize() usage
const summarizer = await Summarizer.create({
sharedContext:
"A general summary to help a user decide if the text is worth reading",
type: "tldr",
length: "short",
});
const summary = await summarizer.summarize(myTextString);
console.log(summary);
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
- Using the Summarizer API
- Web AI demos on chrome.dev