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

Callback is called immediately when opening a webpage in chrome with chrome already open #18

Open
sgen opened this issue Sep 28, 2015 · 11 comments

Comments

@sgen
Copy link

sgen commented Sep 28, 2015

Reproduce by opening chrome and then calling opn('http://google.com/', function() { console.log('closed'); });

The callback is immediately called and chrome remains open.

@sindresorhus
Copy link
Owner

What Node.js and OS version are you on?

Works correctly for me on OS

If you're on Windows, please read the docs:

On Windows you have to explicitly specify an app for it to be able to wait.

@sgen
Copy link
Author

sgen commented Oct 2, 2015

node version: 0.12.7
Im running ubuntu 15.04

@sindresorhus
Copy link
Owner

Works correctly for me on that exact same setup.

@sgen
Copy link
Author

sgen commented Oct 2, 2015

Im running chrome 45.0.2454.101 (Official Build) (64-bit).

Tried reinstalling chrome and Im still having the same issue.

Just to be clear: I open a single chrome window, run 'node index.js' (https://gist.github.com/sgen/3538b746bfa23199bf91).

Chrome opens a new tab in the same window and 'closed' is immediately printed to the terminal.

@sindresorhus
Copy link
Owner

I believe, I just can't reproduce with the exact same setup and code.

Are you sure you're on the latest opn version?

@sgen
Copy link
Author

sgen commented Oct 2, 2015

Yes I am (3.0.2)

@MeoMix
Copy link

MeoMix commented Oct 10, 2015

This happens for me as well. Callback is immediate.

Chrome 45.0.2454.101 m (x86), v3.0.2 of opn on Windows 7 x64

Code looks like:

opn('http://www.google.com'`, {
  app: 'Chrome',
}, function(error) {
  console.log('Error:', error);
});

Error is undefined

@321ckatz123
Copy link

This is obviously not an answer as I am just trying to give more information to people to hopefully help. That being said this also doesn't seem to be an issue with opn itself and, while useful for people to find, should probably be closed.

Same issue in C#
http://stackoverflow.com/questions/19552815/open-chrome-from-command-line-and-wait-till-its-closed

A more in depth explanation into what is happening
http://superuser.com/questions/461552/why-are-there-multiple-chrome-instances-running-even-though-i-only-have-one-wind

FWIW, the --user-data-dir flag is supposed to solve this, but I couldn't get that to work on any language, so if anyone is able to get this to work, please post for others to see (or if relatively trivial, create a pull for @sindresorhus).

@SkyLeite
Copy link

Bumping this as it's still happening. Any developments or at least ways to circumvent this?

@hyalkaf
Copy link

hyalkaf commented Jan 15, 2018

In my case, I'm trying to open an Excel file. Whenever I open the file while another file is open, it will call the callback immediately and not wait for the file to be closed. I want to detect when the file is closed so that I can read it afterwards. I created a repo for this issue with excel files if anyone interested in reproducing it: https://github.com/hyalkaf/nodejs-opening-multiple-excel-file-problem-opn

@jogibaeratvega
Copy link

Hi,
I'm struggeling with an similar issue. I want to open a ".MSG"-File with the open-Library.

Sadly the callback is called immedietly after the window opened if an instance of outlook is already running. This also initially occurred for excel files. I then set the app property ("EXCEL") which solved the problem.

I think the problem is with that "/f" argument which is used to open an msg file. But without that argument I'm not able to open my ".MSG" file.

Versions:
open - 6.2.0

Code:
open(program.filepath, {wait: true, app:["OUTLOOK", "/f"] }).then(() => { // Gets called directly after the window opens (if no outlook instance was running) });

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

7 participants