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

@jennifer-shehane will want to discuss before adding unit tests, etc

Additional details

Steps to test

How has the user experience changed?

PR Tasks


Note

Avoids browser hangs when cy.intercept handles synchronous XMLHttpRequest by tagging sync requests and bypassing awaits/cookie automation in proxy and runner.

  • Network Stubbing (packages/net-stubbing/):
    • In intercepted-request.ts, immediately emit intercept events for synchronous requests by checking req.isSyncRequest to skip awaiting route handlers.
  • Proxy (packages/proxy/):
    • request-middleware.ts: extract and remove x-cypress-is-sync-request header; set req.isSyncRequest.
    • response-middleware.ts: when simulated cookies are added, skip cookie automation flow for synchronous requests to avoid hangs.
    • types.ts: add isSyncRequest: boolean to CypressIncomingRequest.
  • Runner Injection (packages/runner/injection/):
    • main.js and patches/xmlHttpRequest.ts: patch XMLHttpRequest.open/send to mark synchronous requests by setting x-cypress-is-sync-request and bypass async credential signaling for sync requests.
  • Docs:
    • cli/CHANGELOG.md: add bugfix note for freeze on intercepted synchronous requests.

Written by Cursor Bugbot for commit 12a25e4. This will update automatically on new commits. Configure here.

@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.

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

4 participants