Running chrome with command line parameters

I am using systray and open to open chrome browser on a url (mostly served by the golang server itself…), e.g.:

func main() {
	fmt.Println("Quando Go Server started")
...
	go server.ServeHTTPandIO(handlers)
	systray.Run(onReady, nil)
}

func onReady() {
	systray.SetIcon(icon.Data())
	systray.SetTitle("Quando")
	systray.SetTooltip("Quando - noCode Toolset")
	sysEditor := systray.AddMenuItem("Editor", "Open Editor")
	sysClient := systray.AddMenuItem("Client", "Open Client")
	systray.AddSeparator()
	sysDashboard := systray.AddMenuItem("Dashboard", "Open Dashboard")
	systray.AddSeparator()
	sysGithub := systray.AddMenuItem("Quando:Github", "Open Quando -> Github")
	systray.AddSeparator()
	sysQuit := systray.AddMenuItem("Quit", "Stop the server")
	go func() {
		for {
			select {
			case <-sysQuit.ClickedCh:
				fmt.Println("Exiting...")
				systray.Quit()
			case <-sysEditor.ClickedCh:
				open.StartWith("http://127.0.0.1/editor", "chrome")
			case <-sysClient.ClickedCh:
				open.StartWith("http://127.0.0.1/client", "chrome")
			case <-sysDashboard.ClickedCh:
				open.StartWith("http://127.0.0.1", "chrome")
			case <-sysGithub.ClickedCh:
				open.Start("https://github.com/andrewfstratton/quando")
			}
		}
	}()

However, there doesn’t seem to be any way to pass in command line parameters - I would like to pass in ‘–allow-insecure-localhost’.

Does anyone know of a (cross platform) package/option similar to open-lang open that allows specifying the application as chrome AND passing parameters :slight_smile:

Note: I know that lorca does this - but also provides much more than I need…I am considering stripping ‘LocateChrome’ from lorca and using that…

Thank you in advance - Andy

@Andrew_Stratton I suggest you use the os/exec library. You can do something like this:

package main

import (
    "log"
    "os/exec"
)

func main() {
    output, err := exec.Command("chrome", "--allow-insecure-localhost").Output()
    if err != nil {
        log.Fatal(err)
    }

fmt.Println(string(out))
}

Thank you Brandon

I have just been down that route myself - but using lorca to find chrome, since chrome isn’t in PATH by default in windows (and I need very easy deployment/setup). i.e.

	loc := lorca.LocateChrome()
	cmd := exec.Command(loc, "--new-window", "--allow-insecure-localhost", "http://127.0.0.1"+suffix)
	err := cmd.Run()
	if err != nil {
		fmt.Println(err)
	}

This partly works - i.e. opens a new window - but it doesn’t enable insecure localhost when chrome is already running, since it reuses the existing application.

I think I will have to consider using a profile - so this becomes a chrome specific issue…

Thank you - Andy

Using user-data-dir allows a different profile so that a new instance of chrome is run, e.g. (for windows) changing the previous example to include:

	cmd := exec.Command(loc, "--new-window", "--user-data-dir=C:\\chrome_dir", "--allow-insecure-localhost", "http://127.0.0.1"+suffix)