Open scottpledger opened 1 year ago
https://github.com/WICG/pending-beacon may be what you're looking for.
It's similar, but not quite the same. By building on the infrastructure that clients need to set up in order to enable handling of other types of reports via the Reporting API, clients can handle these as they would any other type of report (eg, using url endpoints or a ReportingObserver).
Is there anything preventing you from building a payload that looks like a Report, and sending it to the Reporting API end point using fetch()
?
Is there anything preventing you from building a payload that looks like a Report, and sending it to the Reporting API end point using
fetch()
?
No, but such a solution has a number of drawbacks compared to the Reporting API, namely:
By building this functionality into the proposed Reporting API, sites can have much cleaner and more consistent reporting functionality with less overhead. This is a massive win for developers and I firmly believe it would significantly improve the adoptability of this API overall.
Allowing individual execution contexts to construct and send their own reports would allow this API to provide a single, consistent approach for the reporting of important client-side information such as unhandled errors, timing metrics, and usage information.
One API I have in mind for this is loosely based on the Performance API and goes something like:
An execution context may then initialize a new report as:
All custom reports' types would be prefixed with
'custom-'
so that they are clearly differentiated from browser-native events. IndividualReporter
instances provide additional details about the context of a report.The "body" of these reports would include a "detail" entry containing the "detail" value from the report as well as a "reporter" entry which contains values from the ReporterOptions of the
Reporter
instance that constructed the report, if any.