大网数据广告活动
Web 标准与前端开发

Set Window Rect

· 52CE 我爱测

The _Set Window Rect_ command of the WebDriver API alters the size and position of the operating system window associated with the current `window`. The command acts as the setter of Get Window Rect, which return object you can pass directly as this command's payload.

The Set Window Rect command of the WebDriver API alters the size and position of the operating system window associated with the current window. The command acts as the setter of Get Window Rect, which return object you can pass directly as this command's payload.

Certain subsets of devices do not support setting the window dimensions or its position. In these configurations, the command will return an unsupported operation error. To avoid running into situations where calling this might error, it is possible to call it conditionally on whether the setWindowRect capability is set to true for the session.

Setting the window rect takes x, y, width, and height as input. All the fields are optional, e.g., the command may be called with an empty object, and in this case it will act as a no-op. To set the position both of x and y are required, and correspondingly both width and height are required for altering the window's dimensions.

When setting the width or height, it is not guaranteed that the resulting window size will exactly match that which was requested. The driver is expected to clamp values that are larger than the physical screen dimensions, or smaller than the minimum window size. Some drivers may also have other limitations such as not being able to resize in single-pixel increments. For this reason, the returned width and height might not exactly match Window.outerWidth and Window.outerHeight.

Setting the window's position is similar in nature to calling Window.moveTo(x, y), but differences itself by bypassing security restrictions related to window manipulation.

The Set Window Rect command is blocking.

Syntax

Method URI template
POST /session/{session id}/window/rect

URL parameters

  • session id
    • : Identifier of the session.

Payload

The input is a WindowRect object:

  • x

    • : Horizontal position of the window, which equivalent to Window.screenX. Must be a number in the −(2^31) to 2^31 − 1 range, null, or undefined.
  • y

    • : Vertical position of the window, which is equivalent to Window.screenY. Must be a number in the −(2^31) to 2^31 − 1 range, null, or undefined.
  • width

    • : Outer width of the window, which is equivalent to Window.outerWidth. Must be a number in the 0 to 2^31 − 1 range, null, or undefined.
  • height

    • : Outer width of the window, which is equivalent to Window.outerHeight. Must be a number in the 0 to 2^31 − 1 range, null, or undefined.

Response

The response payload is a WindowRect:

  • x
    • : Horizontal position of the operating system window associated with window, equivalent to Window.screenX.
  • y
    • : Vertical position of the operating system window associated with window, equivalent to Window.screenY.
  • width
  • height

Errors

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。