实现方式

  1. 浏览器启动时,加参数 args=['--start-maximized']
  2. 创建上下文时,加参数 no_viewport=True

img_1.png

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)

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

img_2.png

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

img_3.png


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


华健课堂
1 声望0 粉丝