I'm using following code to iterate over a list of browsers executable paths and start each of them:
foreach (var browser in browsers)
{
var proc = new Process();
proc.StartInfo.FileName = browser.ExecutablePath;
proc.StartInfo.Arguments = "http://google.com";
proc.Start();
proc.WaitForExit();
Console.WriteLine(proc.ExitCode.ToString());
proc.Close();
}
What is should do is: it should open browser window with google.com loaded and stop the application until the window is closed. And it works fine for both IE and Firefox, but fails with Chrome.
For Chrome proc
is in Exit
state just after launching the browser, when the window is still active and visible.
I tried using some of chromium command line switches, including --new-window
and --single-process
but with no success.
Question is, how can I force Google Chrome to run in the process it is started in, so it would be possible to wait until window is closed?
Update
Just to clarify the question:
Launch Command Prompt, then enter "start chrome" into the window to open Google Chrome.
Type "chrome" without quotation marks to run Chrome from the terminal. Chrome is installed in your binary path, so no special directory is required.
Here's how to do it. To run Google Chrome in Incognito mode, the browser supports a special command line switch, -incognito, which forces the browser to start with the Incognito window opened instead of the regular browsing session. Note the hyphen before 'incognito'.
Chrome by default is constantly running in background because of its default settings. Change this option to unchecked:Settings > Show advanced > System > 'Continue running background apps when Google Chrome is closed'
So you have to make sure Chrome is closed before you run it again by your code. That works for me.
Chrome have one 'mother process' and some child processes. The problem is that if you run chrome using your code you are trying to create new instance of 'mother process' but the existing one won't let you do it. She'll instantly kill your new process and create her own child instead. That's how it works...
So, all you need is figure out how to run another 'chrome mother process' and prevent the previous hug from killing her ;P
I figure out this solution:
Run new chrome process with this parameter --user-data-dir="%temp%/random_name"
. This means that you are opening chrome with new user profile.
Advantages:
Disadvantages:
So, maybe you should look for sth in this direction...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With