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

Created on 10 Sep 2018  路  26Comments  路  Source: cypress-io/cypress

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

Most helpful comment

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

All 26 comments

Do you have a screenshot/video of the failure? Is there anything strange being printed in the command log (the lefthand side of Cypress commands)?

@jennifer-shehane You can find the screenshot here https://monosnap.com/file/pKBg4hQBNitQel2lbv0V6cv7tluWMU
Also if it helps, when I added "chromeWebSecurity": false the url changed to data:text/html,chromewebdata https://monosnap.com/file/vB6JWfxTUQYmbUpkJ6ANl3yu6vKrB5

@jennifer-shehane, this happens to me as well 馃槥
OS: macOS High Sierra, version: 10.13.6 (17G65)
OS: Linux Debian - 8.10
Browser: Electron 59.0.3071.115
Cypress: v3.1.0
"chromeWebSecurity" is set to false.

Works on Chrome Version 69.0.3497.100 (Official Build) (64-bit)

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

I wonder if this is related
From https://bugs.chromium.org/p/chromedriver/issues/detail?id=1272

Issue Description:
On connection error, GET url returns "data:text/html,chromewebdata".

Steps to reproduce (if relevant, you MUST provide a simplified html page or
link to public site):
1. Navigate to a URL which produces ERR_CONNECTION_REFUSED in Chrome.
2. GET url for that window and see "data:text/html,chromewebdata"

Potentially related fix going out in 3.1.2 https://github.com/cypress-io/cypress/pull/2787

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?

this is happening to me as well - very inconsistent. I dont believe i can provide a "reproducible example" either. its occuring on 3.1.4 for me in electron as well :(

ooph:
image

My guess is that trying to access properties from other frames is causing an issue. I can see the same code break in certain lines of cypress runner code - e.g. when cypress is getting window props and needs to do contentWindow.document it fails there, as well. So it seems, trying to access properties from a frame other than your own is throwing chrome bugs now. Which is weird especially since it is stemming from cypress code. It appears I am not doing anything extremely weird in my code either. For now I've disabled chrome security which serves as a workaround. I'm going to re-search through the other github issues since I'm definitely confused about this one, and why I'm suddenly running into it.

EDIT: @jennifer-shehane i cannot find anything which seems like the same issue I am having now. Some more details

1) Code has been running in CI for ages and not locally and just fine. We did an upgrade to 3.1.0 at some point while not trying much locally.
2) Started seeing these specific failures in run and open mode on my local. Tried to upgrade to 3.14 to no avail. The only difference was that We were pointing the app to a different domain, but it was not trying to access any cross origin domains. We essentially just flipped staging => dev and everything else is the same. In order to reduce the moving parts impacting this issue, we also modified the code to remove variables such as our custom Iframe test code (not applicable for the failing tests themselves), and the issue remained.
3) Narrowed done one issue to stepping from our own module, which checks window.parent.Cypress. It fails on accessing Cypress. (I can try capturing this better, still)
4) This did not resolve all the issues. I used the Runner again to demonstrate where the exception is thrown, which brought me to internal Cypress code which was simply getting contentWindow.document to pass alone to other things. Mind you, the error is not even thrown on page load, but a few commands in.

I am using MacOS as well.

I'm facing exactly the same error, but no idea how to reproduce it in a way I can share it here.

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. 馃檹

@jennifer-shehane, Hi, I have same issue, when i try to change browser's date by this example

The error is

Cypress detected that an uncaught error was thrown from a cross origin script.

We cannot provide you the stack trace, line number, or file where this error occurred.

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

It's possible to enable debugging these scripts by adding the 'crossorigin' attribute and setting a CORS header.

https://on.cypress.io/cross-origin-script-error

This error originated from your application code, not from Cypress.

When Cypress detects uncaught errors originating from your application it will automatically fail the current test.

This behavior is configurable, and you can choose to turn this off by listening to the 'uncaught:exception' event.

