pythonpyppeteer

Connect to a browser with Pyppeteer


I want to connect to a chrome browser that i have started with the launch command

await launch(headless=False, \
            executablePath ="C:/Program Files/Google/Chrome/Application/chrome.exe",\
            args=["--remote-debugging-port=9222"])

with the connect command

browser=await pyppeteer.connect(browserURL='http://127.0.0.1:9222')

but it looks that this is not right.

if i open the browser with command line

chrome_path = 'C:/Program Files/Google/Chrome/Application/chrome.exe '
cmdCommand = chrome_path + " --remote-debugging-port=9222"
subprocess.Popen(cmdCommand.split(), stdout=subprocess.PIPE)

then pyppeteer.connect works fine.


Solution

  • Whether you are using python or javascript or any other tools, e.g. puppeteer-stealth package, you need to first launch and then get the wsEndpoint and connect it via pyppeteer.connect

    pup = await launch(headless=False, \
                executablePath ="C:/Program Files/Google/Chrome/Application/chrome.exe",\
               );
    endpoint = pup.wsEndpoint()
    
    pyppeteer.connect(browserWSEndpoint = endpoint )
    

    if you are trying to connect by specifying --remote-debugging-port, you have a typo on the option.