Forked from thgiang/gist:e222f036806f126f51a0b75a81956c20
Created
March 2, 2021 16:31
-
-
Save 8bu/2731e8bdaae48373ebc8ccbfc3e2fa23 to your computer and use it in GitHub Desktop.
Control real chrome browser without notice: "Chrome is being controlled by automated test software"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Random rd = new Random(); | |
string remote_port = rd.Next(9000, 9999).ToString(); | |
// Open real Chrome | |
Process process = new Process(); | |
process.StartInfo.UseShellExecute = true; | |
process.StartInfo.FileName = "chrome"; | |
process.StartInfo.Arguments = "https://thgiang.com --load-extension=\"C:\\Users\\Admin\\Desktop\\my_extension\" --disable-gpu --new-window --remote-debugging-port=" + remote_port + " --user-data-dir=\"C:\\Profile\" --proxy-server=\""+proxy+"\" --disable-infobars --disable-notifications --window-size=1366,768"; //--window-position=0,0 --window-size=1200,800 --disable-images | |
process.Start(); | |
Thread.Sleep(1000); | |
var options = new ChromeOptions { DebuggerAddress = "localhost:" + remote_port }; | |
ChromeDriverService sv = ChromeDriverService.CreateDefaultService(); | |
sv.HideCommandPromptWindow = true; | |
var driver = new ChromeDriver(sv, options); | |
// Close all current tabs | |
while (true) | |
{ | |
var tabs = driver.WindowHandles; | |
if (tabs.Count > 1) | |
{ | |
try | |
{ | |
driver.SwitchTo().Window(tabs[1]); | |
driver.Close(); | |
driver.SwitchTo().Window(tabs[0]); | |
} | |
catch { } | |
} | |
else | |
{ | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment