Skip to content

Commit

Permalink
AJAX: debug Fetch requests (nette#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripudil authored and dg committed Feb 27, 2017
1 parent cdd9777 commit 8fcdc40
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Tracy/assets/Bar/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8fcdc40

Please sign in to comment.