denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.26k stars 5.41k forks source link

Interest in Adding Support for "navigator.sendBeacon"? #14307

Open Grunet opened 2 years ago

Grunet commented 2 years ago

I was following up on trying to use OpenTelemetry-JS in Deno (after my earlier efforts here) this time trying to export trace data out of Deno and to an OTEL collector.

The main issue I ran into this time was that the browser version of the exporter relies on either navigator.sendBeacon or XmlHttpRequest to do the exporting, neither of which are currently available in Deno.

I was able to put together this small userland polyfill of navigator.sendBeacon based on this comment from MDN about the "keepalive" option for fetch, which seemed to do the trick as far as my OTEL-JS experiment goes. However I'm not sure if its description there as a "drop-in replacement for navigator.sendBeacon" also applies in Deno.

I remember seeing elsewhere XmlHttpRequest won't be supported in core, but I was curious if the same would apply to navigator.sendBeacon? I'm not quite sure what the direction is around navigator APIs, as I see there seem to only be 2 supported at the moment (?) so I figured it couldn't hurt to ask.

petamoriken commented 3 months ago

As an alternative, fetchLater is proposed. https://github.com/whatwg/fetch/pull/1647