From 4574555c8c26c16a4f785a82a5998ef27ee309e1 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Mon, 3 Jun 2024 11:36:52 +0200 Subject: [PATCH] fix: check for H5 --- src/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index fcac6ce..7125833 100644 --- a/src/index.js +++ b/src/index.js @@ -110,8 +110,13 @@ function trackCheckpoint(checkpoint, data, t) { const sendPing = (pdata = data) => { // eslint-disable-next-line object-curly-newline, max-len const body = JSON.stringify({ weight, id, sanitizeURL: urlSanitizers[window.hlx.RUM_MASK_URL || 'path'], checkpoint, t, ...data }, KNOWN_PROPERTIES); - const url = new URL(`.rum/${weight}`, sampleRUM.collectBaseURL || sampleRUM.baseURL).href; - navigator.sendBeacon(url, body); + const { href: url, origin} = new URL(`.rum/${weight}`, sampleRUM.collectBaseURL || sampleRUM.baseURL); + if (window.location.origin === origin) { + const headers = { type: 'application/json' }; + navigator.sendBeacon(url, new Blob([body], headers)); + } else { + navigator.sendBeacon(url, body); + } // eslint-disable-next-line no-console console.debug(`ping:${checkpoint}`, pdata); };