cypress: Getting Error: Script error. (:0) - How to resolve?

Current behavior:

Cypress test run fails on Chrome in before() with a cryptic error message:

Error: Script error. (:0)

Because this error occurred during a ‘before all’ hook we are skipping the remaining tests in the current suite: ‘Pets - Feed item’

Please see this screenshot:

image

Desired behavior:

A detailed error message should appear and should include clear instructions on how to resolve the problem.

Steps to reproduce: (app code and test code)

I’ve not been able to reproduce based on cypress-test-tiny repo so I’ve created a private repo containing a full test suite. I’ve sent emailed instructions on how to access it to support@cypress.io.

To reproduce using said repo, please:

  1. Clone to Ubuntu.
  2. Run npx cypress open.
  3. Run this spec file: sanity/pets/feed_item.spec.js

Versions

Cypress v3.4.0 Ubuntu 16.04 LTS Chrome 75

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

The best workaround to see the source of error right now on the Guardian website for example is:

  1. Look at the current error - keep DevTools open while the test is running
Screen Shot 2019-08-15 at 11 31 43 AM
  1. Set in cypress.json
{
  "chromeWebSecurity": false
}

Then rerun the test with DevTools open again and it should see better errors

Screen Shot 2019-08-15 at 11 32 34 AM
  1. Notice that the scripts throwing hundreds of errors come from domain assets.guim.co.uk so add it to the blacklists in cypress.json
{
  "chromeWebSecurity": false,
  "blacklistHosts": "assets.guim.co.uk"
}
  1. This might reveal more errors coming from other locations.
Screen Shot 2019-08-15 at 11 36 26 AM
  1. Add the new source of errors to cypress.json
{
  "chromeWebSecurity": false,
  "blacklistHosts": ["assets.guim.co.uk", "interactive.guim.co.uk"]
}

and finally the site loads

Screen Shot 2019-08-15 at 11 38 16 AM

Having the same issue but i managed to find a workaround, in my case at least. Try setting "chromeWebSecurity": false in cypress.json. Before disabling web security i was getting Error: Script error. (:0), after disabling it cypress was logging the correct error.

@urig Cypress’s current implementation is to fail on uncaught exceptions, as we don’t see this as an optimal workflow for an application. In these cases, we offer the option to opt out of failing on these uncaught exceptions with a listener. https://on.cypress.io/catalog-of-events#Uncaught-Exceptions

Unfortunately, this listener doesn’t trigger when uncaught errors are thrown from 3rd party code, which has caused some frustration for users. We do intend to fix this - https://github.com/cypress-io/cypress/issues/987

I’ll bring up this issue with our engineering team and see what we can do. Currently, these issues are not in our current sprint to be fixed.

Hi @jennifer-shehane and thanks.

I recognize that an error in the application is at the root of the issue and, using the chromeWebSecurity: false workaround, I think we’ve been able to find out where this error is coming from. Several people on our side are working on fixing the error (it likely comes from a rather complex Google Tag Manager system we have embedded)

At the same time, the other side of the issue is that Cypress should not break the spec file like this. From our end users’ perspective the JS error is transparent and does not negatively affect UX. So having Cypress crash about half of a sanity E2E tests in this scenario does not make for a good testing experience.

In short - Is there a time line for changing this behavior in Cypress?

Thanks, urig

@sebike88 thanks for the workaround. It sort of worked. I think the difference is that now I can see the underlying error coming from app code.