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

Closes cmd/powershell when opening url #236

Closed
nutgaard opened this issue Mar 21, 2021 · 14 comments · Fixed by #250
Closed

Closes cmd/powershell when opening url #236

nutgaard opened this issue Mar 21, 2021 · 14 comments · Fixed by #250

Comments

@nutgaard
Copy link

Lib version: 8.0.3
Nodejs: 15.11.0
Window: Win 10 build 19042.804

Steps to reproduce;

const open = require('open');
open('http://github.com');

Then: node index.js

Expected behaviour;

  1. Opens url in default browser
  2. Cmd/powershell process is kept running.

Actual behaviour:

  1. Opens url in default browser
  2. Kills cmd/powershell process
@sindresorhus
Copy link
Owner

Is this a new issue in 8.0.3? If not, can you test some older versions?

@nutgaard
Copy link
Author

Just tested it, and was on my way to update the issue. :D

open@8.0.2 works as expected.

@sindresorhus
Copy link
Owner

// @kykint

nutgaard added a commit to nutgaard/gitnext that referenced this issue Mar 21, 2021
open@8.0.3 had an issue on windows causing cmd/powershell to close.
Tracked here; sindresorhus/open#236
@kykint
Copy link
Contributor

kykint commented Mar 21, 2021

According to your code - you don't use "wait: true" option. Without this option powershell shouldn't keep running.
https://github.com/nutgaard/gitnext/blob/e838ecc33cf456f816a003588c136491df3efc50/src/ui/action-selector.tsx#L53
https://github.com/sindresorhus/open#wait
"If false it's fulfilled immediately when opening the app."

@nutgaard
Copy link
Author

I could understand it exiting out of the node-script sure.
But killing the entire terminal-process seems a bit like over-reaching to be honest, but maybe that has been the expected behaviour all along?
Anyways, I'll test it out with {wait: true}.

As a side-note, shouldn't this have been a major-version bump? Pretty drastic change in behaviour for patch-bump.

nutgaard added a commit to nutgaard/gitnext that referenced this issue Mar 21, 2021
@nutgaard
Copy link
Author

nutgaard commented Mar 21, 2021

Done some more testing outside of my project to easier isolate and test.
By the looks of it then both of the snipplets below kills the cmd process when using open@8.0.3;

const open = require('open');
open("http://github.com", { wait: true });
const open = require('open');

(async () => {
  await open("http://github.com", { wait: true });
})();

EDIT:
Also tested by monkey-patching open@8.x.x. into open-cli which yields these results.

Version 8.0.2:
With wait: true; browser opens and script waits for browser to close before continuing.
With wait: false; browser opens and script continues right away.

Version 8.0.3:
With wait: true; browser opens, and cmd window is gone
With wait: false; browser opens, and cmd window is gone

nutgaard added a commit to nutgaard/gitnext that referenced this issue Mar 21, 2021
wait-flag proved ineffective, locking version to 8.0.2
Tracked here; sindresorhus/open#236
@kykint
Copy link
Contributor

kykint commented Mar 21, 2021

I understood the problem. cmd window is not killed - It's just hidden. Will try to fix it

@kykint
Copy link
Contributor

kykint commented Mar 21, 2021

Maybe the best way is just add windows-only option, like "hiddenTerminal". Because there is another situation, when node.js application is started not from cmd. Then powershell creates one more window and it appears on top of all other applications and it is also not good. I can't find better solution yet.

@nutgaard
Copy link
Author

I don't know which situations you're referring to (electron-app? pkg-bundled app?).
But unless there is a reliable way of identifying those situations, then that seems like a better solution.

kykint pushed a commit to kykint/open that referenced this issue Mar 21, 2021
kykint pushed a commit to kykint/open that referenced this issue Mar 21, 2021
@kykint
Copy link
Contributor

kykint commented Mar 21, 2021

I tried to find a way, how to determine environment, but didn't find :( So, I've created a PR #238 with an addition option.

@adamtay
Copy link

adamtay commented Mar 24, 2021

Also encountered this issue on 8.0.4 with cmd disappearing when opening url. Downgrading to 8.0.2 has resolved it.

tromgy added a commit to tromgy/npm-tree that referenced this issue Mar 31, 2021
- change from `execFile` to `exec`, as the former doesn't work on Windows for `npm`
- fix the **open** version to 8.0.2, as the newer ones have an open [issue](sindresorhus/open#236) on Widnows
- change the tree bullets, as the right/down triangles are not fixed-width in monospace font(s) on Windows, messing up alignment.
@imagitama
Copy link

Same issue for me and downgrading to 8.0.2 fixes it (I was on 8.0.5). Using Ubuntu for Windows and opening a URL in default browser with no options

@AnWeber
Copy link

AnWeber commented Apr 19, 2021

I don't know which situations you're referring to (electron-app? pkg-bundled app?).

I use open in my vscode extension to open the browser for the OAuth2 authorization code flow. On some installations this terminates the extension host of vscode, but not on all machines. The extension is vscode-httpyac. I would prefer a setting to enable/ disable the closing mechanism. Downgrade to 8.0.2 fixed it for me.

@alan-agius4
Copy link
Contributor

Had a similar report in Angular CLI angular/angular-cli#20807

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

Successfully merging a pull request may close this issue.

7 participants