Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ce2b63

Browse filesBrowse files
committed
feature symfony#19576 [WebProfiler] added support for window.fetch calls in ajax section (ivoba)
This PR was squashed before being merged into the 3.2-dev branch (closes symfony#19576). Discussion ---------- [WebProfiler] added support for window.fetch calls in ajax section | Q | A | ------------- | --- | Branch? | "master" | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#17444 | License | MIT | Doc PR | reference to the documentation PR, if any This adds support for window.fetch calls to the Ajax section of the WebProfiler toolbar. Credits to @tbopec for implementation :) Commits ------- b1b4d70 [WebProfiler] added support for window.fetch calls in ajax section
2 parents 8d7d903 + cda3bf0 commit 0ce2b63
Copy full SHA for 0ce2b63

File tree

Expand file treeCollapse file tree

3 files changed

+46
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+46
-1
lines changed

‎Resources/views/Collector/ajax.html.twig

Copy file name to clipboardExpand all lines: Resources/views/Collector/ajax.html.twig
+1Lines 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>

‎Resources/views/Profiler/base_js.html.twig

Copy file name to clipboardExpand all lines: Resources/views/Profiler/base_js.html.twig
+44Lines changed: 44 additions & 0 deletions
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+
};
280+
}
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

‎Resources/views/Profiler/toolbar.css.twig

Copy file name to clipboardExpand all lines: Resources/views/Profiler/toolbar.css.twig
+1-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.