Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9eda31a
Document the Summarizer API
chrisdavidmills Apr 24, 2025
a8ad5b0
Update files/en-us/web/api/summarizer_api/index.md
chrisdavidmills Apr 24, 2025
7edfeda
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills Apr 24, 2025
4177ab7
Add most of the Summarizer interface docs
chrisdavidmills Apr 25, 2025
d9573fa
Finish summarizer API pages
chrisdavidmills Apr 27, 2025
e07c245
Merge branch 'main' into writing-assistance-apis
chrisdavidmills May 5, 2025
9e20c15
Small updates
chrisdavidmills May 6, 2025
1617096
fixes and code improvements
chrisdavidmills May 8, 2025
338f147
fixes for tomayac review comments
chrisdavidmills May 8, 2025
7fd0393
Merge branch 'main' into writing-assistance-apis
chrisdavidmills May 12, 2025
d4260fb
Last few bits from the technical review
chrisdavidmills May 12, 2025
a25ab79
Update CreateMonitor description to be more API neutral
chrisdavidmills May 20, 2025
db2453f
Update files/en-us/web/api/summarizer/type/index.md
chrisdavidmills May 21, 2025
66f4ac1
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills May 21, 2025
7a571d8
Update files/en-us/web/api/summarizer/type/index.md
chrisdavidmills May 21, 2025
7abb369
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills May 21, 2025
34dfe28
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills May 21, 2025
1e0b9fc
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills May 21, 2025
1e9edf8
Update files/en-us/web/api/summarizer/availability_static/index.md
chrisdavidmills May 21, 2025
d9a1fc9
Update files/en-us/web/api/summarizer/availability_static/index.md
chrisdavidmills May 21, 2025
04a3de8
Update files/en-us/web/api/summarizer/expectedcontextlanguages/index.md
chrisdavidmills May 21, 2025
7882a89
Update files/en-us/web/api/summarizer/expectedcontextlanguages/index.md
chrisdavidmills May 21, 2025
b299312
Update files/en-us/web/api/summarizer/expectedinputlanguages/index.md
chrisdavidmills May 21, 2025
4673393
Update files/en-us/web/api/summarizer/inputquota/index.md
chrisdavidmills May 21, 2025
9d27864
Update files/en-us/web/api/summarizer/inputquota/index.md
chrisdavidmills May 21, 2025
07bb615
Update files/en-us/web/api/summarizer/inputquota/index.md
chrisdavidmills May 21, 2025
2141196
Update files/en-us/web/api/summarizer/outputlanguage/index.md
chrisdavidmills May 21, 2025
2560383
Update files/en-us/web/api/summarizer/measureinputusage/index.md
chrisdavidmills May 21, 2025
c7558ca
Update files/en-us/web/api/summarizer_api/index.md
chrisdavidmills May 21, 2025
1827e01
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills May 21, 2025
921cd3e
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills May 21, 2025
2682952
Fixes for bsmth review comments
chrisdavidmills May 21, 2025
bc4b6ac
Merge branch 'main' into writing-assistance-apis
bsmth May 21, 2025
5c9ea97
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills May 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finish summarizer API pages
  • Loading branch information
chrisdavidmills committed Apr 27, 2025
commit d9573fa9eeb254dd2a6ef25d7be55108a696ea6e
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: "CreateMonitor: downloadprogress event"
short-title: downloadprogress
slug: Web/API/CreateMonitor/downloadprogress_event
page-type: web-api-event
status:
- experimental
browser-compat: api.CreateMonitor.downloadprogress_event
---

{{APIRef("Summarizer API")}}{{SeeCompatTable}}

The **`downloadprogress`** event of the {{domxref("CreateMonitor")}} interface is fired when progress is made on the summarizer download.

EDITORIAL: Again, I'm not really sure about exactly what this is showing the progress of.

## Syntax

Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.

```js
addEventListener("downloadprogress", (event) => {});

ondownloadprogress = (event) => {};
```

## Event type

A {{domxref("ProgressEvent")}}. Inherits from {{domxref("Event")}}.

{{InheritanceDiagram("ProgressEvent")}}

## Examples

