Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !11878
An error occurred while fetching the assigned milestone of the selected merge_request.

fix: browser selection via env variable

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/FloydJohn/fix-browser-env into main 3 years ago
  • Overview 17
  • Commits 3
  • Pipelines 0
  • Changes 1

Created by: FloydJohn

Hi everyone,

this PR fixes the opening of a browser of choice, selected through the BROWSER environment variable, when starting a generated project.

After migrating to CRA v5.x the feature stopped working (see #11873, #11844, #11942, #11917, #12275).

Browsing the documentation for the open@8.4.0 package (available here) I noticed that the syntax for opening an URL using a specified browser was updated.

This PR includes two small changes:

  • The updated syntax for opening a browser is now used
  • Since the open package natively supports passing an array of arguments to the application, we no longer need to concatenate the arguments before the call

To test this feature I followed this test plan:

  • Create a new .env file in the template project, containing for example the value BROWSER=google-chrome-stable. The browser name could change based on OS or linux distro.
  • Start the template project with npm run start. A new tab should open in the specified browser.
  • Stop the process and remove the newly created .env file.
  • Start again the project with npm run start: it should open on the default browser.
Compare
  • version 1
    bf17dda7
    2 years ago

  • main (HEAD)

and
  • latest version
    bf17dda7
    3 commits, 2 years ago

  • version 1
    bf17dda7
    3 commits, 2 years ago

1 file
+ 3
- 6

    Preferences

    File browser
    Compare changes
packages/react-dev-utils/openBrowser.js
+ 3
- 6
  • View file @ 8e4238a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -117,15 +117,12 @@ function startBrowserProcess(browser, url, args) {
@@ -117,15 +117,12 @@ function startBrowserProcess(browser, url, args) {
browser = undefined;
browser = undefined;
}
}
// If there are arguments, they must be passed as array with the browser
if (typeof browser === 'string' && args.length > 0) {
browser = [browser].concat(args);
}
// Fallback to open
// Fallback to open
// (It will always open new tab)
// (It will always open new tab)
try {
try {
var options = { app: browser, wait: false, url: true };
var options = {
 
app: { name: browser, arguments: args },
 
};
open(url, options).catch(() => {}); // Prevent `unhandledRejection` error.
open(url, options).catch(() => {}); // Prevent `unhandledRejection` error.
return true;
return true;
} catch (err) {
} catch (err) {
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Administrator
Reference:
Source branch: github/fork/FloydJohn/fix-browser-env

Menu

Explore Projects Groups Snippets