cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.8k stars 3.17k forks source link

cy.origin()` failed to create a spec bridge to communicate with the specified origin. Only occurs when running from ECS Fargate #28284

Open EddySum opened 11 months ago

EddySum commented 11 months ago

Current behavior

 CypressError: `cy.origin()` failed to create a spec bridge to communicate with the specified origin. This can happen when you attempt to create a spec bridge to an insecure (http) frame from a secure (https) frame.

Check your Developer Tools Console for the actual error - it should be printed there.

Desired behavior

The cy.origin command should work without an error. The commands inside the cy.origin callback should run.

At the minimum, the error message should be more descriptive/ provide more insight into the issue.

Test code to reproduce

This can get a bit tricky/puzzling. Running our tests locally or from within a docker image locally does not prompt the error seen above.

However, running the docker image on AWS ECS does prompt the issue seen. I have confirmed the issue is not an environment variable issue. I have also confirmed that we are switching from HTTPs origin to HTTPs origin.

This is the code that is causing the issue. Our web application triggers the redirect to an external login page.

 cy.origin(`${Cypress.env('auth_url')}`, { args: [password] }, ([password]) => {
    cy.get('input[type="password"]').type(password);
    cy.get('button[value="login"]').click();
});

Cypress Version

13.4.0

Node version

19

Operating System

ECS Fargate with a bullseye slim linux machine

Debug Logs

No response

Other

The error message is not very descriptive. I have also used an npm package to print the chrome messages to the console and thus our logs in ecs. However, no error related to cy.origin was displayed there either.

I have also run the code in debug mode and am able provide this if needed. (Will need to make sure no sensitive information is included in those logs)

Could anyone shed insight into what could be causing this issue or how to get more information into what is prompting the error?

asadullahqazi-360training commented 9 months ago

I am also encountered same issue. Cypress Version = 13.6.2 Node Version = 20.9.0 OS = Windows 10

cypress-origin-issue

Following is the code where issue is occur:

cy.origin(newOrigin, { args: { printCertificateUrl } }, ({ printCertificateUrl }) => {
    cy.request({
      url: `https://domain.com${printCertificateUrl}`,
      encoding: 'binary',
    }).then((response) => {
      cy.writeFile('cypress/downloads/cert1.pdf', response.body, 'binary')
    })
  })
jennifer-shehane commented 9 months ago

@EddySum @asadullahqazi-360training What browser are you running tests in and what version browser? Did the browser recently update or anything else update before you began seeing this error?

Chrome recently made changes to http -> https upgrading and was just asking this line of questioning to see whether this may be related.

This error is supposed to throw in the situation of visiting an https and then an origin of http of the same domain. The example we test below should throw the error for instance:

cy.visit('https://www.foobar.com:3502/fixtures/primary-origin.html')
cy.origin('http://www.foobar.com:3500', () => {})

In this case, the browser itself would throw an error and we are trying to alert you to check the actual error in DevTools. If this is not what either of you are doing, we'd like to track down this error cause.

danielzsandberg commented 7 months ago

Hello,

We are also encountering this issue. We've been seeing it for several months at this point and are addressing it now because it is generating an enormous amount of test flake.

We are doing the following:

  1. Visiting our app unauthenticated. This causes an automatic redirection to our auth server.
  2. After visiting we immediately call cy.origin in order to type the user and password of our test user

We are considering putting a long sleep between 1 and 2 to give time for the redirection to complete (sometimes it takes a few seconds). That being said, this is a common use case documented in the cy.origin docs and there certainly isn't any sleeping going on there so would really prefer a more robust solution. Also I have no idea if the sleep will even work. We will be monitoring our flake data to determine if it has an impact.

Also to be clear the url we are putting into cy.origin is https and not http. The originating origin is also https

Mykola-Konotop commented 3 months ago

Hi all! I also ran into this problem and noticed that this error is reproduced periodically on CI (GitHub Actions). Locally, everything goes without problems, it doesn't matter in headed or headless mode. I'm currently using Cypress v13.12.0 and the latest version of Chrome, but this is also reproduced on previous versions of Cypress and Chrome on CI. I also use https in my tests, including in cy.origin

Monosnap Cypress test with Chrome browser · Self-I

klaussilveira commented 2 months ago

Also having this issue. Problem does not occur locally on chrome, chromium, firefox or electron. Only occurs on GitHub Actions with chrome.

Pajicc commented 2 weeks ago

Is there any news on this? I have the same problem. Both urls have https, im using cy.origin, works always locally, but on CI (github actions) fails sometimes, not always.