实现方式
1. 浏览器启动时,加参数 args=['--start-maximized']
;
2. 创建上下文时,加参数 no_viewport=True
。
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.