set_window_size
Adjust the browser window size to exact width and height values, enabling precise viewport control for responsive design testing.
Instructions
Set the browser window size.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| width | Yes | ||
| height | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/selenium_mcp_server/server.py:83-86 (registration)MCP tool registration for 'set_window_size' – the @mcp.tool() decorator registers this function as a tool, and it delegates to browser.set_window_size via _run.
@mcp.tool() def set_window_size(width: int, height: int) -> dict[str, Any]: """Set the browser window size.""" return _run("set_window_size", browser.set_window_size, width, height) - Actual implementation of set_window_size in BrowserManager – acquires the thread lock, calls Selenium's driver.set_window_size(width, height), and returns the current browser state.
def set_window_size(self, width: int, height: int) -> BrowserState: with self._lock: self._require_driver().set_window_size(width, height) return self.state() - Initial window size is set during driver configuration in _configure_driver using the configured window_width and window_height settings (suppressing errors).
with suppress(WebDriverException): driver.set_window_size(self._settings.window_width, self._settings.window_height) - Settings schema defining window_width and window_height with default values and validation constraints used when configuring initial window size.
window_width: int = Field(default=1440, ge=320, le=7680) window_height: int = Field(default=1000, ge=240, le=4320) - BrowserState model – the return type of set_window_size, containing session info, URL, title, and window handles.
class BrowserState(BaseModel): session_id: str | None current_url: str | None title: str | None window_handles: list[str] active_window_handle: str | None