实现方式
- 浏览器启动时,加参数
args=['--start-maximized']
; - 创建上下文时,加参数
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.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。