Created by: clarkbw
This fixes #1826 (closed)
The problem is that if Chrome is currently running it doesn't matter that you have another browser set as your default, Chrome will be used.
I only noticed this recently as I haven't been running Chrome as much anymore and the script started opening Firefox by default.
Testing
To test, use the following test script (from the README).
// openBrowser.test.js
var openBrowser = require('./openBrowser');
if (openBrowser('http://localhost:3000')) {
console.log('The browser tab has been opened!');
}
node openBrowser.test.js
Before this change:
- With Chrome running this would open up Chrome even if it is not the default browser
- Chrome reuses the same tab on OS X, a nice feature!
After this change:
- With Chrome running, but not set as the default, this opens the default (Firefox, Safari, Chrome Canary, or other)
- With Chrome set as the default browser the tab reuse feature continues to work as before
Notes
- I added
wait: false
to the options because it was causing the script to hang waiting on the browser process to exit, which is unlikely. Here are the option notes fromopn
Wait for the opened app to exit before fulfilling the promise. If false it's fulfilled immediately when opening the app.
- I updated the README section slightly to remove an unneeded import