I'm trying to open a specific chrome profile using playwright python using the following code
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
# browser = p.chromium.launch(headless= False, slow_mo= 100000)
dir_path = r"C:\\Users\\{user}\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 7"
print("path :", dir_path)
browser = p.chromium.launch_persistent_context(channel="chrome", slow_mo= 100000, user_data_dir= dir_path, headless=False)
page = browser.new_page()
page.goto("https://www.example.com/login")
but it only opens profile 1. I also want to make the automation undetectable if possible.
try this
user_data_dir = r"C:\\Users\\{user}\\AppData\\Local\\Google\\Chrome\\User Data"
args = ["--profile-directory=Profile 7"]
with sync_playwright() as p:
# Launch Chrome with the specified profile
browser = p.chromium.launch_persistent_context(
user_data_dir=user_data_dir, # Base directory
channel='chrome', # Use Chrome browser
args=args, # Specify the profile directory
headless=False # Headful mode for debugging
)
And make sure the Chrome app is closed (with no tabs open) before running.
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