8000 [WebProfiler] added support for window.fetch calls in ajax section · ostrolucky/symfony@b1b4d70 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1b4d70

Browse files
ivobafabpot
authored andcommitted
[WebProfiler] added support for window.fetch calls in ajax section
1 parent 02f59fe commit b1b4d70

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/ajax.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<thead>
1616
<tr>
1717
<th>Method</th>
18+
<th>Type</th>
1819
<th>Status</th>
1920
<th>URL</th>
2021
<th>Time</th>

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 44 additions & 0 deletions
280
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@
124124
methodCell.textContent = request.method;
125125
row.appendChild(methodCell);
126126
127+
var typeCell = document.createElement('td');
128+
typeCell.textContent = request.type;
129+
row.appendChild(typeCell);
130+
127131
var statusCodeCell = document.createElement('td');
128132
var statusCode = document.createElement('span');
129133
if (request.statusCode < 300) {
@@ -235,6 +239,45 @@
235239
}
236240
237241
{% if excluded_ajax_paths is defined %}
242+
243+
if (window.fetch && window.fetch.polyfill === undefined) {
244+
var oldFetch = window.fetch;
245+
window.fetch = function () {
246+
var promise = oldFetch.apply(this, arguments);
247+
if (!arguments[0].match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {
248+
var method = 'GET';
249+
if (arguments[1] && arguments[1].method !== undefined) {
250+
method = arguments[1].method;
251+
}
252+
253+
var stackElement = {
254+
loading: true,
255+
error: false,
256+
url: arguments[0],
257+
method: method,
258+
type: 'fetch',
259+
start: new Date()
260+
};
261+
262+
requestStack.push(stackElement);
263+
promise.then(function (r) {
264+
stackElement.duration = new Date() - stackElement.start;
265+
stackElement.loading = false;
266+
stackElement.error = r.status < 200 || r.status >= 400;
267+
stackElement.statusCode = r.status;
268+
stackElement.profile = r.headers.get('x-debug-token');
269+
stackElement.profilerUrl = r.headers.get('x-debug-token-link');
270+
Sfjs.renderAjaxRequests();
271+
}, function (e){
272+
stackElement.loading = false;
273+
stackElement.error = true;
274+
});
275+
Sfjs.renderAjaxRequests();
276+
}
277+
278+
return promise;
279+
};
+
}
238281
if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) {
239282
var proxied = XMLHttpRequest.prototype.open;
240283
@@ -258,6 +301,7 @@
258301
error: false,
259302
url: url,
260303
method: method,
304+
type: 'xhr',
261305
start: new Date()
262306
};
263307

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
padding: 4px;
335335
}
336336
.sf-ajax-request-url {
337-
max-width: 300px;
337+
max-width: 250px;
338338
line-height: 9px;
339339
overflow: hidden;
340340
text-overflow: ellipsis;

0 commit comments

Comments
 (0)
0