cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.66k stars 3.16k forks source link

Clicking "View App Data" on Linux crashes Cypress #20774

Open flotwig opened 2 years ago

flotwig commented 2 years ago

To reproduce:

  1. Open Cypress.
  2. Click “View App Data” via the context menu.
  3. App crashes.

Desired behavior: View App Data works, and errors with View App Data are gracefully handled.

image

jennifer-shehane commented 2 years ago

I wasn't able to reproduce this on a Mac in 9.5.1.

viniciuspietscher commented 2 years ago

Hi @flotwig, I would like to help but I was not able to reproduce the error on my environment.

What can I do to try to help?

cypress_000 cypress

vinicius@arch my-app(main)$ uname -a Linux arch 5.17.1-arch1-1 #1 SMP PREEMPT Mon, 28 Mar 2022 20:55:33 +0000 x86_64 GNU/Linux

flotwig commented 2 years ago

@viniciuspietscher hmm, what is your DE? how are you launching Cypress?

viniciuspietscher commented 2 years ago

@flotwig I'm using i3, I opened inside the project folder on the terminal using the command: node_modules/.bin/cypress open

jonhermansen commented 2 years ago

I spent some time today reproducing and debugging this issue.

The "crash" as it were would actually be fixed by upgrading to the upstream opn@6.0.0 library, However, instead of the Cypress application closing, there would be no visible error printed and no new window would open when "View App Data" is clicked.

I believe that the root cause of the issue, is that there is no browser installed on the reporter's machine. Anyone should be able to reproduce this problem simply by uninstalling Firefox, Chromium, Chrome, etc. from their minimal Linux system. There is a list of browsers checked for existence, which is defined in the local version of xdg-open provided by the opn library.

@flotwig: I think the issue would be resolved by running pacman -Syu firefox (assuming you are running Arch)

@viniciuspietscher: I think that you can not reproduce the issue because you do have one of the binaries referenced by xdg-open.

I am not sure exactly what should be done with this bug, perhaps it would be nice to at least catch the exception and print out a usable error, i.e. "This feature requires a browser to be installed. We suggest installing x". I did notice that the version of opn in use, is a fork that exists under the cypress-io organization, with some modifications for running on darwin. That may complicate upgrading to the latest upstream version of the library. @brian-mann may want to take a look, since he made some changes to your forked version.

In addition, the opn library has been superceded by a new package called open, and looking at its README, it mentions that there is an alternative that can be used if your app is running under Electron:

If you need this for Electron, use shell.openPath() instead.

Hope this helps resolve the issue somewhat. If anyone has suggestions on what could be done next to resolve the bug, let me know! Thanks.

jonhermansen commented 2 years ago

Small update: it would also be helpful to update to a later version of the xdg-open script in general.

When testing this functionality under GNOME 3, I found that xdg-open is trying to execute gnome-open which does not seem to be included in version 3. It looks as though gio open is now the correct way to open a file browser according to the upstream source: https://cgit.freedesktop.org/xdg/xdg-utils/tree/scripts/xdg-open.in#n164

flotwig commented 2 years ago

Thanks for spending time getting to the root of this issue @jonhermansen

I believe that the root cause of the issue, is that there is no browser installed on the reporter's machine.

Interesting, I did have Firefox (and others) in my path at the time that I encountered this. Why would it be related to browsers anyways?

There is a list of browsers checked for existence, which is defined in the local version of xdg-open provided by the opn library.

Electron also uses xdg-open. Here's the relevant location in Electron where xdg-open is run: https://github.com/electron/electron/blob/31c2b5703a75a5ff2bf0e68f472d9002fe866bfb/shell/common/platform_util_linux.cc#L265 I'm not totally sure if Electron bundles xdg-open or if it uses the system's xdg-open.

If you need this for Electron, use shell.openPath() instead.

Hope this helps resolve the issue somewhat. If anyone has suggestions on what could be done next to resolve the bug, let me know! Thanks.

We also use shell.openExternal() elsewhere, I'm not sure why opn was chosen for this use case. Best path forward would be to drop our usage of opn and switch to shell.openPath() like you say, I think.

If you want to open a PR to fix this and ping me for a review, that would be very welcome.

github-actions[bot] commented 1 year ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

MikeMcC399 commented 1 year ago

