You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Playwright中Page.ViewportSize属性何时会为null?

Page.ViewportSize 属性为 null 的场景
  • 当页面处于无头模式且未显式设置视口大小时,Page.ViewportSize 会为 null,因为无头模式默认不强制固定视口尺寸,采用浏览器自适应逻辑。
  • 通过 BrowserContext.NewPageAsync() 创建页面时,若上下文和页面均未配置视口参数,该属性会返回 null。
  • 主动调用 Page.SetViewportSizeAsync(null) 后,Page.ViewportSize 会变为 null,此时页面恢复浏览器默认视口行为,不再强制固定尺寸。
  • 移动端设备模拟场景中,若未明确指定视口大小、依赖设备默认配置时,Page.ViewportSize 也可能为 null。

内容的提问来源于stack exchange,提问作者lonix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 18:29:51