Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[WebProfilerBundle] SetXDEBUG_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 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
8e0a86b to76241d9CompareXDEBUG_SESSION cookie while performing XHRs| 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?
adrolter commentedDec 9, 2023
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 XHRadrolter commentedDec 9, 2023
Interrupted XHRs due to page reloads/redirects/etc. are now handled by a |
adrolter commentedDec 9, 2023 • 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.
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. |
nicolas-grekas left a comment
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?
adrolter commentedDec 27, 2023
@nicolas-grekas I wish, but no, XHR in modern browsers does not support manually specifying the |
adrolter commentedDec 28, 2023 • 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.
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. |
adrolter commentedDec 28, 2023
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? |
nicolas-grekas commentedDec 29, 2023
Another idea: since xdebug is sensitive to |
adrolter commentedDec 29, 2023 • 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.
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 |
derickr commentedDec 31, 2023 • 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.
| 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 isanother way to trigger Xdebug.
Does that also include passing |
adrolter commentedDec 31, 2023
@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. |
adrolter commentedDec 31, 2023 • 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.
nicolas-grekas commentedJan 2, 2024
What about |
derickr commentedJan 2, 2024
No, |
derickr commentedJan 10, 2024
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 cookiesby 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. 🍪 |
adrolter commentedJan 10, 2024
An |
derickr commentedJan 16, 2024
nicolas-grekas commentedJan 23, 2024
Thanks@derickr |
derickr commentedJan 23, 2024 via email
Just finishing it by writing the tests. |
derickr commentedJan 23, 2024
I have merged this into Xdebug's master now, in case you want to try it (xdebug/xdebug@5630bdb) |
nicolas-grekas commentedFeb 9, 2024
@adrolter let's resume this PR? 🙏 |
XDEBUG_* cookie while performing XHRXDEBUG_IGNORE option for all XHRadrolter commentedFeb 10, 2024 • 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.
Reworked to use thew new @derickr Thank you very much for paving the way for this feature; it's very much appreciated! |
745f20e toae07ed0Comparefabpot commentedMar 17, 2024
Thank you@adrolter. |

Uh oh!
There was an error while loading.Please reload this page.
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!