question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intercepting ajax request with "async: false" cause cypress to freeze

See original GitHub issue

Current behavior

We have code (JS/jQuery) invoking the POST request:

$.ajax({
    type: 'POST',
    url: '/web/api2/v1/term/{0}'.format(tbId),
    dataType: 'json',
    contentType: 'application/json',
    cache: false,
    async: false,
    data: JSON.stringify({
        conceptId: conceptId,
        lang: input.attr('name'),
        text: input.val()
    }),
    success: function (data) {
        ...
    },
    error: function (req, status) {
        ...
    }
});

When we run tests on production we then intercept all the calls to add additional header and only on the request triggered like this cypress completely freeze. Screenshots and Debug logz are attached. Logs.txt caprese 2022-06-19 08-22-05

Desired behavior

Cypress should intercept the request.

Test code to reproduce

application code (JS/jQuery) invoking the POST request

$.ajax({
    type: 'POST',
    url: '/web/api2/v1/term/{0}'.format(tbId),
    dataType: 'json',
    contentType: 'application/json',
    cache: false,
    async: false,
    data: JSON.stringify({
        conceptId: conceptId,
        lang: input.attr('name'),
        text: input.val()
    }),
    success: function (data) {
        ...
    },
    error: function (req, status) {
        ...
    }
});

test.spec.js

cy.get('#tb-insert-button').click();
  cy.get('#tb-insert-tbody').find(`input[type="text"][name=${targetLang}]`).type(term);
  cy.get('#tb-insert-submit').click();`

index.js

`beforeEach('Adds headers to web012 env', () => {
  if (Cypress.env('ENVIRONMENT') === 'web012') {
    cy.log(Cypress.env('ENVIRONMENT'));
    cy.intercept(/^https:\/\/some\.domain\.com\/web\/(?!assets).*/, (req) => {
      req.headers['X-Memsource-Web-Canary-Request'] = 'any';
    });
  }
});

Cypress Version

9.6.2

Other

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tbiethmancommented, Jun 23, 2022

@Donaab thank you for the report, I can reproduce this. The interception of synchronous requests seems to lock up cypress indefinitely. If I don’t intercept the synchronous request, the app will hang while the request executes but continues functioning after the request completes. I can also safely intercept the request if I provide a stubbed response.

I also put together a small reproduction as part of my investigation: https://github.com/tbiethman/cypress-test-tiny/tree/sync-request-intercept

As far as I can tell, when the app makes the synchronous request, it’s not able to handle events emitted from the middleware that allow the interception to be possible, which in result never allows the request to complete. More investigation will be required to determine how we should be handling these types of requests; we definitely shouldn’t allow Cypress to get into a scenario that we know will cause a hang.

0reactions
nogwatercommented, Nov 22, 2022

Is there any way to skip interception of async:false requests? I’m trying to follow this sample code for throttling all requests, but I keep getting stuck with pending requests and Cypress frozen. https://docs.cypress.io/api/commands/intercept#Throttle-or-delay-response-all-incoming-responses

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ajax Async False Freeze - Stack Overflow
Here is a solution that will make the uploads one by one without using async: false while still using asynchronous i/o and not...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
intercept runs, the call is already in progress, and thus not intercepted. Cypress shows XHR calls by default in its Command Log, thus...
Read more >
Changelog - Cypress Documentation
testIsolation=false caused invalid configuration validation when running cypress ... Use the cy.intercept() command to stub network responses and requests.
Read more >
Synchronous Ajax Call - Magia della Natura
The interception of synchronous requests seems to lock up cypress indefinitely. Asynchronous calls allow the client side process to continue while waiting ...
Read more >
Synchronous Ajax Call - Bar Sereno
Intercepting ajax request with "async : false" cause cypress to freeze. gotthard panorama express ticket / fluminense vs palmeiras predictions / like a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found