cypress: Getting the error in CircleCI "CypressError: Cypress detected a cross origin error happened on page load" for same domain

Current behavior:

The current code cy.contains('Pay for booking').click() returns the error in CircleCI:

CypressError: Cypress detected a cross origin error happened on page load:

  > Blocked a frame with origin "http://agents.test" from accessing a cross-origin frame.

Before the page load, you were bound to the origin policy:
  > http://agents.test

at Object.cypressErr (http://agents.test/__cypress/runner/cypress_runner.js:68040:11)
      at Object.throwErr (http://agents.test/__cypress/runner/cypress_runner.js:68005:18)
      at Object.throwErrByPath (http://agents.test/__cypress/runner/cypress_runner.js:68032:17)
      at onPageLoadErr (http://agents.test/__cypress/runner/cypress_runner.js:58363:21)
      at HTMLIFrameElement.<anonymous> (http://agents.test/__cypress/runner/cypress_runner.js:63921:19)
      at HTMLIFrameElement.dispatch (http://agents.test/__cypress/runner/cypress_runner.js:21476:27)
      at HTMLIFrameElement.elemData.handle (http://agents.test/__cypress/runner/cypress_runner.js:21288:28)

But when I run the tests locally everything is ok. As you can see the domain is the same. The URL from where I click the button is http://agents.test/en/booking_details/72MRGKJ and the destination URL is http://agents.test/adyen/checkout/9dc3c07d-18fc-4322-ba10-d390ff3234a7 How is Cypress defining the CORS violation? Could it be the items in Response headers or cookies?

Desired behavior:

Tests should pass.

Versions

CircleCI (The server is http://php.net/manual/en/features.commandline.webserver.php) OS: Linux Ubuntu - 18.04 Browser: Electron 59.0.3071.115 Cypress: v3.1.0

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 32 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@jennifer-shehane same thing happening to me 😦 cypress.json

{
  "baseUrl": "http://localhost:3002",
  "defaultCommandTimeout": 10000,
  "chromeWebSecurity": false
}

Let me know if there is anything I can do to help debug this.

We were also running into this with a login form. We discovered that when the form was submitted, the POST request redirected to http://localhost:5000/__/ (the Cypress test runner) when it should have redirected to http://localhost:5000/ (our app). When we fixed the redirect location, this issue disappeared.

Perhaps Cypress could improve the way this error is displayed. Reading the error and the docs, it doesn’t make any sense why we would get a cross origin error when the origins are actually the same.

We were seeing seemingly random, intermittent CORS errors with the same domain listed, much like the original issue here. I tried all the various solutions, nothing worked — we’d still see occasional CORS errors. Seemed like an obvious race condition having to do with our DB setup, and finally I tracked it down…

In our beforeEach we seed our DB, and I realized that in a few cases we were ending our tests with a .click() on an element that would trigger a navigation. However the test runner would move on to the next test, running beforeEach which would teardown the DB state before the page loaded from the prior click which in app caused an error when the page did load, resulting in a redirect! The solution for us was to ensure that tests didn’t end with an action that caused navigation.

This is probably an edge case, but figured I’d add it here in case it might be helpful to anyone, since we banged our heads against this for a long time.

Could you try to update to version 3.1.2 as we just fixed some cross origin error issues.

Otherwise we’ll have to close this issue if no reproducible example is provided. Can anyone provide a way to reproduce this?

Hello everyone, in my case the problem was as follows:

  • Visit a page normally using Cypress
  • Click a button that submits an HTML form (method post)
  • The form returns a redirect response that redirects to another URL
    • This URL was in the same protocol, host and port
    • However, this URL was returning a JSON response instead of HTML response. After fixing this to have a redirect into a normal HTML page, the error vanished.

In short: the error message was misleading. It was not a ā€œcross-originā€ error. It was a redirect to a non-html page.

@jennifer-shehane same thing happening to me 😦 cypress.json

{
  "baseUrl": "http://localhost:3002",
  "defaultCommandTimeout": 10000,
  "chromeWebSecurity": false
}

Let me know if there is anything I can do to help debug this.

Thank you! This helps for me) I have successfully implemented login and logout with cypress + keycloak ā¤ļø

Strange thing, but it seems, I’ve managed to fix this issue for my case by just cleaning site data in ā€œcypress Chromeā€.

I’ve been working on the separate simple static server for CI (which meant to replace webpack-dev-server). So each time when I’ve been switching to a new server (which served from the same URL ā€œhttp://localhost:3000ā€ as webpack-dev-server) and rerun tests, I’ve encountered issue described here (CypressError: Cypress detected a cross-origin error happened on page load) It happened when tests were trying to get fallback for SPA paths. Something like this:

app.use('*', (req, res) => {  res.sendFile('index.html') })

I thought the problem was in fallback implementation. But after cleaning site data issue just disappeared. I’ve been trying to reproduce it to find out the reason, but without success.

Unfortunately we have to close this issue as there is not enough information to reproduce the problem.

Please comment in this issue with a reproducible example and we will reopen the issue. šŸ™