fysh711426 / UndetectedChromeDriver

GNU General Public License v3.0
166 stars 61 forks source link

Working with many browsers #2

Closed mgawrysiak closed 2 years ago

mgawrysiak commented 2 years ago

Hi, in first place grate job with this!

I hope u can help me with my problem, I have code from 2 days ago. I implemented your solution into wpf app. The idea is to have many instances of that app. Each instance have its own folder with own userDataPath (I need to save some data there)

For first 2 instances it works fine, but when I try to run 3rd instance it's opening browser with some url like folder/BrowserProfile or copy/BrowserProfile or 0.0.0.2/BrowserProfile, once it opened with 2 tabs, first has url '-' and second copy/BrowserProfile.

I'm setting browser profile path like that:

var userDataPath = $"{AppDomain.CurrentDomain.BaseDirectory}BrowserProfile";

Maybe u can help me with that?

fysh711426 commented 2 years ago

Thanks for your question, Opening multiple instances will cause conflicts. I need to study the reason.

fysh711426 commented 2 years ago

Are your ChromeOptions shared? This code will add something to the options, I found a problem with sharing, try using independent options for each instance.

mgawrysiak commented 2 years ago

I think you don't understand me, in my case it is one wpf application, inside this wpf application there is one instance of undetected chromedriver. Then I run this application (app.exe) from 3 folders:

I also noticed that when I run app.exe from the App3 folder, it opens a browser with the address 'copy/BrowserProfile' (on other computers it's 'folder/BrowserProfile' or '0.0.0.2/BrowserProfile' folder) and creates browser profile files in the App 1 folder

fysh711426 commented 2 years ago

I don't understand this

it opens a browser with the address 'copy/BrowserProfile' (on other computers it's 'folder/BrowserProfile' or '0.0.0.2/BrowserProfile' folder) and creates browser profile files in the App 1 folder

Maybe I need some screenshots.

mgawrysiak commented 2 years ago

image image image

mgawrysiak commented 2 years ago

Above screenshots are from scenario when I run app.exe from App3 folder

fysh711426 commented 2 years ago

Thanks, is there a problem with the url of GoToUrl(url)? I suggest you can log to see.

mgawrysiak commented 2 years ago

There is no GoToUrl yet, it is just initialization of browser (GoToUrl will trigger when I click button on wpf app)

fysh711426 commented 2 years ago

Sorry I can't reproduce, I tested with Console and everything works fine.

public static void Test()
{
    var driverExecutablePath = $@"D:\xxx\chromedriver.exe";

    var userDataDir = 
        $"{AppDomain.CurrentDomain.BaseDirectory}BrowserProfile";

    using var driver = UndetectedChromeDriver.Create(
        options: new ChromeOptions(),
        driverExecutablePath: driverExecutablePath,
        userDataDir: userDataDir);

    Console.ReadLine();
}

1653296735688

1653296695025

1653296247016

mgawrysiak commented 2 years ago

Ok, I will prepare some demo, and will add it to my repo.

fysh711426 commented 2 years ago

OK !!

fysh711426 commented 2 years ago

I think of some possibilities. The code mainly uses options.Arguments to start the chrome Process. Does your option use suspicious parameters?

var info = new ProcessStartInfo(options.BinaryLocation,
    string.Join(" ", options.Arguments));
// ...
var browser = Process.Start(info);
mgawrysiak commented 2 years ago

The problem was that there cannot be any spaces in userDataDir. The folder tree that I sent you before was just mockup, and in real data there was something like "C:\App - Copy\" and "C:\App1\", "C:\App2\" "C:\App 3\"

fysh711426 commented 2 years ago

Ok, I fixed it. thanks!