Skip to content

Commit 5961d6b

Browse files
committed
Reporting API top level restructure
1 parent d08b714 commit 5961d6b

1 file changed

Lines changed: 41 additions & 38 deletions

File tree

  • files/en-us/web/api/reporting_api

files/en-us/web/api/reporting_api/index.md

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,25 @@ There are several different features and problems on the web platform that gener
2929
- Occurrence of crashes.
3030
- Occurrence of user-agent interventions (when the browser blocks something your code is trying to do because it is deemed a security risk for example, or just plain annoying, like auto-playing audio).
3131

32-
The purpose of the Reporting API is to provide a consistent reporting mechanism that can be used to make such information available to developers in the form of reports represented by JavaScript objects. There are a few ways to use it, which are detailed in the sections below.
32+
The purpose of the Reporting API is to provide a consistent reporting mechanism that can be used to make such information available to developers in the form of reports represented by JavaScript objects.
3333

34-
### Reporting server endpoints
35-
36-
Each unique origin you want to get reports for can be given a series of "endpoints", which are named URLs (or groups of URLs) that can be sent reports from a user agent.
37-
A reporting server at these endpoints can collect the reports, and process and present them as needed by your application.
34+
Reports can be obtained within a page using JavaScript via reporting observers, or can be sent to a remote server endpoint.
35+
The types of reports and the two reporting approaches are detailed in the sections below.
3836

