Skip to main content

Changing viewport

The Canvasflare API provides the capability to create screenshots with various viewport settings. This feature enables you to see how a website appears on different displays, offering insights into its responsiveness and visual consistency across devices.

viewport_width param

viewport_width (number, required) - This allows you to determine the width of Chrome's viewing area, which will deactivate the auto-cropping feature. Default value is 1366. Min. 480, max. 1920.

viewport_height param

viewport_height (number, required) - This allows you to specify the height of Chrome's viewing area, which in turn deactivates the auto-cropping feature. Default value is 766. Min. 480, max. 1920.

Required parameters

Both the viewport_width and viewport_height parameters need to be established if you choose to use either one.

Let's explore how it works. Below is a screenshot using the default viewport settings:

Screenshot with default viewport

Next, let's adjust the viewport values to 1080 x 1920 to simulate a mobile device. Here, the viewport_width is set to 1080, and the viewport_height is set to 1920. Here's what it looks like:

Screenshot with mobile viewport

Check out our code samples below for more details.

import requests

api_key = 'YOUR_API_KEY'
base_url = 'https://api.canvasflare.com/screenshot'
params = {
'api_key': api_key,
'url': 'https://getbootstrap.com',
'viewport_width': 1080,
'viewport_height': 1920
}

response = requests.get(base_url, params=params)
if response.status_code == 200:
print('Image created:', response.json())
else:
print('Error creating image:', response.text)