Playwright 浏览器窗口最大化

2024-08-14 12:55:19 浏览数 (2)

实现方式

1. 浏览器启动时,加参数 args=['--start-maximized']

2. 创建上下文时,加参数 no_viewport=True

代码语言:python代码运行次数:0复制
from playwright.sync_api import Playwright, sync_playwright


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False, args=['--start-maximized'])
    context = browser.new_context(no_viewport=True)
    page = context.new_page()
    page.goto("https://playwright.dev/")
    page.wait_for_timeout(10*1000)
    # ---------------------
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)

再运行,就可以飞起来啦~~~

有图有真相!窗口已是最大化!


Life is great and everything will be OK, huajianketang is here.

0 人点赞