https://on.cypress.io/uncaught-exception-from-application
    at createErrFromMsg (http://simpla.v2/__cypress/runner/cypress_runner.js:58811:14)
    at Object.createUncaughtException (http://simpla.v2/__cypress/runner/cypress_runner.js:58818:13)
    at Object.onUncaughtException (http://simpla.v2/__cypress/runner/cypress_runner.js:61698:20)
    at onError (http://simpla.v2/__cypress/runner/cypress_runner.js:61197:39)
From previous event:
    at run (http://simpla.v2/__cypress/runner/cypress_runner.js:61382:15)
    at Object.cy.(anonymous function) [as clock] (http://simpla.v2/__cypress/runner/cypress_runner.js:61610:11)
    at Context.runnable.fn (http://simpla.v2/__cypress/runner/cypress_runner.js:61740:20)
    at callFn (http://simpla.v2/__cypress/runner/cypress_runner.js:30560:21)
    at Test.Runnable.run (http://simpla.v2/__cypress/runner/cypress_runner.js:30553:7)
    at http://simpla.v2/__cypress/runner/cypress_runner.js:64685:28
From previous event:
    at Object.onRunnableRun (http://simpla.v2/__cypress/runner/cypress_runner.js:64680:20)
    at $Cypress.action (http://simpla.v2/__cypress/runner/cypress_runner.js:60037:51)
    at Test.Runnable.run (http://simpla.v2/__cypress/runner/cypress_runner.js:63746:20)
    at Runner.runTest (http://simpla.v2/__cypress/runner/cypress_runner.js:31023:10)
    at http://simpla.v2/__cypress/runner/cypress_runner.js:31129:12
    at next (http://simpla.v2/__cypress/runner/cypress_runner.js:30943:14)
    at http://simpla.v2/__cypress/runner/cypress_runner.js:30953:7
    at next (http://simpla.v2/__cypress/runner/cypress_runner.js:30885:14)
    at http://simpla.v2/__cypress/runner/cypress_runner.js:30921:5
    at timeslice (http://simpla.v2/__cypress/runner/cypress_runner.js:26162:27)

Cypress version: v3.5.2
OS: Linux Mint 19.1 Cinnamon
Browser: Chrome v73.0.3683.

describe("Date time",()=>{
    it("should not fails",()=>{
        const now = new Date(2017, 3, 14).getTime() // April 14, 2017 timestamp
       // When the next line is commented out, the code works fine.
        cy.clock(now)
        cy.visit('/');
    })
})

@Deemon47 I'm unable to reproduce this when calling cy.visit('https://example.cypress.io') in the example you provided. This failure is likely somehow specific to the actual url you are visiting in cy.visit().

Can you provide the url here? I think an error is being thrown somewhere from the application code (or a 3rd party dep of the app).

I can confirm this happened to me today multiple times, but after an hour or so it simply disappeared, and I've been unable to reproduce it since.

@jennifer-shehane , Thanks for response.
I run tests on my localhost, so i can't provide the url.

Today strange things happen: After my post i wasn't touch the code, and now when I run the test again, there is no cross-origin error. Now it has Yandex Maps API error - it's used on my project and looks like this API checks the current date and throw an exception when date is wrong. I understand that current error it is not cypress error, but why there was cross-origin error at previous time? look like bug.

Hello! This is my code, I hope this one is reproducible:

describe('Happy Path B2C / Checkout V2 ', function () {
beforeEach("Home - Catalog - PP - Cart", function(){

        //Going directly to product's page 
        cy.visit('https://juntozstagingv2.com/es-pe/');

        //Closing Ads
        cy.get("div[data-action='close-mc-modal']").click({force:true})

        //Triggerin Login
        cy.get("a[aria-haspopup='true']").click();
        cy.get("a[href='https://juntozstagingv2.com/account/login']").click();
    })
});

I'm not sure if this is the issue in the topic but I get this screen when I try to access certain pages:
image
This I can easily access on the same browser used by cypress
image

I have my "chromeWebSecurity": false on my cypress file just in case

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.

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 鈥斅爓e'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.

Not sure where the discussion should be continued. So i copy & paste the same into this issue:

ok here is a small example:
https://github.com/gabbersepp/cypress-example/tree/cy-issue-2448

StR:

bash 1: npm run server
bash 2: npm run cypress:open
execute "cross" spec
please note: it seems that using the cypress retry plugin is the key in our case.
I try to find a bugfix for our usecase.

@jennifer-shehane maybe you have to start the test a few times using the reload button:
image

The bug occurrs when executing cy.wrap().as() while trying to get the remote jquery instance:

image

image

I tried to avoid the usage of cy.wrap() but this did not help. I will open a issue in the retry repository

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 鈥斅爓e'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.

Yup... I had exactly the same scenario as yours and it took me a day to figure this out. A fix was to add an assertion after a click command that URL contains certain expected text. That fixed the issue because now cypress was waiting to complete click() command before running beforeEach for the next test.

@Postavshik Ah, good call!

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

Because my server threw an exception that was not caught during one of my tests, causing the server to go offline before the test completed (and the test tried to reach the server again), I got this error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carloscheddar picture carloscheddar  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments

igorpavlov picture igorpavlov  路  3Comments

verheyenkoen picture verheyenkoen  路  3Comments

szabyg picture szabyg  路  3Comments