From 579c4524926d3f79165d71d7b1c567e065c91286 Mon Sep 17 00:00:00 2001 From: Amir Hosseini <19665344+itsamirhn@users.noreply.github.com> Date: Tue, 11 Feb 2025 12:18:53 +0330 Subject: [PATCH] chore: Update GoatCounter counter.js file --- static/js/count.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/static/js/count.js b/static/js/count.js index 7c504bc0..8798d119 100644 --- a/static/js/count.js +++ b/static/js/count.js @@ -1,6 +1,5 @@ // GoatCounter: https://www.goatcounter.com -// This file (and *only* this file) is released under the ISC license: -// https://opensource.org/licenses/ISC +// This file (and *only* this file) is released under the ISC license: https://opensource.org/licenses/ISC ;(function() { 'use strict'; @@ -145,24 +144,27 @@ var f = goatcounter.filter() if (f) return warn('not counting because of: ' + f) - var url = goatcounter.url(vars) if (!url) return warn('not counting because path callback returned null') - var img = document.createElement('img') - img.src = url - img.style.position = 'absolute' // Affect layout less. - img.style.bottom = '0px' - img.style.width = '1px' - img.style.height = '1px' - img.loading = 'eager' - img.setAttribute('alt', '') - img.setAttribute('aria-hidden', 'true') - - var rm = function() { if (img && img.parentNode) img.parentNode.removeChild(img) } - img.addEventListener('load', rm, false) - document.body.appendChild(img) + if (!navigator.sendBeacon(url)) { + // This mostly fails due to being blocked by CSP; try again with an + // image-based fallback. + var img = document.createElement('img') + img.src = url + img.style.position = 'absolute' // Affect layout less. + img.style.bottom = '0px' + img.style.width = '1px' + img.style.height = '1px' + img.loading = 'eager' + img.setAttribute('alt', '') + img.setAttribute('aria-hidden', 'true') + + var rm = function() { if (img && img.parentNode) img.parentNode.removeChild(img) } + img.addEventListener('load', rm, false) + document.body.appendChild(img) + } } // Get a query parameter. @@ -266,5 +268,4 @@ if (!goatcounter.no_events) goatcounter.bind_events() }) -})(); - +})(); \ No newline at end of file