Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial review: Topics API docs #30107

Merged
merged 49 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8661469
Add Topic API docs
chrisdavidmills Jul 26, 2023
fa39c12
Merge branch 'main' into topics-api
chrisdavidmills Oct 2, 2023
886c17f
Update files/en-us/web/api/fetch/index.md
chrisdavidmills Oct 2, 2023
fcbaf9c
Making fixes for samdutton review comments
chrisdavidmills Oct 2, 2023
fe27f5c
prettier fix
chrisdavidmills Oct 2, 2023
9555094
Merge branch 'main' into topics-api
chrisdavidmills Oct 2, 2023
c740f99
Merge branch 'main' into topics-api
chrisdavidmills Oct 17, 2023
b40bfe7
Making fixes for samdutton comments
chrisdavidmills Oct 17, 2023
7a6f3bf
fix ad tech example URL issue
chrisdavidmills Oct 18, 2023
f2df65c
Rewrite explanatory text for Topics API usage
chrisdavidmills Oct 18, 2023
5d6b663
improve Sec-Browsing-Topics header description and ref page
chrisdavidmills Oct 18, 2023
a201a6e
Merge branch 'main' into topics-api
chrisdavidmills Oct 18, 2023
e33b683
minor tweaks to browsingTopics() wording
chrisdavidmills Oct 18, 2023
daebcf0
Merge branch 'main' into topics-api
chrisdavidmills Oct 27, 2023
844bc8c
Further update description of API usage, based on samdutton comments
chrisdavidmills Oct 27, 2023
eeb83a3
Fixes for latest samdutton review
chrisdavidmills Oct 30, 2023
f0db378
Merge branch 'main' into topics-api
chrisdavidmills Oct 31, 2023
5235cc5
remove specification macros for features that have no spec_url in BCD
chrisdavidmills Oct 31, 2023
154535b
Merge branch 'main' into topics-api
chrisdavidmills Nov 6, 2023
0c491a0
final few bits of cleanup
chrisdavidmills Nov 6, 2023
50ac344
Merge branch 'main' into topics-api
chrisdavidmills Nov 6, 2023
302b463
Update history entry description with feedback from Yao
chrisdavidmills Nov 7, 2023
8a829dc
Merge branch 'topics-api' of github.com:chrisdavidmills/content into …
chrisdavidmills Nov 7, 2023
788e787
Merge branch 'main' into topics-api
chrisdavidmills Nov 7, 2023
0028eca
Merge branch 'main' into topics-api
chrisdavidmills Nov 8, 2023
aad4ccd
Merge branch 'main' into topics-api
chrisdavidmills Nov 15, 2023
c516924
Add privacy sandbox enrollment information, restructure privacy secti…
chrisdavidmills Nov 15, 2023
28720be
Merge branch 'main' into topics-api
chrisdavidmills Nov 15, 2023
6c5f8c3
Merge branch 'main' into topics-api
chrisdavidmills Nov 17, 2023
ad934a7
Merge branch 'main' into topics-api
chrisdavidmills Dec 6, 2023
ef1f139
Restructure and clarify topics api content, answer review comments
chrisdavidmills Dec 7, 2023
4e736f7
missing paren
chrisdavidmills Dec 7, 2023
c211dd9
Other small tweaks
chrisdavidmills Dec 7, 2023
98dd17b
Merge branch 'main' into topics-api
chrisdavidmills Dec 7, 2023
de4aa9e
Merge branch 'main' into topics-api
chrisdavidmills Dec 19, 2023
0f88582
Update non-standard and spec opposition information
chrisdavidmills Dec 19, 2023
d1a2069
fix merge conflicts
chrisdavidmills Dec 20, 2023
bbe5dbe
Merge branch 'main' of github.com:mdn/content into topics-api
chrisdavidmills Jan 5, 2024
48289f3
Merge branch 'main' into topics-api
chrisdavidmills Feb 11, 2024
dfd7f08
fix linting errors
chrisdavidmills Feb 15, 2024
84667d3
Further updates to topics API description
chrisdavidmills Feb 15, 2024
92e1ae0
Update standards positions information
chrisdavidmills Feb 15, 2024
7603ce6
more changes to increase accuracy of content
chrisdavidmills Feb 19, 2024
899728f
Merge branch 'main' into topics-api
chrisdavidmills Feb 22, 2024
12f8163
Update files/en-us/web/api/topics_api/index.md
chrisdavidmills Feb 22, 2024
8dbfcb6
Update files/en-us/web/api/topics_api/index.md
chrisdavidmills Feb 22, 2024
188f0cb
Update files/en-us/web/api/topics_api/index.md
chrisdavidmills Feb 22, 2024
ef2011f
Update files/en-us/web/api/document/browsingtopics/index.md
chrisdavidmills Feb 22, 2024
15ad355
Fixes for wbamberg review comments
chrisdavidmills Feb 22, 2024
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
1 change: 1 addition & 0 deletions files/en-us/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12780,6 +12780,7 @@
/en-US/docs/Web/Performance/Time_to_interactive /en-US/docs/Glossary/Time_to_interactive
/en-US/docs/Web/Performance/business_case_for_performance /en-US/docs/Learn/Performance/business_case_for_performance
/en-US/docs/Web/Performance/learn /en-US/docs/Web/Performance/How_browsers_work
/en-US/docs/Web/Privacy/Partitioned_cookies /en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies
/en-US/docs/Web/Privacy/Tracking_Protection /en-US/docs/Web/Privacy/Firefox_tracking_protection
/en-US/docs/Web/Progressive_web_apps/Add_to_home_screen /en-US/docs/Web/Progressive_web_apps/Guides/Making_PWAs_installable
/en-US/docs/Web/Progressive_web_apps/Advantages /en-US/docs/Web/Progressive_web_apps
Expand Down
102 changes: 102 additions & 0 deletions files/en-us/web/api/document/browsingtopics/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
title: "Document: browsingTopics() method"
short-title: browsingTopics()
slug: Web/API/Document/browsingTopics
page-type: web-api-instance-method
status:
- non-standard
browser-compat: api.Document.browsingTopics
---