Seeing this crash on Cypress 12.12.0 on Ubuntu 22.04. Browsers Chrome and Firefox are installed.

Exited with code 4
Error: Exited with code 4
    at ChildProcess.<anonymous> (<embedded>:3139:421199)
    at Object.onceWrapper (node:events:642:26)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Socket.<anonymous> (node:internal/child_process:451:11)
    at Socket.emit (node:events:527:28)
    at Pipe.<anonymous> (node:net:709:12)
jonhermansen commented 1 year ago

Seeing this crash on Cypress 12.12.0 on Ubuntu 22.04. Browsers Chrome and Firefox are installed.

Exited with code 4
Error: Exited with code 4
    at ChildProcess.<anonymous> (<embedded>:3139:421199)
    at Object.onceWrapper (node:events:642:26)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Socket.<anonymous> (node:internal/child_process:451:11)
    at Socket.emit (node:events:527:28)
    at Pipe.<anonymous> (node:net:709:12)

@MikeMcC399 Can you check if your BROWSER/DISPLAY environment variables are set, and also if you have any of these executables in your PATH?

BROWSER=links2:elinks:links:lynx:w3m
    if [ -n "$DISPLAY" ]; then
        BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
    fi

The logic for how Cypress is attempting to pick a browser is here. Maybe something is off with your browsers command name. Or could be something else entirely. Its been a while since I looked at this issue.

jonhermansen commented 1 year ago

Also, your terminal may have different environment variable values set than what is available to Cypress. Depends on how you are launching the Cypress UI.

MikeMcC399 commented 1 year ago

I was able to reproduce on Ubuntu 22.04 and 23.04, however on Ubuntu 20.04 View App Data worked correctly.

I will do a clean install of Ubuntu 22.04 and see what happens there.

MikeMcC399 commented 1 year ago

This issue is reproducible with Cypress 12.12.0 (Edit: also on 12.17.0) on a clean install of Ubuntu 22.04.2 LTS using Node.js 18.16.1.

Install Ubuntu 22.04.02 from iso on VMware Workstation.

Install prerequisites:

sudo apt install curl
sudo apt install make
sudo apt install git
curl -L https://bit.ly/n-install | bash

then

mkdir cy-view-app-data
cd cy-view-app-data
git init
npm init -y
npm install cypress@12.12.0 -D
npx cypress open

In Cypress desktop app Click on File > View App Data

which then crashes with the console output:

Exited with code 4
Error: Exited with code 4
    at ChildProcess.<anonymous> (<embedded>:3139:421199)
    at Object.onceWrapper (node:events:642:26)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Socket.<anonymous> (node:internal/child_process:451:11)
    at Socket.emit (node:events:527:28)
    at Pipe.<anonymous> (node:net:709:12)

On Ubuntu it should be displaying the contents of ~/.config/Cypress/cy/production

Check with

ls -al ~/.config/Cypress/cy/production
nautilus ~/.config/Cypress/cy/production
MikeMcC399 commented 1 year ago

@jonhermansen Thanks for your debugging steps! I would like to leave this now to the Cypress.io team to look at as I have not installed any additional browsers or modified any environment variables. The Cypress desktop app otherwise works correctly and is able to run tests in Electron and Firefox. Hopefully they will also be able to reproduce and fix the issue.

MikeMcC399 commented 1 year ago

This issue remains unresolved in cypress@13.1.0 cypress@13.6.2. The Cypress desktop app crashes using "View App Data" on Ubuntu 22.04.

In Cypress desktop app (npx cypress open) Click on File > View App Data

console output stack trace for cypress@13.1.0:

Exited with code 4
Error: Exited with code 4
    at ChildProcess.<anonymous> (<embedded>:3180:421654)
    at Object.onceWrapper (node:events:642:26)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Socket.<anonymous> (node:internal/child_process:451:11)
    at Socket.emit (node:events:527:28)
    at Pipe.<anonymous> (node:net:709:12)

Workaround

nautilus ~/.config/Cypress/cy/production
TahirMehmood8082 commented 8 months ago

This issue remains unresolved in cypress@13.6.1. The Cypress desktop app crashes using "View App Data" on Ubuntu 22.04.

Cypress package version: 13.6.1
Cypress binary version: 13.6.1
Electron version: 25.8.4
Bundled Node version: 18.15.0
Done in 0.16s.
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:    22.04
Codename:   jammy