Coder Social home page Coder Social logo

Comments (7)

pavelfeldman avatar pavelfeldman commented on August 16, 2024

Try replacing

playwright.chromium.connect_over_cdp(("http://localhost:1234"))

with

playwright.chromium.connect_over_cdp(("http://127.0.0.1:1234"))

It sound like localhost resolves to ipv6 on your system.

from playwright.

mxschmitt avatar mxschmitt commented on August 16, 2024

My guess is that

chrome_path = r'"C:\Program Files\Google\Chrome\Application\chrome.exe"'
debugging_port = "--remote-debugging-port=1234"

command = f"{chrome_path} {debugging_port}"
subprocess.Popen(command, shell=True)

is not working or not waiting long enough to Playwright to connect, so the server is not listening yet. Could you verify that?

from playwright.

Louis24 avatar Louis24 commented on August 16, 2024

Try replacing

playwright.chromium.connect_over_cdp(("http://localhost:1234"))

with

playwright.chromium.connect_over_cdp(("http://127.0.0.1:1234"))

It sound like localhost resolves to ipv6 on your system.

Try replacing

playwright.chromium.connect_over_cdp(("http://localhost:1234"))

with

playwright.chromium.connect_over_cdp(("http://127.0.0.1:1234"))

It sound like localhost resolves to ipv6 on your system.

browser = playwright.chromium.connect_over_cdp("http://127.0.0.1:1234")

image
when I change to browser = playwright.chromium.connect_over_cdp("ws://127.0.0.1:1234")

image

from playwright.

Louis24 avatar Louis24 commented on August 16, 2024

My guess is that

chrome_path = r'"C:\Program Files\Google\Chrome\Application\chrome.exe"'
debugging_port = "--remote-debugging-port=1234"

command = f"{chrome_path} {debugging_port}"
subprocess.Popen(command, shell=True)

is not working or not waiting long enough to Playwright to connect, so the server is not listening yet. Could you verify that?

sure, i'll try wait longer time. I have setting the time=10s, still error.
I guess a possible reason is that I use a vpn, is that cause the error?

from playwright.

mxschmitt avatar mxschmitt commented on August 16, 2024

I had to modify it a little bit, since I'm on macOS, then it was working for me, note the --user-data-dir:

chrome_path = r'"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"'
debugging_port = "--remote-debugging-port=1234 --user-data-dir=foo"

command = f"{chrome_path} {debugging_port}"
subprocess.Popen(command, shell=True)

from playwright.

Louis24 avatar Louis24 commented on August 16, 2024

I had to modify it a little bit, since I'm on macOS, then it was working for me, note the --user-data-dir:

chrome_path = r'"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"'
debugging_port = "--remote-debugging-port=1234 --user-data-dir=foo"

command = f"{chrome_path} {debugging_port}"
subprocess.Popen(command, shell=True)

thx, not working on windows.

Since YouTube has a security check mechanism and detected that the Playwright framework contained risks, I wondered if there was a possibility to let Playwright open the local browser and load local cookies and plug-ins, which would save the login step.

So I tried another method:

def run(playwright):
browser = playwright.chromium.launch_persistent_context(
user_data_dir=r"C:\Users\Louis\AppData\Local\Google\Chrome\User Data\Profile 1", # 设置用户数据目录
executable_path=r'C:\Program Files\Google\Chrome\Application\chrome.exe', # Chrome 可执行文件路径
accept_downloads=True, # 允许下载
headless=False, # 非无头模式,即显示浏览器界面
bypass_csp=True, # 绕过 Content Security Policy
slow_mo=10, # 减速执行,便于调试
args=[
'--disable-blink-features=AutomationControlled', # 禁用 Blink 功能控制
'--remote-debugging-port=1234', # 启用远程调试端口
'--in-process-plugins', # 插件在浏览器进程中运行
'--allow-outdated-plugins', # 允许使用过期插件
]
)
page = browser.new_page()
page.goto("https://www.baidu.com/")
print(page.title())
page.pause()

with sync_playwright() as playwright:
run(playwright)

The results is like this
image

Which I expect like this
image

is it possible to open a broswer with cache and plugin? and how about codegen using my own broswer?

from playwright.

mxschmitt avatar mxschmitt commented on August 16, 2024

This doesn't look like and end-to-end testing use-case, so I'm going to close it for now. If you want to open an existing profile, see e.g. here or here.

from playwright.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.