From 8fcdc404ca080f383b6d7c5007ee0e38f34ca602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pudil?= Date: Mon, 27 Feb 2017 13:05:01 +0100 Subject: [PATCH] AJAX: debug Fetch requests (#249) --- src/Tracy/assets/Bar/bar.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Tracy/assets/Bar/bar.js b/src/Tracy/assets/Bar/bar.js index 6cdb17845..17f088465 100755 --- a/src/Tracy/assets/Bar/bar.js +++ b/src/Tracy/assets/Bar/bar.js @@ -395,6 +395,30 @@ }); } }; + + if (window.fetch) { + var oldFetch = window.fetch; + window.fetch = function(request, options) { + options = options || {}; + options.headers = new Headers(options.headers || {}); + var url = request instanceof Request ? request.url : request; + + if (window.TracyAutoRefresh !== false && url.indexOf('//') <= 0 || url.indexOf(location.origin + '/') === 0) { + options.headers.set('X-Tracy-Ajax', header); + options.credentials = (request instanceof Request && request.credentials) || options.credentials || 'same-origin'; + + return oldFetch(request, options).then(function (response) { + if (response.headers.has('X-Tracy-Ajax') && response.headers.get('X-Tracy-Ajax')[0] === '1') { + Debug.loadScript('?_tracy_bar=content-ajax.' + header + '&XDEBUG_SESSION_STOP=1&v=' + Math.random()); + } + + return response; + }); + } + + return oldFetch(request, options); + }; + } }; Debug.loadScript = function(url) {