{{APIRef("Topics API")}}

> **Warning:** This feature is currently opposed by two browser vendors. See the [Standards positions](/en-US/docs/Web/API/Topics_API#standards_positions) section below for details of opposition.
> **Note:** An [Enrollment process](/en-US/docs/Web/Privacy/Privacy_sandbox/Enrollment) is required to use this feature in your applications.
The `browsingTopics()` method of the {{domxref("Document")}} interface returns a promise that fulfills with an array of objects representing the selected topics for the current user, which can then be returned to the ad tech platform in a subsequent fetch request. It also triggers the browser to observe the topics inferred from the calling site's URL (i.e. the site where the ad tech `<iframe>` is embedded).

See [Using the Topics API](/en-US/docs/Web/API/Topics_API/Using) for more details.

> **Note:** `browsingTopics()` does not rely on HTTP headers to send topics and mark topics as observed like the other [Topics API enabling features](/en-US/docs/Web/API/Topics_API/Using#what_api_features_enable_the_topics_api), but it is somewhat less performant. You are advised to use one of the HTTP header-using features, falling back to `browsingTopics()` only in situations where the headers cannot be modified.
## Syntax

```js-nolint
browsingTopics()
browsingTopics(options)
```

### Parameters

- `options` {{optional_inline}}
- : An options object, which can contain the following properties:
- `skipObservation`
- : A boolean value that, if set to `true`, causes the browser to _not_ observe topics when `browsingTopics()` is invoked. The default is `false`, which causes topics to be observed.

### Return value

A {{jsxref("Promise")}} that fulfills with an array of up to three objects representing the current user's selected topics for the last three epochs. Each object contains the following properties:

- `configVersion`
- : A string identifying the algorithm (other than the model part) used to calculate the topic.
- `modelVersion`
- : A string representing the model used to classify a string (such as a web page's hostname) into topic IDs.
- `taxonomyVersion`
- : A string representing the taxonomy version used.
- `topic`
- : A number representing the ID of the topic, which can be used by the browser to retrieve the topic from the taxonomy (see an example [taxonomy of interests](https://github.com/patcg-individual-drafts/topics/blob/main/taxonomy_v1.md)).
- `version`
- : The `configVersion`, `modelVersion`, and `taxonomyVersion`, concatenated with colons (`:`) between each.

The exact property values may vary by browser implementation. An example object from Chrome might look as follows:

```js
{
configVersion: "chrome.1",
modelVersion: "1",
taxonomyVersion: "1",
topic: 43,
version: "chrome.1:1:1"
}
```

### Exceptions

- `NotAllowedError` {{domxref("DOMException")}}
- : Thrown if:
- Usage of the [Topics API](/en-US/docs/Web/API/Topics_API) is disallowed by a {{httpheader('Permissions-Policy/browsing-topics','browsing-topics')}} [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy).
- The calling site does not have the Topics API included in a successful [privacy sandbox enrollment process](/en-US/docs/Web/Privacy/Privacy_sandbox/Enrollment).

## Examples

```js
// Get an array of top topics for this user
const topics = await document.browsingTopics();

// Request an ad creative
const response = await fetch("https://ads.example/get-creative", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(topics),
});

// Get the JSON from the response
const creative = await response.json();

// Display ad
```

## Specifications

This feature is not part of an official standard, although it is specified in the [Topics API Unofficial Proposal Draft](https://patcg-individual-drafts.github.io/topics/).

## Browser compatibility

{{Compat}}

## See also

- [Topics API](/en-US/docs/Web/API/Topics_API)
2 changes: 2 additions & 0 deletions files/en-us/web/api/document/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ _This interface also inherits from the {{DOMxRef("Node")}} and {{DOMxRef("EventT
- : Adopt node from an external document.
- {{DOMxRef("Document.append()")}}
- : Inserts a set of {{domxref("Node")}} objects or string objects after the last child of the document.
- {{DOMxRef("Document.browsingTopics()")}} {{Experimental_Inline}}
- : Returns a promise that fulfills with an array of objects representing observed topics for the current user and site. It also triggers the browser to observe topics for the current user and site. See the [Topics API](/en-US/docs/Web/API/Topics_API) for more details.
- {{DOMxRef("Document.captureEvents()")}} {{Deprecated_Inline}}
- : See {{DOMxRef("Window.captureEvents")}}.
- {{DOMxRef("Document.caretPositionFromPoint()")}}
Expand Down
91 changes: 52 additions & 39 deletions files/en-us/web/api/fetch/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,67 @@ fetch(resource, options)
- : An object containing any custom settings you want to apply to the request.
The possible options are:

- `method`
- : The request method, e.g., `"GET"`, `"POST"`.
The default is `"GET"`.
Note that the {{httpheader("Origin")}} header is not set on Fetch requests with a method of {{HTTPMethod("HEAD")}} or {{HTTPMethod("GET")}}.
Any string that is a case-insensitive match for one of the methods in [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110#name-overview) will be uppercased automatically.
If you want to use a custom method (like `PATCH`), you should uppercase it yourself.
- `headers`

- : Any headers you want to add to your request, contained within a {{domxref("Headers")}} object or an object literal with {{jsxref("String")}} values.
Note that [some names are forbidden](/en-US/docs/Glossary/Forbidden_header_name).

> **Note:** The [`Authorization`](/en-US/docs/Web/HTTP/Headers/Authorization) HTTP header may be added to a request, but will be removed if the request is redirected cross-origin.
- `body`

- : Any body that you want to add to your request:
this can be a {{domxref("Blob")}}, an {{jsxref("ArrayBuffer")}}, a {{jsxref("TypedArray")}}, a {{jsxref("DataView")}},
a {{domxref("FormData")}}, a {{domxref("URLSearchParams")}}, string object or literal,
or a {{domxref("ReadableStream")}} object. This latest possibility is still experimental; check the [compatibility information](/en-US/docs/Web/API/Request#browser_compatibility) to verify you can use it.
Note that a request using the `GET` or `HEAD` method cannot have a body.
- `mode`
- : The [mode](/en-US/docs/Web/API/Request/mode) you want to use for the request, e.g., `cors`,
`no-cors`, or `same-origin`.

- `browsingTopics` {{experimental_inline}}

- : A boolean specifying that the selected topics for the current user should be sent in a {{httpheader("Sec-Browsing-Topics")}} header with the associated request. See [Using the Topics API](/en-US/docs/Web/API/Topics_API/Using) for more details.

- `cache`

- : A string indicating how the request will interact with the browser's [HTTP cache](/en-US/docs/Web/HTTP/Caching). The possible values, `default`, `no-store`, `reload`, `no-cache`, `force-cache`, and `only-if-cached`, are documented in the article for the {{domxref("Request/cache", "cache")}} property of the {{domxref("Request")}} object.

- `credentials`

- : Controls what browsers do with credentials ([cookies](/en-US/docs/Web/HTTP/Cookies), [HTTP authentication](/en-US/docs/Web/HTTP/Authentication) entries, and TLS client certificates). Must be one of the following strings:

- `omit`
- : Tells browsers to exclude credentials from the request, and ignore any credentials sent back in the response (e.g., any {{HTTPHeader("Set-Cookie")}} header).
- `same-origin`
- : Tells browsers to include credentials with requests to same-origin URLs, and use any credentials sent back in responses from same-origin URLs. **This is the default value.**
- `include`
- `omit`: Tells browsers to exclude credentials from the request, and ignore any credentials sent back in the response (e.g., any {{HTTPHeader("Set-Cookie")}} header).
- `same-origin`: Tells browsers to include credentials with requests to same-origin URLs, and use any credentials sent back in responses from same-origin URLs. **This is the default value.**
- `include`: Tells browsers to include credentials in both same- and cross-origin requests, and always use any credentials sent back in responses.

- : Tells browsers to include credentials in both same- and cross-origin requests, and always use any credentials sent back in responses.
> **Note:** Credentials may be included in simple and "final" cross-origin requests, but should not be included in [CORS preflight requests](/en-US/docs/Web/HTTP/CORS#preflight_requests_and_credentials).
> **Note:** Credentials may be included in simple and "final" cross-origin requests, but should not be included in [CORS preflight requests](/en-US/docs/Web/HTTP/CORS#preflight_requests_and_credentials).
- `headers`

- `cache`
- : A string indicating how the request will interact with the browser's [HTTP cache](/en-US/docs/Web/HTTP/Caching). The possible values, `default`, `no-store`, `reload`, `no-cache`, `force-cache`, and `only-if-cached`, are documented in the article for the {{domxref("Request/cache", "cache")}} property of the {{domxref("Request")}} object.
- : Any headers you want to add to your request, contained within a {{domxref("Headers")}} object or an object literal with {{jsxref("String")}} values.
Note that [some names are forbidden](/en-US/docs/Glossary/Forbidden_header_name).

> **Note:** The [`Authorization`](/en-US/docs/Web/HTTP/Headers/Authorization) HTTP header may be added to a request, but will be removed if the request is redirected cross-origin.
- `integrity`

- : Contains the [subresource integrity](/en-US/docs/Web/Security/Subresource_Integrity)
value of the request (e.g., `sha256-BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=`).

- `keepalive`
- : The `keepalive` option can be used to allow the request to outlive the page.
Fetch with the `keepalive` flag is a replacement for the {{domxref("Navigator.sendBeacon()")}} API.
- `method`

- : The request method, e.g., `"GET"`, `"POST"`.
The default is `"GET"`.
Note that the {{httpheader("Origin")}} header is not set on Fetch requests with a method of {{HTTPMethod("HEAD")}} or {{HTTPMethod("GET")}}.
(This behavior was corrected in Firefox 65 — see [Firefox bug 1508661](https://bugzil.la/1508661).)
Any string which is a case-insensitive match for one of the methods in [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110#name-overview) will be uppercased automatically.
If you want to use a custom method (like `PATCH`), you should uppercase it yourself.

- `mode`
- : The mode you want to use for the request, e.g., `cors`,
`no-cors`, or `same-origin`.
- `priority`
- : Specifies the priority of the fetch request relative to other requests of the same type. Must be one of the following strings:
- `high`
- : A high priority fetch request relative to other requests of the same type.
- `low`
- : A low priority fetch request relative to other requests of the same type.
- `auto`
- : Automatically determine the priority of the fetch request relative to other requests of the same type (default).
- `redirect`

- : How to handle a `redirect` response:
Expand All @@ -92,31 +115,19 @@ fetch(resource, options)
See [WHATWG fetch standard](https://fetch.spec.whatwg.org/#concept-request-redirect-mode) for more information.

- `referrer`

- : A string specifying the referrer of the request. This can be a
same-origin URL, `about:client`, or an empty string.

- `referrerPolicy`
- : Specifies the [referrer policy](https://w3c.github.io/webappsec-referrer-policy/#referrer-policies) to use for the request. May be one of `no-referrer`,
`no-referrer-when-downgrade`, `same-origin`,
`origin`, `strict-origin`,
`origin-when-cross-origin`,
`strict-origin-when-cross-origin`, or `unsafe-url`.
- `integrity`
- : Contains the [subresource integrity](/en-US/docs/Web/Security/Subresource_Integrity)
value of the request (e.g., `sha256-BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=`).
- `keepalive`
- : The `keepalive` option can be used to allow the request to outlive the page.
Fetch with the `keepalive` flag is a replacement for the {{domxref("Navigator.sendBeacon()")}} API.
- `signal`
- : An {{domxref("AbortSignal")}} object instance; allows you to communicate with a
fetch request and abort it if desired via an {{domxref("AbortController")}}.
- `priority`
- : Specifies the priority of the fetch request relative to other requests of the same type. Must be one of the following strings:
- `high`
- : A high-priority fetch request relative to other requests of the same type.
- `low`
- : A low-priority fetch request relative to other requests of the same type.
- `auto`
- : Automatically determine the priority of the fetch request relative to other requests of the same type (default).

### Return value

Expand All @@ -127,6 +138,8 @@ A {{jsxref("Promise")}} that resolves to a {{domxref("Response")}} object.
- `AbortError` {{domxref("DOMException")}}
- : The request was aborted due to a call to the {{domxref("AbortController")}}
{{domxref("AbortController.abort", "abort()")}} method.
- `NotAllowedError` {{domxref("DOMException")}}
- : Usage of the [Topics API](/en-US/docs/Web/API/Topics_API) is specifically disallowed by a {{httpheader('Permissions-Policy/browsing-topics','browsing-topics')}} [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy), and a `fetch()` request was made with `browsingTopics: true`.
- {{jsxref("TypeError")}}
- : Can occur for the following reasons:

Expand Down
70 changes: 70 additions & 0 deletions files/en-us/web/api/htmliframeelement/browsingtopics/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: "HTMLIFrameElement: browsingTopics property"
short-title: browsingTopics
slug: Web/API/HTMLIFrameElement/browsingTopics
page-type: web-api-instance-property
status:
- non-standard
browser-compat: api.HTMLIFrameElement.browsingTopics
---

{{APIRef("HTML DOM")}}

> **Warning:** This feature is currently opposed by two browser vendors. See the [Standards positions](#standards_positions) section below for details of opposition.
The **`browsingTopics`** property of the {{domxref("HTMLIFrameElement")}} interface is a boolean specifying that that the selected topics for the current user should be sent with the request for the associated {{htmlelement("iframe")}}'s source in a {{httpheader("Sec-Browsing-Topics")}} header. This reflects the `browsingtopics` HTML attribute.

See [Using the Topics API](/en-US/docs/Web/API/Topics_API/Using) for more details.

## Value

A boolean. The default value is `false`; set it to `true` to send the associated `<iframe>` source request with a {{httpheader("Sec-Browsing-Topics")}} header containing the selected topics for the current user.

## Examples

### Get

Set `browsingtopics` to `true` then load the `<iframe>` contents declaratively:

```html
<iframe browsingtopics title="Advertising container" src="adtech1.example">
...
</iframe>
```

Log the `browsingTopics` value via script:

```js
const iframeElem = document.querySelector("iframe");
console.log(iframeElem.browsingTopics); // will return true in supporting browsers
```

### Set

Specify a minimum `<iframe>`:

```html
<iframe> ... </iframe>
```

Set `browsingtopics` to `true` then load the `<iframe>` contents via script:

```js
const iframeElem = document.querySelector("iframe");

iframeElem.browsingTopics = true;
iframeElem.title = "Advertising container";
iframeElem.src = "adtech1.example";
```

## Specifications

This feature is not part of an official standard, although it is specified in the [Topics API Unofficial Proposal Draft](https://patcg-individual-drafts.github.io/topics/).

## Browser compatibility

{{Compat}}

## See also

- [Topics API](/en-US/docs/Web/API/Topics_API)
6 changes: 2 additions & 4 deletions files/en-us/web/api/htmliframeelement/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ _Inherits properties from its parent, {{domxref("HTMLElement")}}_.
- : A boolean value indicating whether the inline frame is willing to be placed into full screen mode. See [Using fullscreen mode](/en-US/docs/Web/API/Fullscreen_API) for details.
- {{domxref("HTMLIFrameElement.allowPaymentRequest")}} {{Deprecated_Inline}} {{Non-standard_Inline}}
- : A boolean value indicating whether the [Payment Request API](/en-US/docs/Web/API/Payment_Request_API) may be invoked inside a cross-origin iframe.
- {{domxref("HTMLIFrameElement.browsingTopics")}} {{Experimental_Inline}}
- : A boolean property specifying that that the selected topics for the current user should be sent with the request for the associated {{htmlelement("iframe")}}'s source. This reflects the `browsingtopics` content attribute value.
- {{domxref("HTMLIFrameElement.contentDocument")}} {{ReadOnlyInline}}
- : Returns a {{domxref("Document")}}, the active document in the inline frame's nested browsing context.
- {{domxref("HTMLIFrameElement.contentWindow")}} {{ReadOnlyInline}}

- : Returns a {{glossary("WindowProxy")}}, the window proxy for the nested browsing context.

- {{domxref("HTMLIFrameElement.credentialless")}} {{Experimental_Inline}}

- : A boolean value indicating whether the `<iframe>` is credentialless, meaning that its content is loaded in a new, ephemeral context. This context does not have access to the parent context's shared storage and credentials. In return, the {{httpheader("Cross-Origin-Embedder-Policy")}} (COEP) embedding rules can be lifted, so documents with COEP set can embed third-party documents that do not. See [IFrame credentialless](/en-US/docs/Web/Security/IFrame_credentialless) for a deeper explanation.

- {{domxref("HTMLIFrameElement.csp")}} {{Experimental_Inline}}
- : Specifies the Content Security Policy that an embedded document must agree to enforce upon itself.
- {{domxref("HTMLIFrameElement.featurePolicy")}} {{ReadOnlyInline}} {{Experimental_Inline}}
Expand Down
Loading
Loading