Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[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

Closed
ivoba wants to merge4 commits intosymfony:masterfromfreshcells:ticket_17444

Conversation

@ivoba
Copy link
Contributor

@ivobaivoba commentedAug 9, 2016
edited
Loading

QA
Branch?"master"
Bug fix?yes
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#17444
LicenseMIT
Doc PRreference 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 :)

ro0NL, staabm, and RolfBabijn reacted with hooray emoji
@fabpot
Copy link
Member

@javiereguiluz Can you validate this one?

@fabpot
Copy link
Member

@robfrawley Can you test it?

@nicolas-grekas
Copy link
Member

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');
Copy link
Member

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@romainneutron any ideas?

Copy link
Contributor

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
Copy link
Member

Status: needs work

@ivoba
Copy link
ContributorAuthor

Applied fixes for@stof `s comments.

@@ -1,4 +1,4 @@
<script{%ifcsp_script_nonceisdefinedandcsp_script_nonce %}nonce={{csp_script_nonce }}{%endif %}>/*<![CDATA[*/
Copy link
Member

@stofstofAug 24, 2016
edited
Loading

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
Copy link
Member

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
Copy link
ContributorAuthor

oops how did that happen?
fix is coming...

@ivoba
Copy link
ContributorAuthor

@stof done, sorryy

var promise=oldFetch.apply(null,arguments);
var method='GET';
if(arguments[1].method!==undefined){

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 .

Copy link
ContributorAuthor

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%}
Copy link
Member

@fabpotfabpotSep 14, 2016
edited
Loading

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 }}))) {
Copy link
Member

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){
Copy link
Member

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
Copy link

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);
Copy link
Member

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

Copy link
ContributorAuthor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

oldFetch.apply(window, arguments);

Copy link
Member

@stofstofSep 30, 2016
edited
Loading

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

Copy link
ContributorAuthor

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) {
Copy link
Contributor

@romainneutronromainneutronSep 30, 2016
edited
Loading

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.

Copy link
ContributorAuthor

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;
});
Copy link
Contributor

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?

Copy link
ContributorAuthor

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);
Copy link
Contributor

@romainneutronromainneutronSep 30, 2016
edited
Loading

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;
Copy link
Contributor

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?

Copy link
ContributorAuthor

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.

Copy link
Member

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)

Copy link
ContributorAuthor

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 () {
Copy link
Contributor

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

Copy link
ContributorAuthor

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) {
Copy link
Member

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)

Copy link
ContributorAuthor

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?

Copy link
Member

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.

Copy link
ContributorAuthor

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
Copy link
Contributor

@ivoba Do you need help with the templates so you can finish this feature for 3.2? :)

@fabpot
Copy link
Member

Thank you@ivoba.

@fabpotfabpot mentioned this pull requestOct 27, 2016
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull requestMar 25, 2018
…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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@stofstofstof approved these changes

+1 more reviewer

@romainneutronromainneutronromainneutron requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

9 participants

@ivoba@fabpot@nicolas-grekas@stof@RolfBabijn@HeahDude@romainneutron@aegyed91@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp