We are getting thousands of "TypeError: Load failed" errors in Sentry and this appears to be because PostHog has a request in flight while we are redirecting the user to an external URL.
From my understanding, XMLHttpRequest does not have a mechanism like keepalive that will not cancel the request when the page is unloaded.
Fetch is available on every major supported browser. Could fetch be made the default? If not, could an option be provided to make it the default for our instance?
Alternatively, it could be helpful to have a method that returns a promise that resolves when all the pending events have been sent so we can block the redirect on that request, but that seems unnecessary with keepalive.
We are getting thousands of "TypeError: Load failed" errors in Sentry and this appears to be because PostHog has a request in flight while we are redirecting the user to an external URL.
It looks like this is because XMLHttpRequest is preferred over fetch. https://github.com/PostHog/posthog-js/blob/38744a512abef2f4eb7327e7a3c23d184c3993ca/src/request.ts#L202-L216
Indeed,
XHR
is the default transport: https://github.com/PostHog/posthog-js/blob/38744a512abef2f4eb7327e7a3c23d184c3993ca/src/request.ts#L237From my understanding, XMLHttpRequest does not have a mechanism like keepalive that will not cancel the request when the page is unloaded.
Fetch is available on every major supported browser. Could
fetch
be made the default? If not, could an option be provided to make it the default for our instance?Alternatively, it could be helpful to have a method that returns a promise that resolves when all the pending events have been sent so we can block the redirect on that request, but that seems unnecessary with keepalive.