The problem was the only headline you could set with navigator.sendBeacon is Content-Type, and you set it by setting type in the Blob option. The server route had to be changed to satisfy the request without an authorization header (I passed it as a URL parameter instead - strange for a POST request, but apparently the only way to do this with a beacon). Here's what it looked like at the end:
$(global).bind('unload', function () { if(appState.jobId == null) return; let headers = { type: 'application/json' }; let jobEventLoggingBody = { UserEmail: appState.user.email, Job: { Id: appState.jobId }, Timestamp: '/Date(' + new Date().getTime() + ')/', EventOrigin: 'PdfReviewClient', Event: 'JobClosed' }; let jobEventLoggingUrl = `${configuration.rootApiUrl}jobevents?jwt=${authenticationState.token}`; let jobEventLoggingBlob = new Blob([JSON.stringify(jobEventLoggingBody)], headers); navigator.sendBeacon(jobEventLoggingUrl, jobEventLoggingBlob); });
See also this question , which specifically relates to the sending of headers in beacons.
source share