ReportBody: toJSON() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Note: This feature is available in Web Workers.
The toJSON()
method of the ReportBody
interface is a serializer, and returns a JSON representation of the ReportBody
object.
Syntax
js
toJSON()
Parameters
None.
Return value
A JSON object that is the serialization of the ReportBody
object.
Examples
In this example we create a new ReportingObserver
to observe intervention reports, then return a JSON representation of the first entry. The report, and therefore the JSON object returned will be an instance of InterventionReportBody
which inherits from ReportBody
.
js
const options = {
types: ["intervention"],
buffered: true,
};
const observer = new ReportingObserver(([firstReport], observer) => {
console.log(firstReport.toJSON());
}, options);
Specifications
Specification |
---|
Reporting API # dom-reportbody-tojson |
Browser compatibility
BCD tables only load in the browser