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

Figure out how to pass a Node script to BROWSER #1533

Closed
gaearon opened this issue Feb 12, 2017 · 6 comments
Closed

Figure out how to pass a Node script to BROWSER #1533

gaearon opened this issue Feb 12, 2017 · 6 comments

Comments

@gaearon
Copy link
Contributor

gaearon commented Feb 12, 2017

We added support for BROWSER env variable that is interpreted by OS-specific command.
On OS X, it runs open http://url.com -a <BROWSER>.

However I'm not sure how to make it execute a Node script, and if it's even possible. That would be the best for allowing use cases like #1096 and #1450. It would be awesome to investigate how to get it working with a Node script (my naïve attempt at pointing it to a shell script with node env didn't seem to work), and maybe implement some custom handling for JS extension if we don't find a solution.

@GAumala
Copy link
Contributor

GAumala commented Feb 13, 2017

I think that the best choice is to spawn a child process to execute the node script if the BROWSER string ends in ".js". It is the easiest way to support al operating systems.

react-dev-utils uses opn to open the browser. This module uses the command open on OS X, start on Windows and xdg-open on other platforms. I only use Linux, so I only know about xdg-open, but I believe the other tools are designed in a similar way.

xdg-open is meant to be used in desktop sessions, like when the user double clicks a file. You click a photo, your photo viewer is opened. You click a video, your media player is opened. In settings, the user can choose what programs to use for each type of file. For security reasons, it is strongly discouraged to execute scripts when double clicked, opening the file with a text editor is a much better choice. This is what probably every Linux desktop environment does by default, since users could be tricked into double clicking malicious scripts.

Handling the ".js" extension is much easier and secure.

@gaearon
Copy link
Contributor Author

gaearon commented Feb 13, 2017

Sounds good. Want to send a PR to support this?

@GAumala
Copy link
Contributor

GAumala commented Feb 13, 2017

Sure, I'll work on it this week.

@gaearon
Copy link
Contributor Author

gaearon commented May 15, 2017

Fixed in #1590.

@gaearon gaearon closed this as completed May 15, 2017
@sunknudsen
Copy link

Is it possible to use the BROWSER env variable to open Firefox using a given profile?

Looking for an equivalent to /Applications/Firefox.app/Contents/MacOS/firefox-bin -p development.

Trying to limit the reach of browser extensions such as React and Redux that run on all tabs and have access to all our browsing data.

@sunknudsen
Copy link

Found a way to achieve this using the script option on MacOS.

The following works if a development profile has been created.

https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_starting-the-profile-manager

Set BROWSER=open.js in .env.

// Content of open.js
const { spawn } = require('child_process');

spawn(
  '/Applications/Firefox.app/Contents/MacOS/firefox-bin',
  ['-p', 'development', process.argv[2]],
  { detached: true }
);
process.exit(0);

Then run npm start as usual.

@lock lock bot locked and limited conversation to collaborators Jan 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants