0

I have some Chrome profiles in which I have my different accounts logged in. I'm writing a multi-threaded script that will run each profile using launch_persistent_context so that I'm already logged in and script starts working from thereon.

I'm using Playwright, on Windows 10.

Here's my code snippet which works for only one profile (I'm not sure why, because the profile it opens is Profile 1 in my file-path, however the script works only for the parent directory, and that too for only a single profile)

def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch_persistent_context(
            channel="chrome", user_data_dir=r"C:\\Users\\Home\\AppData\\Local\\Google\\Chrome\\User Data", headless=False)

    page = browser.new_page()

I'm facing difficulties in running all the Chrome profiles simultaneously or even sequentially.

I looked at the docs and GitHub issues but I'm not sure what to do.

1 Answer 1

2

I'm not very specialist but you can't use same user_data_dir for multiple instace of context. You should use differnt user_data_dir like

F:/Chrome/Dir1

F:/Chrome/Dir2

This is what I did my self in C# for multiple contexts. I hope be useful

List<IBrowserContext> browserContexts = new List<IBrowserContext>();
IBrowserContext context;
        for (int i = 0; i < 4; i++)
        {
             context = await playwright.Chromium.LaunchPersistentContextAsync($"F:/Program Files/chrome/{i}", new BrowserTypeLaunchPersistentContextOptions
            {
                Headless = false,
                SlowMo = 0,           
            });
            browserContexts.Add(context);                
        }
 

As you see for each browser context, I created a new directory named i which is 0,1,2,3 in this case.

Sign up to request clarification or add additional context in comments.

2 Comments

> Wait a little between your task to avoid some unwanted results So that means multi-threading isnt possible? I'm not a specialist as well so kind of stuck on this one.
Sorry, I reviewed my previous problems and I saw that I used some delay between sending requests to example.com for not sending a huge amount of requests at the same time. Finally it was another matter and I made a correction to my answer. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.