2

My goal is to automate a task on a website that requires login. So I want to login once manually and let the automation run from there. I tried using CRD but when my code runs, it opens a new window where my account is not logged in. Here is an example code I am running:

from playwright.sync_api import sync_playwright
import time


def connect_to_chrome_debugger():
    with sync_playwright() as p:
        # Connect to the running Chrome instance using CDP
        browser = p.chromium.connect_over_cdp("http://localhost:9234")

        # Create a new page in the connected browser
        page = browser.new_page()

        # Navigate to a URL
        page.goto("https://gmail.com")
        time.sleep(10)

        # Print the title of the page
        print(page.title())

        # Perform additional actions as needed

        # Close the page (not the entire browser)
        page.close()


if __name__ == "__main__":
    connect_to_chrome_debugger()

Now in this example, I have already logged into my gmail on chrome and when I launch the CRD session using:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9234

it shows me as logged in user. However, when playwright runs and opens a new window, then it behaves as if I am logged out.

1 Answer 1

0

Your exact code worked for me on with the following launch command, specifying a user data dir:

% /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
  --remote-debugging-port=9234 \
  --user-data-dir=/tmp/chrome-debug

Versions:

  • MacOS 14.4 (23E214) M3 Pro
  • Chrome 139.0.7258.139 (Official Build) (arm64)

If I don't pass --user-data-dir, I get ECONNREFUSED.

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

Comments

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.