1

I want to add Google Chrome to path under the google-chrome name so that I can execute the following command: google-chrome --version.

First I tried with:

sudo ln -s /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome /usr/local/bin/google-chrome

But I kept receiving pop-ups with an error message (Google Chrome quit unexpectedly.). So I tried with --headless, i.e. made a script called /usr/local/bin/google-chrome and put the following there:

#!/bin/bash
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome "$@" --headless

But I'm getting: ContextResult::kTransientFailure: Failed to send GpuControl.CreateCommandBuffer.

Made a bit of googling, tried a solution with --disable-gpu, but it still does not work.

Note that /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version returns the correct version.

1
  • 3
    Why do you add --headless in the script? I just tried without that, and was able to successfully run script.sh --version.
    – nohillside
    Commented Oct 20, 2023 at 7:27

2 Answers 2

2

The precise error message reveals that it tries to open additional files relative to the binary you launched.

macbook:~ tripleee$ ln -s /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome ~/bin/google-chrome
macbook:~ tripleee$ google-chrome
dlopen /Users/tripleee/bin/../Frameworks/Google Chrome Framework.framework/Versions/120.0.6099.71/Google Chrome Framework: dlopen(/Users/tripleee/bin/../Frameworks/Google Chrome Framework.framework/Versions/120.0.6099.71/Google Chrome Framework, 0x0105): tried: '/Users/tripleee/bin/../Frameworks/Google Chrome Framework.framework/Versions/120.0.6099.71/Google Chrome Framework' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/tripleee/bin/../Frameworks/Google Chrome Framework.framework/Versions/120.0.6099.71/Google Chrome Framework' (no such file), '/Users/tripleee/bin/../Frameworks/Google Chrome Framework.framework/Versions/120.0.6099.71/Google Chrome Framework' (no such file).Abort trap: 6

The simple and obvious workaround is to make a wrapper script which calls the real binary at its original location instead, without the --headless option.

#!/bin/sh
exec "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" "$@"

Save as /usr/local/bin/google-chrome (or wherever you want it), chmod a+x, and go.

Prefer /bin/sh over /bin/bash as it is significantly smaller, and use exec to avoid having the shell hang around waiting for Chrome when it's not going to do anything more after Chrome exits.

0

If you only need it in the path so that you can run the --version command, just do a

PATH="/Applications/Google Chrome.app/Contents/MacOS:$PATH"
rehash
"Google Chrome" --version 

Aside from this, I would start chrome from the command line by doing a

open -a "Google Chrome".app

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .