目前 playwright- Python 还是不完善

查看 30|回复 0
作者:hanssx   
今天发现一个 BUG ,主要是开启调试的情况下,运行完会导致浏览器 crash ,插件全部 crash (和插件本身无关),相关 issue: https://github.com/microsoft/playwright-python/issues/2160
我这边目前 100%复现,代码很简单,我贴一个,有兴趣的可以复现一下。
playwright 代码
from playwright.sync_api import Playwright, sync_playwright, expect
def run(playwright: Playwright) -> None:
    browser = playwright.chromium.connect_over_cdp('http://127.0.0.1:2333')
    context = browser.contexts[0]
    # context.tracing.start(screenshots=True, snapshots=True, sources=True)
    page = context.pages[0]
    page.goto("https://www.baidu.com/")
    # context.tracing.stop(path = "trace.zip")
    # page.close()  # 加上 page.close()可以解决,但是会关闭网页啊,这没法继续后面的操作了。
    # context.close()
    # browser.close()
with sync_playwright() as playwright:
    run(playwright)
selenium 代码
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
chrome_service = Service('./chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:2333")
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
driver.get('https://www.baidu.com/')
您需要登录后才可以回帖 登录 | 立即注册

返回顶部