InterventionReportBody: toJSON() 方法

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

注意:此功能在 Web Workers 中可用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

InterventionReportBody 接口的 toJSON() 方法是一个序列化器,它返回 InterventionReportBody 对象的 JSON 表示形式。

语法

js
toJSON()

参数

无。

返回值

一个 JSON 对象,它是 InterventionReportBody 对象的序列化结果。

示例

在此示例中,我们创建一个新的 ReportingObserver 来观察干预报告,然后返回第一个条目的 JSON 表示形式。

js
const options = {
  types: ["intervention"],
  buffered: true,
};

const observer = new ReportingObserver((reports, observer) => {
  const firstReport = reports[0];
  console.log(firstReport.toJSON());
}, options);

规范

规范
干预报告
# dom-interventionreportbody-tojson

浏览器兼容性