feat(app.js): Ajoute détection User-Agent test et masque bannières pour PageSpeed.

This commit is contained in:
Serreau Jovann
2025-11-21 21:51:55 +01:00
parent 6e1a97fb69
commit dd26699cc7

View File

@@ -251,12 +251,33 @@ async function promptForPermissionAndSubscribe() {
}
}
// ====================================================================
// --- NOUVELLE FONCTION DE DÉTECTION POUR PAGESPEED/LIGHTHOUSE ---
// ====================================================================
/**
* Vérifie si le script est exécuté par un User Agent de test (e.g., Lighthouse/PageSpeed)
* @returns {boolean} True si c'est un User Agent de test.
*/
function isPerformanceTestAgent() {
const ua = navigator.userAgent;
// Vérifie les User Agents connus des outils de performance
return ua.includes('Lighthouse') || ua.includes('Chrome-Lighthouse') || ua.includes('PageSpeed');
}
/**
* Affiche une petite carte de notification push temporaire en bas à gauche.
* N'affiche QUE si la permission n'est PAS accordée.
*/
function handleNotificationBanner() {
// 0. MASQUAGE POUR PAGESPEED
if (isPerformanceTestAgent()) {
console.log("Notification Banner skipped for performance test agent.");
return;
}
// --- FIN MASQUAGE ---
const BANNER_ID = 'notification-prompt-banner';
const DURATION_MS = 15000; // 15 secondes d'affichage
const M = getLanguageMessages(); // Récupère les messages traduits
@@ -345,6 +366,13 @@ function handleNotificationBanner() {
* Affiche le bandeau de consentement aux cookies en bas à droite s'il n'a jamais été accepté.
*/
function handleCookieBanner() {
// 0. MASQUAGE POUR PAGESPEED
if (isPerformanceTestAgent()) {
console.log("Cookie Banner skipped for performance test agent.");
return;
}
// --- FIN MASQUAGE ---
const BANNER_ID = 'cookie-banner';
const M = getLanguageMessages(); // Récupère les messages traduits
@@ -454,7 +482,11 @@ document.addEventListener('DOMContentLoaded', ()=>{
// Tracing
tracesSampleRate: 1.0, // Capture 100% of the transactions
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
// Remplacez l'ancienne valeur par celle-ci dans Sentry.init()
tracePropagationTargets: [
"localhost",
/^https:\/\/www\.e-cosplay\.fr/
],
// Session Replay
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
replaysOnErrorSampleRate: 1.0 // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.