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

CrashReport

· 52CE 我爱测

The `CrashReport` dictionary of the Reporting API represents a crash report.

Reporting API

The CrashReport dictionary of the Reporting API represents a crash report.

[!NOTE] It is not possible to retrieve crash reports using a ReportingObserver — the reports are only generated when the browser crashes, at which point the observer code isn't available to run.

Instance properties

  • age
    • : The age of the report in milliseconds.
  • type
    • : The string "crash" indicating that this is a crash report.
  • url
    • : A string representing the URL of the document that generated the report.
  • user_agent
    • : The user agent string of the browser that generated the report.
  • body
    • : The body of the report. This is an object with the following properties:
      • crash_report_api
        • : An object containing the key-value pairs set via the CrashReportContext.set() method, if any.
      • is_top_level
        • : A boolean indicating whether the crashed document was a top-level document (true) or an embedded document (false).
      • reason
        • : A string indicating the specific reason why the crash occurred, if known. Possible values are:
          • oom
            • : The page ran out of memory.
          • unresponsive
            • : The page was killed due to being unresponsive.
      • stack
        • : A string representing the JavaScript call stack at the time of the crash. This is included if the reason is unresponsive, if the Document-Policy value for include-js-call-stacks-in-crash-reports in the document that crashed is true, and if the call stack was able to be recovered from the crashed document.
      • visibility_state
        • : An enumerated value indicating whether the document is visible. This mirrors the value of the Document.visibilityState property. Possible values are:
          • visible
            • : The document content is at least partially visible.
          • hidden
            • : The document content is completely hidden.

Description

Crash reports containing arbitrary information can be sent to a server endpoint using the Reporting API . This is useful because we can store detailed diagnostic information throughout the lifetime of an application and use the reports to debug crashes more effectively.

The diagnostic information is stored in a special key-value store that can be manipulated using the document's CrashReportContext object. This is accessed via the Window.crashReport property.

When the browser crashes, the information stored in the key-value store is added to a CrashReport and sent to a reporting server. The reporting server endpoint and its mapping to a particular URL are set using the Reporting-Endpoints header.

  • If a crash-reporting server endpoint is defined, crash reports are delivered there. For example:
    Reporting-Endpoints: crash-reporting="https://example.com/reports"
    
  • If a crash-reporting endpoint is not defined, but a default reporting server endpoint is defined, crash reports are delivered there. For example:
    Reporting-Endpoints: default="https://example.com/reports"
    
  • If neither endpoint is defined, crash reports are not delivered.

Examples

Sending a report to a reporting endpoint

Configuring a web page to send a crash report requires that you define a reporting server endpoint using the Reporting-Endpoints header, for example https://example.com/reports, as described earlier.

A typical report structure is as follows:

{
  "age": 27,
  "type": "crash",
  "url": "https://example.com/",
  "user_agent": "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0",
  "body": {
    "sourceFile": "https://example.com/",
    "reason": "unresponsive",
    "stack": "SomeError: ... at ...",
    "is_top_level": true,
    "visibility_state": "visible",
    "crash_report_api": {
      "crash_data_1": "0001",
      "crash_data_2": "0002"
    }
  }
}

The report will be sent as a JSON object in a POST request to the endpoint whenever the browser crashes.

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

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

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