大网数据广告活动
Web 标准与前端开发

ReportingObserver: ReportingObserver() constructor

· 52CE 我爱测

The **`ReportingObserver()`** constructor of the Reporting API creates a new ReportingObserver object instance, which can be used to collect and access reports.

Reporting API

The ReportingObserver() constructor of the Reporting API creates a new ReportingObserver object instance, which can be used to collect and access reports.

Syntax

new ReportingObserver(callback)
new ReportingObserver(callback, options)

Parameters

  • callback

    • : A callback function that runs when the observer starts to collect reports (i.e., via ReportingObserver.observe()). The callback function is given two parameters:
      • reports

        • : A sequence of objects representing the reports collected in the observer's report queue.

          Report objects are expected to have the following properties:

          • body
            • : An object representing the body of the report. The structure of the report (in particular of its body), depends on its type.
          • type
            • : A string indicating the type of the report. For information on report types see options.types below.
          • url
            • : A string representing the URL of the document that generated the report.
      • observer

        • : A reference to the same ReportingObserver object, allowing for recursive report collection, and so on.
  • options

    • : An object allowing you to set the options for creating the object. The available options are:
      • types

        • : An array of strings representing the types of report to be collected by this observer. Available types include:

          • coep
            • : Violations of the site's Cross-Origin-Embedder-Policy (COEP). Reports are COEPViolationReport instances.
          • crash
            • : Browser crash reports. Reports are CrashReport instances. Note that crash reports aren't retrievable via a ReportingObserver but can be sent to a server.
          • csp-violation
            • : Violations of the site's CSP policy. Reports are CSPViolationReport instances.
          • deprecation
            • : Deprecated features used by the site. Reports are DeprecationReport instances.
          • integrity-violation
            • : Violations of the page's integrity policy. Reports are IntegrityViolationReport instances.
          • intervention
            • : Features blocked by the user agent, for example, if an ad significantly impacts page performance. Reports are InterventionReport instances.
          • permissions-policy-violation
            • : Violations of the site's Permissions-Policy. Reports are PermissionsPolicyViolationReport instances.

          If this option is omitted, all supported types are collected.

      • buffered

        • : A boolean that defines whether the reports that were generated before the observer was able to be created should be observable (true) or not (false).

Examples

Display specific report types

This code shows how to create a ReportingObserver that could be used to observe deprecation and integrity-violation reports.

const options = {
  types: ["deprecation", "integrity-violation"],
  buffered: true,
};

const observer = new ReportingObserver((reports, observer) => {
  reportBtn.onclick = () => displayReports(reports);
}, options);

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。