ReportBody: toJSON()-Methode

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Hinweis: Diese Funktion ist in Web Workers verfügbar.

Die toJSON()-Methode der ReportBody-Schnittstelle ist ein Serializer und liefert eine JSON-Darstellung des ReportBody-Objekts zurück.

Syntax

js
toJSON()

Parameter

Keine.

Rückgabewert

Ein JSON-Objekt, das die Serialisierung des ReportBody-Objekts darstellt.

Beispiele

In diesem Beispiel erstellen wir einen neuen ReportingObserver, um Eingriffsberichte zu beobachten, und geben dann eine JSON-Darstellung des ersten Eintrags zurück. Der Bericht und somit das zurückgegebene JSON-Objekt wird eine Instanz von InterventionReportBody sein, die von ReportBody erbt.

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

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

Spezifikationen

Specification
Reporting API
# dom-reportbody-tojson

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
toJSON

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
User must explicitly enable this feature.