39-
The {{httpheader("Reporting-Endpoints")}} HTTP header is used to specify details about the different endpoints that a user-agent has available to it for delivering reports.
40-
The endpoints can then be used on particular HTTP response headers to indicate the specific endpoint (or in some cases endpoints) that will be used for the associated report.
41-
The directive or parameter used to specify an endpoint depends on the header.
42-
For example, the CSP {{CSP("report-to")}} directive can be used on the {{HTTPHeader("Content-Security-Policy")}} or {{HTTPHeader("Content-Security-Policy-Report-Only")}} HTTP headers to specify the endpoint that CSP violation reports should be sent to, while the [`endpoints`](/en-US/docs/Web/HTTP/Reference/Headers/Integrity-Policy#endpoints) field is used on {{httpheader("Integrity-Policy")}} or {{httpheader("Integrity-Policy-Report-Only")}} to specify where to send integrity-policy violation reports.
43-
44-
Report types that don't have an associated HTTP header, such as `crash`, `deprecation`, and `intervention` reports, will usually send reports to the "default reporting endpoint".
45-
This is just an endpoint named "default" specified using the `Reporting-Endpoints` header.
37+
### Report types
4638

47-
> [!NOTE]
48-
> There is no absolute guarantee of report delivery — a report could still fail to be collected if a serious error occurs.
39+
Reports sent to reporting observers are instances of dictionary objects, such as {{domxref("COEPViolationReport")}}, {{domxref("CrashReport")}}, {{domxref("DeprecationReport")}}, {{domxref("IntegrityViolationReport")}}, {{domxref("InterventionReport")}}, {{domxref("CSPViolationReport")}}, and {{domxref("PermissionsPolicyViolationReport")}}.
40+
These all have an origin `url`, a `type`, and a `body` that is specific to the report type.
41+
The type of report can be determined from its `type` property, which for the reports above would be `coep`, `crash`, `deprecation`, `integrity-violation`, `intervention`, `csp-violation`, and `permissions-policy-violation`.
4942

50-
The reports themselves are sent to the target endpoint by the user agent in a `POST` operation with a {{HTTPHeader("Content-Type")}} of `application/reports+json`.
51-
They are serializations of the corresponding dictionary for each [report type](#report_types).
52-
For example, CSP violation reports are a serialization of a {{domxref("CSPViolationReport")}} object.
43+
Reports sent to reporting endpoints and reporting observers are essentially the same.
44+
The only difference is that server reports are JSON serializations of the objects that have additional `user_agent` and `age` fields.
5345

54-
Reports sent to endpoints can be retrieved independently of the running of the websites they relate to, which is useful — a crash for example could bring down a website and stop anything running, but a report could still be obtained to give the developer some clues as to why it happened.
46+
A list of documented report types and their corresponding report dictionary are given in the [`options.types`](/en-US/docs/Web/API/ReportingObserver/ReportingObserver#types) parameter passed to the `ReportingObserver()` constructor.
5547

5648
### Reporting observers
5749

58-
Reports can also be obtained via {{domxref("ReportingObserver")}} objects created via JavaScript inside the website you are aiming to get reports on.
50+
Reports can be obtained via {{domxref("ReportingObserver")}} objects created via JavaScript inside the website you are aiming to get reports on.
5951
This method is not as failsafe as sending reports to the server because any page crash could stop you retrieving the reports — but it is easier to set up, and more flexible.
6052

6153
A `ReportingObserver` object is created using the {{domxref("ReportingObserver.ReportingObserver", "ReportingObserver()")}} constructor, which is passed two parameters:
@@ -65,16 +57,39 @@ A `ReportingObserver` object is created using the {{domxref("ReportingObserver.R
6557

6658
Methods are then available on the observer to start collecting reports ({{domxref("ReportingObserver.observe()")}}), retrieve the reports currently in the report queue ({{domxref("ReportingObserver.takeRecords()")}}), and disconnect the observer so it can no longer collect records ({{domxref("ReportingObserver.disconnect()")}}).
6759

68-
### Report types
60+
### Reporting server endpoints
6961

70-
Reports sent to reporting observers are instances of dictionary objects, such as {{domxref("COEPViolationReport")}}, {{domxref("CrashReport")}}, {{domxref("DeprecationReport")}}, {{domxref("IntegrityViolationReport")}}, {{domxref("InterventionReport")}}, {{domxref("CSPViolationReport")}}, and {{domxref("PermissionsPolicyViolationReport")}}.
71-
These all have an origin `url`, a `type`, and a `body` that is specific to the report type.
72-
The type of report can be determined from its `type` property, which for the reports above would be `coep`, `crash`, `deprecation`, `integrity-violation`, `intervention`, `csp-violation`, and `permissions-policy-violation`.
62+
Reports can also be sent to remote _server endpoints_ by the user agent in a `POST` operation with a {{HTTPHeader("Content-Type")}} of `application/reports+json`.
63+
They are serializations of the corresponding dictionary for each [report type](#report_types).
64+
For example, CSP violation reports are a serialization of a {{domxref("CSPViolationReport")}} object.
7365

74-
Reports sent to reporting endpoints and reporting observers are essentially the same.
75-
The only difference is that server reports are JSON serializations of the objects that have additional `user_agent` and `age` fields.
66+
Reports sent to endpoints can be retrieved independently of the running of the websites they relate to, which is useful — a crash for example could bring down a website and stop anything running, but a report could still be obtained to give the developer some clues as to why it happened.
7667

77-
A list of documented report types and their corresponding report dictionary are given in the [`options.types`](/en-US/docs/Web/API/ReportingObserver/ReportingObserver#types) parameter passed to the `ReportingObserver()` constructor.
68+
> [!NOTE]
69+
> There is no absolute guarantee of report delivery — a report could still fail to be collected if a serious error occurs.
70+
71+
The {{httpheader("Reporting-Endpoints")}} HTTP header is used to specify the name and URL for different endpoints that a user-agent has available to it for delivering reports.
72+
The endpoints can then be used on particular HTTP response headers to indicate the specific endpoint (or in some cases endpoints) that will be used for the associated report.
73+
Report types that don't have an associated HTTP header, such as `crash`, `deprecation`, and `intervention` reports, will usually send reports to the [`"default"` reporting endpoint](/en-US/docs/Web/HTTP/Reference/Headers/Reporting-Endpoints#default_reporting_endpoint) (this is just an endpoint named "default" specified using the `Reporting-Endpoints` header).
74+
75+
The mechanism to specify server endpoint for each report is listed below.
76+
77+
- `coep`
78+
- `report-to` parameter on {{HTTPHeader("Cross-Origin-Embedder-Policy")}} or {{HTTPHeader("Cross-Origin-Embedder-Policy-Report-Only")}}
79+
- `csp-violation`
80+
- {{CSP("report-to")}} directive on {{HTTPHeader("Content-Security-Policy")}} or {{HTTPHeader("Content-Security-Policy-Report-Only")}}.
81+
- `integrity-violation`
82+
- [`endpoints`](/en-US/docs/Web/HTTP/Reference/Headers/Integrity-Policy#endpoints) field in {{httpheader("Integrity-Policy")}} or {{httpheader("Integrity-Policy-Report-Only")}}
83+
- `permissions-policy-violation`
84+
- `report-to` parameter on {{HTTPHeader("Permissions-Policy")}} or {{HTTPHeader("Permissions-Policy-Report-Only")}}
85+
- [`"default"` endpoint](/en-US/docs/Web/HTTP/Reference/Headers/Reporting-Endpoints#default_reporting_endpoint)
86+
- `crash`
87+
- `crash-reporting` endpoint
88+
- `default` endpoint.
89+
- `deprecation`
90+
- `default` endpoint.
91+
- `intervention`
92+
- `default` endpoint.
7893

7994
### Generating reports via WebDriver
8095

@@ -122,18 +137,6 @@ These HTTP response headers define the endpoints where reports are sent.
122137
- {{HTTPHeader("Report-To")}} {{deprecated_inline}}
123138
- : No longer part of the Reporting API but still supported by some browsers. This sets the name and URL of reporting endpoint groups, which may be used with a number of HTTP headers especially for [Network Error Logging](/en-US/docs/Web/HTTP/Guides/Network_Error_Logging) that has not yet been updated to support `Reporting-Endpoints`. Other Reporting API reports should use `Reporting-Endpoints` instead for better future support.
124139

125-
Report endpoints can be set for the following reports using the {{CSP("report-to")}} directive or parameter on the corresponding headers:
126-
127-
- COEP violations
128-
- : {{HTTPHeader("Cross-Origin-Embedder-Policy")}} or {{HTTPHeader("Cross-Origin-Embedder-Policy-Report-Only")}}.
129-
- CSP violations
130-
- : {{HTTPHeader("Content-Security-Policy")}} or {{HTTPHeader("Content-Security-Policy-Report-Only")}}.
131-
132-
Report endpoints can be set for the following reports using the [`endpoints`](/en-US/docs/Web/HTTP/Reference/Headers/Integrity-Policy#endpoints) field in a structured dictionary on the corresponding headers:
133-
134-
- Integrity-Policy violations
135-
- : {{httpheader("Integrity-Policy")}} or {{httpheader("Integrity-Policy-Report-Only")}}.
136-
137140
## Examples
138141

139142
### Reporting deprecated features

0 commit comments

Comments
 (0)