cypress: file download not working in electron

Current behavior

This appears to be the same issue as described in https://github.com/cypress-io/cypress/issues/14747

However I am getting it in cypress 8.6.0

It eventually bombs out with

Error: ERR_FAILED (-2) loading 'https://docs.google.com/uc?export=download&id=1qnZDkUKzYKcgsrQlflMYtiQL5U1rmP_h'
    at rejectAndCleanup (electron/js2c/browser_init.js:161:7486)
    at Object.stopLoadingListener (electron/js2c/browser_init.js:161:7861)
    at Object.emit (events.js:376:20)
{
  errno: -2,
  code: 'ERR_FAILED',
  url: 'https://docs.google.com/uc?export=download&id=1qnZDkUKzYKcgsrQlflMYtiQL5U1rmP_h'
}
Error: ERR_FAILED (-2) loading 'https://docs.google.com/uc?export=download&id=1qnZDkUKzYKcgsrQlflMYtiQL5U1rmP_h'
    at rejectAndCleanup (electron/js2c/browser_init.js:161:7486)
    at Object.stopLoadingListener (electron/js2c/browser_init.js:161:7861)
    at Object.emit (events.js:376:20)

And returns you to the command line my downloads folder is empty

I ran into the same problem when trying to write a test in my automation framework at work and thought it might be a problem with the app (or proxy) but this seems to indicate otherwise.

Am I doing something wrong here?

Desired behavior

Allow me to download the file

Test code to reproduce

To reproduce:

  1. Create a new NPM project
  2. Install Cypress
  3. Create a spec file as follows
describe('test', () => {
    it('downloads', () => {
        cy.visit('https://www.appsloveworld.com/sample-excel-data-for-analysis/')
        cy.get('.Downloadbutton')
        .eq(0)
        .click();
    });
});
  1. Run the spec file in the runner

Cypress Version

8.6.0

Other

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 6
  • Comments: 15 (3 by maintainers)

Most upvoted comments

I am getting the same issue in Cypress 12.14.0

Cypress:        12.14.0                                                                        │
Browser:        Electron 106 (headless)                                                        │
Node Version:   v16.0.0

I am getting seemingly the same problem:

Trace: The new-window event is deprecated and will be removed. Please use contents.setWindowOpenHandler() instead.
    at Object.log (node:electron/js2c/browser_init:225:603)
    at emitDeprecatedNewWindowEvent (node:electron/js2c/browser_init:185:1303)
    at openGuestWindow (node:electron/js2c/browser_init:185:1685)
    at EventEmitter.<anonymous> (node:electron/js2c/browser_init:165:14118)
    at EventEmitter.emit (node:events:527:28)
ERR_FAILED (-2) loading 'about:blank#blocked'
Error: ERR_FAILED (-2) loading 'about:blank#blocked'
    at rejectAndCleanup (node:electron/js2c/browser_init:165:7500)
    at EventEmitter.stopLoadingListener (node:electron/js2c/browser_init:165:7875)
    at EventEmitter.emit (node:events:527:28)

And it stops going over the rest of tests. We are debugging our own web app deployed to a public URL. Our code does not use new-window anywhere nor opens about:blank nor about:blank#blocked. All test steps can be repeated manually without problems.

The versions:

Cypress:        12.0.2
Browser:        Electron 106 (headless)
Node Version:   v14.21.2 (/Users/eugene/.nvm/versions/node/v14.21.2/bin/node)

It does seem like there is a bug here. When we are doing the win.loadURL for the child BrowserWindow, we aren’t catching exceptions, and so loading a broken URL just crashes Cypress. Need more investigation on what to do here, but that does seem like the likely culprit. Possibly it’s not just broken URLs, but any URL that causes an immediate file download.

We have a reproduction from #24354 in this repo: https://github.com/aaron-qa/cy-error-repoduce

I have the same issue downloading a PDF in a new tab crashes Electron. As a result it is impossible to run these kind of tests in CI. This issue doesn’t happen with other browsers.