in glean/src/platform/browser/sendbeacon_fallback_uploader.ts [22:46]
async post(
url: string,
pingRequest: PingRequest<string | Uint8Array>
): Promise<UploadResult> {
// Some options require us to submit custom headers. Unfortunately not all the
// uploaders support them (e.g. `sendBeacon`). In case headers are required, switch
// back to the `fetch` uploader that supports headers.
// Then try `sendBeacon` first,
// fall back to `fetch` if `sendBeacon` reports an error or `sendBeacon` is
// not defined.
const hasNoCustomHeaders = !Context.config?.sourceTags && !Context.config?.debugViewTag;
if (hasNoCustomHeaders && !!navigator && !!navigator.sendBeacon) {
const beaconStatus = await this.sendBeaconUploader.post(url, pingRequest, false);
if (beaconStatus.result == UploadResultStatus.Success) {
return beaconStatus;
}
log(LOG_TAG, "The `sendBeacon` call was not serviced by the browser. Falling back to the `fetch` uploader.", LoggingLevel.Warn);
} else {
log(LOG_TAG, "`sendBeacon` is not available. Falling back to the `fetch` uploader.", LoggingLevel.Warn);
}
return this.fetchUploader.post(url, pingRequest);
}