Skip to content

browser.viewport.set#

Functions#

size(width, height) #

Attempt to set custom viewport size in pixels.

Note

It's recommended to run emulations in headless mode since an open browser may have minimum or maximum dimensions, either limited by the browser window or the monitor.

Parameters:

Name Type Description Default
width int

Viewport width in pixels.

required
height int

Viewport height in pixels.

required
Example
browser.viewport.set.size(1920, 1080)

size_by_device(device) #

Attempt to set the viewport size by device types, e.g. iPhone, iPad, or other common devices.

Note

It's recommended to run emulations in headless mode since an open browser may have minimum or maximum dimensions, either limited by the browser window or the monitor.

Parameters:

Name Type Description Default
device DeviceViewportSize

Device type to emulate.

required
Example
1
2
3
4
5
from browserist import Browser, DeviceViewportSize

with Browser() as browser:
    custom_device = DeviceViewportSize(width=375, height=812)
    browser.viewport.set.size_by_device(custom_device)