From 2026467f1ecf94f4333e995c3c33691da601bbb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20G=C3=BCnter?= Date: Fri, 8 Dec 2023 12:02:12 -0500 Subject: [PATCH] Remove XDEBUG_SESSION cookie while performing XHRs --- Resources/views/Profiler/toolbar_js.html.twig | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Resources/views/Profiler/toolbar_js.html.twig b/Resources/views/Profiler/toolbar_js.html.twig index 90f254c1..0ffc91f6 100644 --- a/Resources/views/Profiler/toolbar_js.html.twig +++ b/Resources/views/Profiler/toolbar_js.html.twig @@ -77,7 +77,34 @@ }); } + const setCookie = function (name, value, days) { + var exp = new Date(); + exp.setTime(exp.getTime() + (days * 24 * 60 * 60 * 1000)); + document.cookie = name + '=' + value + '; expires=' + exp.toGMTString() + '; path=/; SameSite=Lax'; + }; + + const getCookie = function (name) { + var prefix = name + '='; + var cookieStartIndex = document.cookie.indexOf(prefix); + var cookieEndIndex; + + if (cookieStartIndex == -1) { + return null; + } + + cookieEndIndex = document.cookie.indexOf(';', cookieStartIndex + prefix.length); + if (cookieEndIndex == -1) { + cookieEndIndex = document.cookie.length; + } + + return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)); + }; + var request = function(url, onSuccess, onError, payload, options, tries) { + if (xdebugCookieValue !== null) { + setCookie('XDEBUG_SESSION', xdebugCookieValue, 365); + } + var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); options = options || {}; options.retry = options.retry || false; @@ -114,6 +141,11 @@ options.onSend(tries); } + var xdebugCookieValue = getCookie('XDEBUG_SESSION'); + if (xdebugCookieValue !== null) { + setCookie('XDEBUG_SESSION', null, -1); + } + xhr.send(payload || ''); };