GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||
GeezerVison is showing developer.mozilla.org — Reporting API - Web APIs | MDN Reporting API
|
| Type | Report object | Notes |
|---|---|---|
coep |
COEPViolationReport |
Cross-Origin-Embedder-Policy (COEP) violations |
coop |
COOPViolationReport |
Cross-Origin-Opener-Policy (COOP) violations |
crash |
CrashReport |
Browser crash reports |
csp-violation |
CSPViolationReport |
Content Security Policy (CSP) violations |
deprecation |
DeprecationReport |
Deprecated features used by the site. |
integrity-violation |
IntegrityViolationReport |
Integrity-Policy violations |
intervention |
InterventionReport |
Features blocked by the user agent, such as ads that significantly impact page performance |
permissions-policy-violation |
PermissionsPolicyViolationReport |
Permissions-Policy violations |
A list of the types is also is given in the options.types parameter passed to the ReportingObserver() constructor.
Reports can be obtained via ReportingObserver objects created via JavaScript inside the website you are aiming to get reports on.
This method is not as failsafe as sending reports to the server because any page crash could stop you from retrieving the reports; it is, however, easier to set up, and more flexible.
A ReportingObserver object is created using the ReportingObserver() constructor, which is passed two parameters:
ReportingObserver object, which allows observation to be controlled directly from inside the callback. The callback runs when observation starts.buffered: true).Methods are then available on the observer to start collecting reports (ReportingObserver.observe()), retrieve the reports currently in the report queue (ReportingObserver.takeRecords()), and disconnect the observer so it can no longer collect records (ReportingObserver.disconnect()).
Reports can also be sent to remote server endpoints by the user agent in a POST operation with a Content-Type of application/reports+json.
They are serializations of the corresponding dictionary for each report type.
For example, CSP violation reports are a serialization of a CSPViolationReport object.
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.
Note: There is no absolute guarantee of report delivery — a report could still fail to be collected if a serious error occurs.
The 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.
The endpoints can then be specified within particular HTTP response headers to indicate the endpoint (or in some cases, endpoints) that associated reports will be delivered to.
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 (this is just an endpoint named "default" specified using the Reporting-Endpoints header).
The mechanisms to specify server endpoints for each report type are listed below:
coep
report-to parameter on Cross-Origin-Embedder-Policy or Cross-Origin-Embedder-Policy-Report-Onlycsp-violation
report-to directive on Content-Security-Policy or Content-Security-Policy-Report-Only.integrity-violation
endpoints field in Integrity-Policy or Integrity-Policy-Report-Onlypermissions-policy-violation
report-to parameter on Permissions-Policy or Permissions-Policy-Report-Only"default" endpointcrash
crash-reporting endpointdefault endpoint.deprecation
default endpoint.intervention
default endpoint.The Reporting API spec also defines a Generate Test Report WebDriver extension, which allows you to simulate report generation during automation. Reports generated via WebDriver are observed by any registered ReportingObserver objects present in the loaded website. This is not yet documented.
CrashReportContextProvides methods enabling arbitrary data to be recorded for the current top-level browsing context, which is then added to a CrashReport and sent to a reporting endpoint when a browser crash occurs.
ReportingObserverAn object that can be used to collect and access reports as they are generated.
SecurityPolicyViolationEventRepresents the event object of a securitypolicyviolation event fired on an element, document, or worker when its CSP is violated.
This is defined as part of the HTTP Content Security Policy (CSP) specifications.
COEPViolationReportContains details of a Cross-Origin-Embedder-Policy (COEP) violation.
CrashReportContains details of a browser crash.
CSPViolationReportContains details of a CSP violation. This is defined as part of the HTTP Content Security Policy (CSP) specifications.
DeprecationReportContains details of deprecated web platform features that a website is using.
InterventionReportContains details of an intervention report, which is generated when a request made by the website has been denied by the browser; e.g., for security reasons.
IntegrityViolationReportContains information about a resource that was blocked because it did not meet the Subresource Integrity guarantees required by its Integrity-Policy, or that would be blocked for report-only policies set using Integrity-Policy-Report-Only.
This is defined as part of the Subresource Integrity specification.
PermissionsPolicyViolationReportContains details of a Permissions-Policy violation.
These HTTP response headers define the endpoints where reports are sent.
Reporting-EndpointsSets the name and URL of reporting endpoints.
These endpoints can be used in the report-to directive, which may be used with a number of HTTP headers including Content-Security-Policy or Content-Security-Policy-Report-Only.
Report-To 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 that has not yet been updated to support Reporting-Endpoints. Other Reporting API reports should use Reporting-Endpoints instead for better future support.
This example shows how to observe "deprecation" reports within a page that triggers them using a ReportingObserver.
Note we've chosen to display a "deprecation" report because it doesn't require that particular HTTP headers are set, and can therefore be run as an MDN live example.
<pre id="log"></pre>
#log {
height: 200px;
margin: 10px;
overflow: scroll;
padding: 0.5rem;
border: 1px solid black;
}
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = `${logElement.innerText}${text}\n`;
logElement.scrollTop = logElement.scrollHeight;
}
First we construct a new ReportingObserver object to listen for reports with the type "deprecation", passing a callback that will receive and log the reports.
const options = {
types: ["deprecation"],
buffered: true,
};
const observer = new ReportingObserver((reports, observer) => {
reports.forEach((report) => {
log(JSON.stringify(report, null, 2));
});
}, options);
// Start the observer
observer.observe();
We then call the following code which uses synchronous XHR (deprecated API). Note that this is defined after the observer it triggers once the observer is running.
const xhr = new XMLHttpRequest();
xhr.open("GET", "/", false); // false = synchronous (deprecated)
xhr.send();
On browsers that support deprecation reports, a report should be displayed below.
Note that the type is "deprecation".