See the main {{domxref("CreateMonitor")}} page for an example.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using)
- [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev.
52 changes: 52 additions & 0 deletions files/en-us/web/api/createmonitor/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: CreateMonitor
slug: Web/API/CreateMonitor
page-type: web-api-interface
status:
- experimental
browser-compat: api.CreateMonitor
---

{{APIRef("Summarizer API")}}{{SeeCompatTable}}

The **`CreateMonitor`** interface of the Writing Assistance APIs ({{domxref("Summarizer API", "Summarizer API", "", "nocode")}} provides information on the progress of a summarizer download.

{{InheritanceDiagram}}

## Events

_Inherits events from its parent, {{DOMxRef("EventTarget")}}._

- {{domxref("CreateMonitor/downloadprogress_event", "downloadprogress")}} {{Experimental_Inline}}
- : Fired when progress is made on the summarizer download.

## Examples

```js
const summarizer = await Summarizer.create({
sharedContext:
"A general summary to help a user decide if the text is worth reading",
monitor: (monitor) => {
monitor.addEventListener("downloadprogress", (e) => {
console.log(`download progress: ${e.loaded}/${e.total}`);
});
},
});

const summary = await summarizer.summarize(myText);
```

EDITORIAL: I can get this to work, but I'm not really sure what exactly it is monitoring progress of. It would be good to get some more information on this.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using)
- [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev.
9 changes: 9 additions & 0 deletions files/en-us/web/api/summarizer/availability_static/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ Possible values include:

EDITORIAL: I am guessing at how language model updates are identified and downloaded. Is this something that is done programmatically, or does the app need to instruct the user to do so? I'm assuming how this is handled will be implementation-dependant, but we ought to given an example of how Chrome does it. I probably need to give some more details on "best fit" languages, as per the example mentioned in the spec. More research needed.

### Exceptions

- `NotAllowedError` {{domxref("DOMException")}}
- : Thrown if usage of the Summarizer API is blocked by a {{httpheader('Permissions-Policy/summarizer','summarizer')}} {{httpheader("Permissions-Policy")}}.
- `NotSupportedError` {{domxref("DOMException")}}
- : Thrown if the provided `context` is not in language the `Summarizer` supports.
- `UnknownError` {{domxref("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
Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/summarizer/create_static/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ A {{jsxref("Promise")}} that fulfills with a `Summarizer` object instance.

### Exceptions

- `NotAllowedError` {{domxref("DOMException")}}
- : Thrown if usage of the Summarizer API is blocked by a {{httpheader('Permissions-Policy/summarizer','summarizer')}} {{httpheader("Permissions-Policy")}}.
- `NotSupportedError` {{domxref("DOMException")}}
- : Thrown if any of the language tags specified in `expectedContextLanguages`, `expectedInputLanguages`, or `outputLanguage` are invalid, or not supported.
- `OperationError` {{domxref("DOMException")}}
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/summarizer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The **`Summarizer`** interface of the {{domxref("Summarizer API", "Summarizer AP
- {{domxref("Summarizer.destroy", "destroy()")}} {{Experimental_Inline}}
- : Destroys the `Summarizer` instance it is called on.
- {{domxref("Summarizer.measureInputUsage", "measureInputUsage()")}} {{Experimental_Inline}}
- : Reports how much input quota is used by a given summarize operation.
- : Reports how much input quota would be used by a summarize operation for a given text input.
- {{domxref("Summarizer.summarize", "summarize()")}} {{Experimental_Inline}}
- : Generates a new summary string.
- {{domxref("Summarizer.summarizeStreaming", "summarizeStreaming()")}} {{Experimental_Inline}}
Expand Down
79 changes: 79 additions & 0 deletions files/en-us/web/api/summarizer/measureinputusage/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: "Summarizer: measureInputUsage() method"
short-title: measureInputUsage()
slug: Web/API/Summarizer/measureInputUsage
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.Summarizer.measureInputUsage
---

{{APIRef("Summarizer API")}}{{SeeCompatTable}}

The **`measureInputUsage()`** method of the {{domxref("Summarizer")}} interface reports how much input quota would be used by a summarize operation for a given text input.

## Syntax

```js-nolint
measureInputUsage(input)
measureInputUsage(input, options)
```

### Parameters

- `input`
- : A string representing the input text you want an input usage measurement for.
- `options` {{optional_inline}}
- : An object specifying configuration options for the `measureInputUsage()` operation. Possible values include:
- `context`
- : A string describing the context the input text would be used in, to help generate a more suitable summary.
- `signal`
- : An {{domxref("AbortSignal")}} object instance, which allows the `measureInputUsage()` operation to be aborted via the associated {{domxref("AbortController")}}.

EDITORIAL: Aborting the call via an abort signal doesn't seem to work. Am I missing something?

### Return value

A {{jsxref("Promise")}} that fulfills with a number specifying the {{domxref("Summarizer.inputQuota", "inputQuota")}} usage of the given input text.

EDITORIAL: As I said on the inputQuota page, I ought to include some information about input quota and how it is determined for each implenentation. Maybe just including all of that info on the inputQuota page and then linking to it from here would be enough? I should specify how accurate the value returned by measureInputUsage is, whether it an estimaate, etc.?

### Exceptions

- `NotAllowedError` {{domxref("DOMException")}}
- : Thrown if usage of the Summarizer API is blocked by a {{httpheader('Permissions-Policy/summarizer','summarizer')}} {{httpheader("Permissions-Policy")}}.
- `NotReadableError` {{domxref("DOMException")}}
- : Thrown if the output summary was filtered by the user agent, for example because it was detected to be harmful, inaccurate, or nonsensical.
- `NotSupportedError` {{domxref("DOMException")}}
- : Thrown if the provided `context` is not in language the `Summarizer` supports.
- `UnknownError` {{domxref("DOMException")}}
- : Thrown if the `measureInputUsage()` call failed for any other reason, or a reason the user agent did not wish to disclose.

## Examples

### Basic `measureInputUsage()` usage

```js
const summarizer = await Summarizer.create({
sharedContext:
"A general summary to help a user decide if the text is worth reading",
type: "tl;dr",
length: "short",
});

const inputUsage = await summarizer.measureInputUsage(myText);
console.log(`Input usage: ${inputUsage}`);
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using)
- [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev.
8 changes: 8 additions & 0 deletions files/en-us/web/api/summarizer/summarize/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ A {{jsxref("Promise")}} that fulfills with a string containing the generated sum

- `InvalidStateError` {{domxref("DOMException")}}
- : Thrown if the current {{domxref("Document")}} is not active.
- `NotAllowedError` {{domxref("DOMException")}}
- : Thrown if usage of the Summarizer API is blocked by a {{httpheader('Permissions-Policy/summarizer','summarizer')}} {{httpheader("Permissions-Policy")}}.
- `NotReadableError` {{domxref("DOMException")}}
- : Thrown if the output summary was filtered by the user agent, for example because it was detected to be harmful, inaccurate, or nonsensical.
- `NotSupportedError` {{domxref("DOMException")}}
- : Thrown if the provided `context` is not in language the `Summarizer` supports.
- `UnknownError` {{domxref("DOMException")}}
- : Thrown if the `summarize()` call failed for any other reason, or a reason the user agent did not wish to disclose.

## Examples

Expand Down
8 changes: 8 additions & 0 deletions files/en-us/web/api/summarizer/summarizestreaming/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ A {{jsxref("Promise")}} that fulfills with a {{domxref("ReadableStream")}} conta

- `InvalidStateError` {{domxref("DOMException")}}
- : Thrown if the current {{domxref("Document")}} is not active.
- `NotAllowedError` {{domxref("DOMException")}}
- : Thrown if usage of the Summarizer API is blocked by a {{httpheader('Permissions-Policy/summarizer','summarizer')}} {{httpheader("Permissions-Policy")}}.
- `NotReadableError` {{domxref("DOMException")}}
- : Thrown if the output summary was filtered by the user agent, for example because it was detected to be harmful, inaccurate, or nonsensical.
- `NotSupportedError` {{domxref("DOMException")}}
- : Thrown if the provided `context` is not in language the `Summarizer` supports.
- `UnknownError` {{domxref("DOMException")}}
- : Thrown if the `summarizeStreaming()` call failed for any other reason, or a reason the user agent did not wish to disclose.

## Examples

Expand Down
5 changes: 5 additions & 0 deletions files/en-us/web/api/summarizer_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ See [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using) for a w
- {{domxref("Summarizer")}} {{Experimental_Inline}}
- : Contains all the functionality for the Summarizer API, including checking AI model availability, creating a new `Summarizer` instance, using it to generate a new summary, and more.

## HTTP headers

- {{httpheader("Permissions-Policy")}}; the {{httpheader('Permissions-Policy/summarizer','summarizer')}} directive
- : Controls access to the Summarizer API. Where a policy specifically disallows the use of the Summarizer API, any attempts to call the API's methods will fail with a `NotAllowedError` {{domxref("DOMException")}}.

## Examples

For a full example, see [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ You can specify

- : Controls whether a document loaded in a third-party context (i.e., embedded in an {{htmlelement("iframe")}}) is allowed to use the {{domxref("Storage Access API", "Storage Access API", "", "nocode")}} to request access to unpartitioned cookies.

- {{httpheader("Permissions-Policy/summarizer", "summarizer")}} {{Experimental_Inline}}

- : Controls access to the [Summarizer API](/en-US/docs/Web/API/Summarizer_API).

- {{httpheader('Permissions-Policy/usb', 'usb')}} {{Experimental_Inline}}

- : Controls whether the current document is allowed to use the [WebUSB API](/en-US/docs/Web/API/WebUSB_API).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: "Permissions-Policy: summarizer"
slug: Web/HTTP/Reference/Headers/Permissions-Policy/summarizer
page-type: http-permissions-policy-directive
status:
- experimental
browser-compat: http.headers.Permissions-Policy.summarizer
---

{{HTTPSidebar}}{{SeeCompatTable}}

The HTTP {{HTTPHeader("Permissions-Policy")}} header `summarizer` directive controls access to the [Summarizer API](/en-US/docs/Web/API/Summarizer_API).

Specifically, where a defined policy blocks Summarizer API usage, any attempts to call the API's methods will fail with a `NotAllowedError` {{domxref("DOMException")}}.

## Syntax

```http
Permissions-Policy: summarizer=<allowlist>;
```

- `<allowlist>`
- : A list of origins for which permission is granted to use the feature. See [`Permissions-Policy` > Syntax](/en-US/docs/Web/HTTP/Reference/Headers/Permissions-Policy#syntax) for more details.

## Default policy

The default allowlist for `summarizer` is `self`.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{HTTPHeader("Permissions-Policy")}} header
- [Permissions Policy](/en-US/docs/Web/HTTP/Guides/Permissions_Policy)