Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[WebProfiler] added support for window.fetch calls in ajax section#19576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
fabpot commentedAug 15, 2016
@javiereguiluz Can you validate this one? |
fabpot commentedAug 15, 2016
@robfrawley Can you test it? |
nicolas-grekas commentedAug 23, 2016
Could anyone please test this one? |
| 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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Is this compatible with CORS restriction or will it log a security warning ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@romainneutron any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm gonna try this PR
stof commentedAug 23, 2016
Status: needs work |
ivoba commentedAug 24, 2016
Applied fixes for@stof `s comments. |
| @@ -1,4 +1,4 @@ | |||
| <script{%ifcsp_script_nonceisdefinedandcsp_script_nonce %}nonce={{csp_script_nonce }}{%endif %}>/*<![CDATA[*/ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This removal must be reverted. You are breaking the CSP compatibility
stof commentedAug 24, 2016
I will review again when the indentation changes are reverted. They make it very hard to see what actually changed (and if I ignored the whitespace changes, I cannot comment on the diff anymore, which is not convenient) |
ivoba commentedAug 24, 2016
oops how did that happen? |
ivoba commentedAug 24, 2016
@stof done, sorryy |
| var promise=oldFetch.apply(null,arguments); | ||
| var method='GET'; | ||
| if(arguments[1].method!==undefined){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@ivoba Theinit config object is optional (Promise<Response> fetch(input[, init]);) therefore this can throw an error. First check if the 2nd argument even existsarguments[1] && arguments[1].method !== undefined .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@tsm91 correct. i fixed this.
| } | ||
| {%if excluded_ajax_paths is defined%} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
extra blank line here
| var oldFetch=window.fetch; | ||
| window.fetch=function () { | ||
| if (!arguments[0].match(newRegExp({{ excluded_ajax_paths|json_encode|raw }}))) { | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
extra blank line here
| var method='GET'; | ||
| if(arguments[1]&&arguments[1].method!==undefined){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
missing space afterif and before{
RolfBabijn commentedSep 27, 2016
Really looking forward to this fix/feature. Is there any way I can assist? |
| var oldFetch=window.fetch; | ||
| window.fetch=function () { | ||
| if (!arguments[0].match(newRegExp({{ excluded_ajax_paths|json_encode|raw }}))) { | ||
| var promise=oldFetch.apply(null,arguments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this call must be done outside the URL profiling blacklist check (and the return at the end too). Otherwise, you break fetch entirely for URLs blacklisted by the AJAX profiling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@stof fixed
added error handling on promise catch,moved fetch block out of XHR block,fixed method detect,matched url against excluded urls
| if (window.fetch) { | ||
| var oldFetch=window.fetch; | ||
| window.fetch=function () { | ||
| var promise=oldFetch.apply(null,arguments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
oldFetch.apply(window, arguments);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
even better:.apply(this, arguments), keeping the same context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed using@stof 's approach
| stackElement.profile=r.headers.get('x-debug-token'); | ||
| stackElement.profilerUrl=r.headers.get('x-debug-token-link'); | ||
| Sfjs.renderAjaxRequests(); | ||
| }).catch(function(err) { |
romainneutronSep 30, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
it's better to use the second argument ofthen instead of usingcatch: if an error is thrown bySfjs.renderAjaxRequests, the request would be tagged as erroneous whereas the error came from the code executed after that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
| }).catch(function(err) { | ||
| stackElement.loading=false; | ||
| stackElement.error=true; | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
what about adding the error content as a property and display this error in the toolbar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
its a good idea, but maybe we can put this in another PR since its also not implemented for XHR, afaik, and it would need some more adjustments in how we render the table.
| if (window.fetch) { | ||
| var oldFetch=window.fetch; | ||
| window.fetch=function () { | ||
| var promise=oldFetch.apply(null,arguments); |
romainneutronSep 30, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Works perfectly, no security error, even incors mode
| Sfjs.renderAjaxRequests(); | ||
| }).catch(function(err) { | ||
| stackElement.loading=false; | ||
| stackElement.error=true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
what about adding atype so we could make distinction betweenajax (xhr) andfetch in the toolbar. As they do not behave the same way, it may be useful, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
yeah was thinking about that too, but was bit afraid of the extra effort. i see what i can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
well, the extra work is mainly about figuring out the display. Adding the type property is not hard (it should just be done in both place initializing a stackElement)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
i added type to stackElement and to display
| if (window.fetch) { | ||
| var oldFetch=window.fetch; | ||
| window.fetch=function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
what about usingfetch signature (fetch(url, options):promise) instead of relying on arguments? I think it's easier to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
absolutly, fixed
| {%if excluded_ajax_paths is defined%} | ||
| if (window.fetch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should we try to detect native fetch here ? If someone uses a fetch polyfill based on XHR (e.g. the polyfill maintained by github), we would register the request twice otherwise (at the fetch level and at the xhr level)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
how would you detect this? just check if the browser supports fetch? this needs to happen before any ployfill is loaded, im not sure how to do this.
also as the profiler is a dev tool, how many people develop on outdated browsers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
the polyfill defines awindow.fetch.polyfill property (set to true) to allow to identify itself.
And people are expected to try their site in old browsers from time to time if they support them. Having your dev tools working to debug errors is a good idea there. The Symfony debug toolbar is meant to work in old browsers, even if it is less fancy (as it is embed in the page itself). The profiler does not support them, but you can always open it in a modern browser in parallel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ok i see, i added a check on polyfillif (window.fetch && window.fetch.polyfill === undefined)
HeahDude commentedOct 1, 2016
@ivoba Do you need help with the templates so you can finish this feature for 3.2? :) |
…g fetch signature instead of arguments
fabpot commentedOct 5, 2016
Thank you@ivoba. |
…lls in ajax section (ivoba)This PR was squashed before being merged into the 3.2-dev branch (closessymfony#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 anyThis 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
Uh oh!
There was an error while loading.Please reload this page.
This adds support for window.fetch calls to the Ajax section of the WebProfiler toolbar.
Credits to@tbopec for implementation :)