-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: Browser will freeze when sync request is intercepted #32925
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
|
|
Hi @alexsch01 👋🏼, thanks for opening this PR! Just to make sure I understand the proposed changes, this would resolve the freezing issue but the |
The routeHandler is executed but the request that goes to the server won't be modified req.headers["foo"] = "bar" The server will not get this since it's not resolved, but anything you console.log in the routeHandler will print in DevTools console |
|
Ok, I see the |
|
The second part of the fix (7b4f2e7) fixes a freezing issue when there's a sync request in cy.origin block The downside is cross-origin cookies most likely won't work in this case In cases where you must use |
|
Thanks for cross origin explanation. I'll have to look into it further. |
|
@alexsch01, I discussed this PR with the rest of the team and we are good with proceeding. We should skip adding the subscriptions entirely here so the |
|
@mschile I skipped adding the subscriptions entirely for sync requests and added the 2 warnings Let me know how that looks |
made some tests, your changes look good |
AtofStryker
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.
I don't think we need to fully patch XMLHttpRequest in the main injection code as we do in the cross-origin code. if we need to detect a sync request in the main injection, we likely want to create a partial patch as well as add documentation in the code as to why we are patching the main injection code because right now that is not entirely obvious.
AtofStryker
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.
So I completely misread the diff where the patches got moved, so the main injection patch really is simple like we need. My fault on that! Rest of the PR looks good on my end
|
@mschile in firefox for the driver cookie_misc test, the sync cookie is set so the length of cookies array is 2 |
Yep, I'm updating the test since Firefox does indeed get the cookie. |
|
Thank you guys so much on working with me on this! I just tested the pre-release and it works perfectly |
This issue happens when a synchronous request is intercepted and the
routeHandlerargument to cy.intercept is givenThe second part of this PR (prevent cross origin cookies from breaking sync requests)
Additional details
Note
Avoids freezing by not intercepting synchronous XHRs with route handlers and adds warnings for sync XHR interception/cookie caveats across proxy and runner.
cy.intercept()for synchronous XHRs with arouteHandler(intercepted-request.ts); emit warningSYNCHRONOUS_XHR_REQUEST_NOT_INTERCEPTED.x-cypress-is-sync-requestheader; plumb through request pipeline (request-middleware.ts,types.ts).x-cypress-is-sync-requestand avoid awaiting credentials for sync requests; reorganize patches underpatches/cross-origin/*.SYNCHRONOUS_XHR_REQUEST_NOT_INTERCEPTED,SYNCHRONOUS_XHR_REQUEST_COOKIES_NOT_APPLIED,SYNCHRONOUS_XHR_REQUEST_COOKIES_NOT_SET(errors, snapshots, GraphQL enum).@packages/errorsdevDependency in net-stubbing.Written by Cursor Bugbot for commit 8526514. This will update automatically on new commits. Configure here.
Steps to test
Verify intercepted synchronous XHR requests with a
routeHandlerno longer cause the browser to hang.Verify a synchronous XHR request from within a
cy.originblock and aset-cookiein the response no longer cause the browser to hang.How has the user experience changed?
The browser no longer hangs with synchronous XHR requests.

PR Tasks
cypress-documentation? doc: add docs for synchronous XHR requests cypress-documentation#6332type definitions?