Skip to content

Conversation

@alexsch01
Copy link
Contributor

@alexsch01 alexsch01 commented Nov 10, 2025

This issue happens when a synchronous request is intercepted and the routeHandler argument to cy.intercept is given


The second part of this PR (prevent cross origin cookies from breaking sync requests)

  • prevents the browser from freezing when a sync request is made through the cross origin runner

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.

  • Network/Proxy:
    • Skip cy.intercept() for synchronous XHRs with a routeHandler (intercepted-request.ts); emit warning SYNCHRONOUS_XHR_REQUEST_NOT_INTERCEPTED.
    • Detect sync XHR via x-cypress-is-sync-request header; plumb through request pipeline (request-middleware.ts, types.ts).
    • Warn when cross-origin cookies may not be applied/set for sync XHRs in request/response middleware.
  • Runner Injection:
    • Patch XHR in both primary and cross-origin injections to set x-cypress-is-sync-request and avoid awaiting credentials for sync requests; reorganize patches under patches/cross-origin/*.
  • Errors/Schema:
    • Add new warnings: SYNCHRONOUS_XHR_REQUEST_NOT_INTERCEPTED, SYNCHRONOUS_XHR_REQUEST_COOKIES_NOT_APPLIED, SYNCHRONOUS_XHR_REQUEST_COOKIES_NOT_SET (errors, snapshots, GraphQL enum).
  • Tests:
    • Add e2e tests for sync XHR interception behavior (including worker and cross-origin) and cookie behavior; update system tests to assert terminal warnings; unit tests for new header handling.
  • Misc:
    • Update CHANGELOG with bugfix; adjust import paths; add @packages/errors devDependency 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 routeHandler no longer cause the browser to hang.
Verify a synchronous XHR request from within a cy.origin block and a set-cookie in the response no longer cause the browser to hang.

How has the user experience changed?

The browser no longer hangs with synchronous XHR requests.
Screenshot 2025-12-04 at 10 43 35 AM

PR Tasks

@alexsch01 alexsch01 marked this pull request as draft November 10, 2025 15:06
@cypress-app-bot
Copy link
Collaborator

@alexsch01 alexsch01 marked this pull request as ready for review November 10, 2025 15:31
@mschile
Copy link
Contributor

mschile commented Nov 13, 2025

Hi @alexsch01 👋🏼, thanks for opening this PR! Just to make sure I understand the proposed changes, this would resolve the freezing issue but the routeHandler of the intercepted request would not be executed. Is my understanding correct?

@alexsch01
Copy link
Contributor Author

Hi @alexsch01 👋🏼, thanks for opening this PR! Just to make sure I understand the proposed changes, this would resolve the freezing issue but the routeHandler of the intercepted request would not be executed. Is my understanding correct?

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

@mschile
Copy link
Contributor

mschile commented Nov 14, 2025

Ok, I see the before:request event is still emitted but since this is a sync request, the event is received after the sync request has already been fully processed. I'm going to discuss this further with the team but my initial thought is that we should skip the adding the subscriptions entirely here.

@alexsch01
Copy link
Contributor Author

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 cy.origin due to navigating to a different subdomain, this allows the test to work as expected when there's a sync request

@mschile
Copy link
Contributor

mschile commented Nov 14, 2025

Thanks for cross origin explanation. I'll have to look into it further.

@mschile
Copy link
Contributor

mschile commented Nov 18, 2025

@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 routeHandler won't get run. We would also like to log out some warnings to the terminal to inform the user that the sync request was not intercepted and for the cross-origin case that cookies may not have been applied.

@alexsch01
Copy link
Contributor Author

@mschile I skipped adding the subscriptions entirely for sync requests and added the 2 warnings

Let me know how that looks

@alexsch01
Copy link
Contributor Author

alexsch01 commented Nov 21, 2025

Looks good overall! Made a few changes. Let's go ahead and add some unit and e2e tests.

made some tests, your changes look good

@mschile mschile requested a review from AtofStryker December 2, 2025 23:31
Copy link
Contributor

@AtofStryker AtofStryker left a 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 AtofStryker self-requested a review December 4, 2025 17:24
Copy link
Contributor

@AtofStryker AtofStryker left a 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

@alexsch01
Copy link
Contributor Author

@mschile in firefox for the driver cookie_misc test, the sync cookie is set so the length of cookies array is 2
Doesn't happen in Chrome

@mschile
Copy link
Contributor

mschile commented Dec 4, 2025

@mschile in firefox for the driver cookie_misc test, the sync cookie is set so the length of cookies array is 2 Doesn't happen in Chrome

Yep, I'm updating the test since Firefox does indeed get the cookie.

@mschile mschile merged commit 2656332 into cypress-io:develop Dec 5, 2025
67 checks passed
@alexsch01
Copy link
Contributor Author

Thank you guys so much on working with me on this!

I just tested the pre-release and it works perfectly

@alexsch01 alexsch01 deleted the fix-browser-freeze branch December 5, 2025 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Browser will freeze when sync request is intercepted

5 participants