From af9225de57970be43d170fdfbec1560476226dc5 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Tue, 9 Aug 2016 12:35:04 +0200 Subject: [PATCH 1/4] added support for window.fetch calls in ajax section --- .../views/Profiler/base_js.html.twig | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig index b1a19f0ea1924..8e1e1aaf1a5ff 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig @@ -236,6 +236,31 @@ {% if excluded_ajax_paths is defined %} if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) { + if (window.fetch) { + var oldFetch = window.fetch; + window.fetch = function () { + var promise = oldFetch.apply(null, arguments); + var stackElement = { + loading: true, + error: false, + url: arguments[0], + method: arguments[1].method, + start: new Date() + }; + requestStack.push(stackElement); + promise.then(function (r) { + stackElement.duration = new Date() - stackElement.start; + stackElement.loading = false; + stackElement.error = r.status < 200 || r.status >= 400; + stackElement.statusCode = r.status; + stackElement.profile = r.headers.get('x-debug-token'); + stackElement.profilerUrl = r.headers.get('x-debug-token-link'); + Sfjs.renderAjaxRequests(); + }); + Sfjs.renderAjaxRequests(); + return promise; + }; + } var proxied = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, url, async, user, pass) { From e080ca16dbe8b7309b5069d9a4a11a5461114760 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Wed, 24 Aug 2016 10:39:39 +0200 Subject: [PATCH 2/4] applied suggested fixes: added error handling on promise catch, moved fetch block out of XHR block, fixed method detect, matched url against excluded urls --- .../views/Profiler/base_js.html.twig | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig index 8e1e1aaf1a5ff..b091bd5590b9c 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig @@ -235,18 +235,25 @@ } {% if excluded_ajax_paths is defined %} - if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) { - if (window.fetch) { - var oldFetch = window.fetch; - window.fetch = function () { - var promise = oldFetch.apply(null, arguments); + + if (window.fetch) { + var oldFetch = window.fetch; + window.fetch = function () { + var promise = oldFetch.apply(null, arguments); + if (!arguments[0].match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) { + var method = 'GET'; + if (arguments[1] && arguments[1].method !== undefined) { + method = arguments[1].method; + } + var stackElement = { loading: true, error: false, url: arguments[0], - method: arguments[1].method, + method: method, start: new Date() }; + requestStack.push(stackElement); promise.then(function (r) { stackElement.duration = new Date() - stackElement.start; @@ -256,11 +263,17 @@ stackElement.profile = r.headers.get('x-debug-token'); stackElement.profilerUrl = r.headers.get('x-debug-token-link'); Sfjs.renderAjaxRequests(); + }).catch(function(err) { + stackElement.loading = false; + stackElement.error = true; }); Sfjs.renderAjaxRequests(); - return promise; - }; - } + } + + return promise; + }; + } + if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) { var proxied = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, url, async, user, pass) { From 36cad1e75b8fdf9efdd7d8e71d1019fbb625a502 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Wed, 5 Oct 2016 10:23:05 +0200 Subject: [PATCH 3/4] added type to profiler table, use 2nd argument instead of catch, using fetch signature instead of arguments --- .../Resources/views/Collector/ajax.html.twig | 1 + .../Resources/views/Profiler/base_js.html.twig | 10 ++++++++-- .../Resources/views/Profiler/toolbar.css.twig | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/ajax.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/ajax.html.twig index 8734fa8809d2f..fce25a7f26e1c 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/ajax.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/ajax.html.twig @@ -15,6 +15,7 @@ Method + Type Status URL Time diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig index b091bd5590b9c..109866841b8f6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig @@ -124,6 +124,10 @@ methodCell.textContent = request.method; row.appendChild(methodCell); + var typeCell = document.createElement('td'); + typeCell.textContent = request.type; + row.appendChild(typeCell); + var statusCodeCell = document.createElement('td'); var statusCode = document.createElement('span'); if (request.statusCode < 300) { @@ -239,7 +243,7 @@ if (window.fetch) { var oldFetch = window.fetch; window.fetch = function () { - var promise = oldFetch.apply(null, arguments); + var promise = oldFetch.apply(this, arguments); if (!arguments[0].match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) { var method = 'GET'; if (arguments[1] && arguments[1].method !== undefined) { @@ -251,6 +255,7 @@ error: false, url: arguments[0], method: method, + type: 'fetch', start: new Date() }; @@ -263,7 +268,7 @@ stackElement.profile = r.headers.get('x-debug-token'); stackElement.profilerUrl = r.headers.get('x-debug-token-link'); Sfjs.renderAjaxRequests(); - }).catch(function(err) { + }, function (e){ stackElement.loading = false; stackElement.error = true; }); @@ -296,6 +301,7 @@ error: false, url: url, method: method, + type: 'xhr', start: new Date() }; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig index 87827fa7ba903..5bf85d4e946fc 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig @@ -334,7 +334,7 @@ padding: 4px; } .sf-ajax-request-url { - max-width: 300px; + max-width: 250px; line-height: 9px; overflow: hidden; text-overflow: ellipsis; From 385279c29b5a3ef2f58e468a8e9e7885a9f2eb42 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Wed, 5 Oct 2016 17:16:37 +0200 Subject: [PATCH 4/4] fixed polyfill detect --- .../Resources/views/Profiler/base_js.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig index 109866841b8f6..9fffeb0782444 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig @@ -240,7 +240,7 @@ {% if excluded_ajax_paths is defined %} - if (window.fetch) { + if (window.fetch && window.fetch.polyfill === undefined) { var oldFetch = window.fetch; window.fetch = function () { var promise = oldFetch.apply(this, arguments);