-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WebProfilerBundle] Set XDEBUG_IGNORE
option for all XHR
#52950
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
8e0a86b
to
76241d9
Compare
XDEBUG_SESSION
cookie while performing XHRs
@@ -88,6 +111,10 @@ | |||
xhr.open(options.method || 'GET', url, true); | |||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | |||
xhr.onreadystatechange = function(state) { | |||
if (xdebugCookieValue !== null) { |
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 don't fully understand why here we need this code to set the cookie 🤔
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.
looks like the results are achieved by removing the cookie during the request. Therefor the cookie wil by set again after te request finishes.
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.
You are right. This sounds obvious now 😊 Thanks for helping me understand this.
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.
Yes, that's correct. Thank you, Duncan. The only pitfall I see with my approach is that it is possible that the request is interrupted and never finishes for some reason (which would leave the cookie unset), but this seems fairly unlikely. And even if it did happen, the worst outcome is that the Xdebug extension becomes disabled and has to manually be enabled again, so it's fairly benign.
ETA: I could add a "beforeunload" callback to handle this case, if deemed beneficial?
FYI I decided to implement the "beforeunload" handler and rework this a bit, so I've converted to it to a draft for the moment. I'll submit a revision and switch it back shortly. Thanks! |
XDEBUG_SESSION
cookie while performing XHRsXDEBUG_*
cookie while performing XHR
Interrupted XHRs due to page reloads/redirects/etc. are now handled by a |
After more testing, I discovered that reinstating the cookie after the response was received (in a What does seem to work very reliably, at least in Chrome, is reinstating the cookie on the next iteration of the browser's event loop. |
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.
Would it be possible to force the cookie header just for the XHR instead of changing the state of the browser?
@nicolas-grekas I wish, but no, XHR in modern browsers does not support manually specifying the |
As I see it, the only viable solutions to this issue are:
I wish there was a more elegant avenue because I quite dislike both of the given options for different reasons, but I haven't found one yet. |
Actually, what if instead of managing the Xdebug cookie via some extra browser extension, the Symfony toolbar could manage it instead through a new UI element with similar functionality to the browser extensions? This is probably still prone to side-effects when there are concurrent requests in different tabs or caused by XHR in the user's app, for example, but maybe it's a step in the right direction? |
Another idea: since xdebug is sensitive to |
Impossible, unfortunately...at least AFAICT. All of the GET parameters that Xdebug respects ( The only way to prevent triggering Xdebug when making an HTTP request and The |
| Symfony toolbar could manage it instead through a new UI element with similar functionality to the browser extensions? Please don't do that. That makes the support on my side even harder, as now there is another way to trigger Xdebug.
Does that also include passing |
@derickr If that works, I won't complain, but it is undocumented. I'll report back with my findings – thanks!
I hadn't considered this aspect. I assumed that support for the feature would fall on the Symfony project, but that was probably naive. |
What about |
No, |
I have had a look now, and all that I see two options:
I think I slightly prefer the latter, as I have the intention of phasing out the whole setting cookies by Xdebug. Most people either use an IDE to trigger a request, or a browser extension which always sends the cookie, no matter what Xdebug does itself with the cookies. 🍪 |
An |
Thanks @derickr |
Just finishing it by writing the tests.
|
I have merged this into Xdebug's master now, in case you want to try it (xdebug/xdebug@5630bdb) |
@adrolter let's resume this PR? 🙏 |
XDEBUG_*
cookie while performing XHRXDEBUG_IGNORE
option for all XHR
Reworked to use thew new @derickr Thank you very much for paving the way for this feature; it's very much appreciated! |
745f20e
to
ae07ed0
Compare
Thank you @adrolter. |
When using an Xdebug browser extension with Symfony, toolbar requests are also processed by Xdebug because the browser extension has set an
XDEBUG_*
cookie on the page. This leads to superfluous breakpoint triggering when debugging at lower levels of the codebase, as well as a performance hit with no gain for every toolbar request, junk profiler/trace output blobs, etc.The only sane way to prevent this behavior seems to be for the cookie to never be sent, as Xdebug has no mechanism for ignoring requests to certain URIs, and detecting this condition at the webserver and rewriting the request before passing it off to PHP is also non-trivial.
This PR detects the
XDEBUG_*
cookie and removes it before conducting XHR, then re-sets it after the fact.Thanks!