Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
olefirenko opened this issue Sep 10, 2018 · 32 comments

Comments

@olefirenko
Copy link

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

@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Sep 10, 2018
@jennifer-shehane
Copy link
Member

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)?

@olefirenko
Copy link
Author

@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

@itaykotler-fundbox
Copy link

itaykotler-fundbox commented Sep 26, 2018

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

@grantspeelman
Copy link

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

@grantspeelman
Copy link

grantspeelman commented Oct 23, 2018

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"

@jennifer-shehane
Copy link
Member

Potentially related fix going out in 3.1.2 #2787

@jennifer-shehane
Copy link
Member

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?

@egucciar
Copy link
Contributor

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 :(

@egucciar
Copy link
Contributor

ooph:
image

@egucciar
Copy link
Contributor

egucciar commented Jan 18, 2019

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.

@xavivars
Copy link

xavivars commented Apr 2, 2019

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

@jennifer-shehane jennifer-shehane removed the stage: needs investigating Someone from Cypress needs to look at this label Apr 24, 2019
@jennifer-shehane
Copy link
Member

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

@Deemon47
Copy link

Deemon47 commented May 3, 2019

@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('/');
    })
})

@jennifer-shehane
Copy link
Member

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

@GeeWee
Copy link

GeeWee commented May 6, 2019

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.

@Deemon47
Copy link

Deemon47 commented May 6, 2019

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

@gerardovanegas-eagle
Copy link

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

@VoloshinS
Copy link

VoloshinS commented May 31, 2019

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.

@jmwohl
Copy link

jmwohl commented Aug 28, 2019

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.

gabbersepp added a commit to gabbersepp/cypress-example that referenced this issue Nov 19, 2019
StR:
- bash 1: npm run server
- bash 2: npm run cypress:open
- execute "cross" spec

note: retry plugin seems to be the key in this usercase
gabbersepp added a commit to gabbersepp/cypress-example that referenced this issue Nov 19, 2019
StR:
- bash 1: npm run server
- bash 2: npm run cypress:open
- execute "cross" spec

note: retry plugin seems to be the key in this usercase
@gabbersepp
Copy link
Contributor

gabbersepp commented Nov 19, 2019

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

@gabbersepp
Copy link
Contributor

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

image

image

@gabbersepp
Copy link
Contributor

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

@bondar-artem
Copy link

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.

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.

@jmwohl
Copy link

jmwohl commented Nov 27, 2019

@Postavshik Ah, good call!

@just0110
Copy link

@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

@brettz9
Copy link

brettz9 commented May 25, 2020

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.

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jan 12, 2021

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.

@rrauenza
Copy link
Contributor

rrauenza commented Jan 21, 2022

Also seeing this,

CypressError: Cypress detected a cross origin error happened on page load:
  > Blocked a frame with origin "http://localhost:47064" from accessing a cross-origin frame.
Before the page load, you were bound to the origin policy:
  > http://localhost:47064
A cross origin error happens when your application navigates to a new URL which does not match the origin policy above.


Because this error occurred during a before each hook we are skipping the remaining tests in the current suite:

Now.. I've been monkeying around with my beforeEach and added some cy.intercepts recently to deal with the problem that my cy.request() with followRedirect=false not always being honored.

function do_login(username: string = 'e2e', password: string = 'e2e'): void {
  // ignore any GET's during login due to cy.request not honoring followRedirect always.
  cy.intercept(
    {method: 'GET'},
    {
      statusCode: 400,
    }
  );
  cy.request({method: 'POST', url: 'api/rest/accounts/login/', followRedirect: false, body: {username: username, password: password}}).then(
    (response) => {
      expect(response.status).to.eq(200);
      const jwt = JSON.stringify(response.body.jwt);
      window.localStorage.setItem('jwt', jwt);
      expect(window.localStorage.getItem('jwt')).to.eq(jwt);
    }
  );
  // re-enable GET's
  cy.intercept(
    {method: 'GET'},
    (req) => {
      req.continue((res) => {})
    }
  );
}

@lpyfm
Copy link

lpyfm commented Mar 9, 2022

I had the same error in GitLab CI and cypress 4.0.1. Our e2e-tests sometimes succeeded and sometimes failed in GitLab, but always succeeded when run on a developer machine. It turns out that the issue was insufficient shared memory: Monitoring the /dev/shm file showed that, when the test cases failed, no (or close to none) shared memory was available. I was able to solve the issue by adding the following in /etc/gitlab-runner/config.toml:

[[runners]]
#
  [runners.docker]
    #
    shm_size = 536870912

Of course, 536870912 is just an example value, choose whatever you think is sensible. The important part is that you increase it from the default 16 MB.

I was very surprised that insufficient shm_size causes cross-origin errors, but I've repeated the tests with and without this fix a few times, so I'm very confident that this was the root issue in our case.

@papb
Copy link

papb commented Jul 1, 2022

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.

@papb
Copy link

papb commented Jul 1, 2022

I suspect @lpyfm's situation may be similar, maybe the error message was misleading too and the actual problem was something else.

@ZachEspositoPCTY
Copy link

For me the problem was apparently an administrator turning on certain policies - running in electron instead of chrome worked

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

No branches or pull requests