|
230 | 230 | }
|
231 | 231 |
|
232 | 232 | {% if excluded_ajax_paths is defined %}
|
233 |
| - if (window.fetch && window.fetch.polyfill === undefined) { |
234 |
| - var oldFetch = window.fetch; |
235 |
| - window.fetch = function () { |
236 |
| - var promise = oldFetch.apply(this, arguments); |
237 |
| - if (!arguments[0].match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) { |
238 |
| - var method = 'GET'; |
239 |
| - if (arguments[1] && arguments[1].method !== undefined) { |
240 |
| - method = arguments[1].method; |
241 |
| - } |
242 |
| -
|
243 |
| - var stackElement = { |
244 |
| - error: false, |
245 |
| - url: arguments[0], |
246 |
| - method: method, |
247 |
| - type: 'fetch', |
248 |
| - start: new Date() |
249 |
| - }; |
250 |
| -
|
251 |
| - var idx = requestStack.push(stackElement) - 1; |
252 |
| - promise.then(function (r) { |
253 |
| - stackElement.duration = new Date() - stackElement.start; |
254 |
| - stackElement.error = r.status < 200 || r.status >= 400; |
255 |
| - stackElement.statusCode = r.status; |
256 |
| - stackElement.profile = r.headers.get('x-debug-token'); |
257 |
| - stackElement.profilerUrl = r.headers.get('x-debug-token-link'); |
258 |
| - finishAjaxRequest(idx); |
259 |
| - }, function (e){ |
260 |
| - stackElement.error = true; |
261 |
| - }); |
262 |
| - startAjaxRequest(idx); |
263 |
| - } |
264 |
| -
|
265 |
| - return promise; |
266 |
| - }; |
267 |
| - } |
268 |
| - if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) { |
269 |
| - var proxied = XMLHttpRequest.prototype.open; |
| 233 | + if (window.fetch && window.fetch.polyfill === undefined) { |
| 234 | + var oldFetch = window.fetch; |
| 235 | + window.fetch = function () { |
| 236 | + var promise = oldFetch.apply(this, arguments); |
| 237 | + if (!arguments[0].match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) { |
| 238 | + var method = 'GET'; |
| 239 | + if (arguments[1] && arguments[1].method !== undefined) { |
| 240 | + method = arguments[1].method; |
| 241 | + } |
270 | 242 |
|
271 |
| - XMLHttpRequest.prototype.open = function(method, url, async, user, pass) { |
272 |
| - var self = this; |
| 243 | + var stackElement = { |
| 244 | + error: false, |
| 245 | + url: arguments[0], |
| 246 | + method: method, |
| 247 | + type: 'fetch', |
| 248 | + start: new Date() |
| 249 | + }; |
273 | 250 |
|
274 |
| - /* prevent logging AJAX calls to static and inline files, like templates */ |
275 |
| - var path = url; |
276 |
| - if (url.substr(0, 1) === '/') { |
277 |
| - if (0 === url.indexOf('{{ request.basePath|e('js') }}')) { |
278 |
| - path = url.substr({{ request.basePath|length }}); |
| 251 | + var idx = requestStack.push(stackElement) - 1; |
| 252 | + promise.then(function (r) { |
| 253 | + stackElement.duration = new Date() - stackElement.start; |
| 254 | + stackElement.error = r.status < 200 || r.status >= 400; |
| 255 | + stackElement.statusCode = r.status; |
| 256 | + stackElement.profile = r.headers.get('x-debug-token'); |
| 257 | + stackElement.profilerUrl = r.headers.get('x-debug-token-link'); |
| 258 | + finishAjaxRequest(idx); |
| 259 | + }, function (e){ |
| 260 | + stackElement.error = true; |
| 261 | + }); |
| 262 | + startAjaxRequest(idx); |
279 | 263 | }
|
280 |
| - } |
281 |
| - else if (0 === url.indexOf('{{ (request.schemeAndHttpHost ~ request.basePath)|e('js') }}')) { |
282 |
| - path = url.substr({{ (request.schemeAndHttpHost ~ request.basePath)|length }}); |
283 |
| - } |
284 | 264 |
|
285 |
| - if (!path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) { |
286 |
| - var stackElement = { |
287 |
| - error: false, |
288 |
| - url: url, |
289 |
| - method: method, |
290 |
| - type: 'xhr', |
291 |
| - start: new Date() |
292 |
| - }; |
293 |
| -
|
294 |
| - var idx = requestStack.push(stackElement) - 1; |
| 265 | + return promise; |
| 266 | + }; |
| 267 | + } |
| 268 | + if (window.XMLHttpRequest && XMLHttpRequest.prototype.addEventListener) { |
| 269 | + var proxied = XMLHttpRequest.prototype.open; |
295 | 270 |
|
296 |
| - this.addEventListener('readystatechange', function() { |
297 |
| - if (self.readyState == 4) { |
298 |
| - stackElement.duration = new Date() - stackElement.start; |
299 |
| - stackElement.error = self.status < 200 || self.status >= 400; |
300 |
| - stackElement.statusCode = self.status; |
301 |
| - extractHeaders(self, stackElement); |
| 271 | + XMLHttpRequest.prototype.open = function(method, url, async, user, pass) { |
| 272 | + var self = this; |
302 | 273 |
|
303 |
| - finishAjaxRequest(idx); |
| 274 | + /* prevent logging AJAX calls to static and inline files, like templates */ |
| 275 | + var path = url; |
| 276 | + if (url.substr(0, 1) === '/') { |
| 277 | + if (0 === url.indexOf('{{ request.basePath|e('js') }}')) { |
| 278 | + path = url.substr({{ request.basePath|length }}); |
304 | 279 | }
|
305 |
| - }, false); |
| 280 | + } |
| 281 | + else if (0 === url.indexOf('{{ (request.schemeAndHttpHost ~ request.basePath)|e('js') }}')) { |
| 282 | + path = url.substr({{ (request.schemeAndHttpHost ~ request.basePath)|length }}); |
| 283 | + } |
306 | 284 |
|
307 |
| - startAjaxRequest(idx); |
308 |
| - } |
| 285 | + if (!path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) { |
| 286 | + var stackElement = { |
| 287 | + error: false, |
| 288 | + url: url, |
| 289 | + method: method, |
| 290 | + type: 'xhr', |
| 291 | + start: new Date() |
| 292 | + }; |
| 293 | +
|
| 294 | + var idx = requestStack.push(stackElement) - 1; |
| 295 | +
|
| 296 | + this.addEventListener('readystatechange', function() { |
| 297 | + if (self.readyState == 4) { |
| 298 | + stackElement.duration = new Date() - stackElement.start; |
| 299 | + stackElement.error = self.status < 200 || self.status >= 400; |
| 300 | + stackElement.statusCode = self.status; |
| 301 | + extractHeaders(self, stackElement); |
| 302 | +
|
| 303 | + finishAjaxRequest(idx); |
| 304 | + } |
| 305 | + }, false); |
309 | 306 |
|
310 |
| - proxied.apply(this, Array.prototype.slice.call(arguments)); |
311 |
| - }; |
312 |
| - } |
| 307 | + startAjaxRequest(idx); |
| 308 | + } |
| 309 | +
|
| 310 | + proxied.apply(this, Array.prototype.slice.call(arguments)); |
| 311 | + }; |
| 312 | + } |
313 | 313 | {% endif %}
|
314 | 314 |
|
315 | 315 | return {
|
|
0 commit comments