Skip to content

Commit 8a67fa2

Browse files
authored
Merge branch 'main' into hypeship/project-contract-docs
2 parents 68c8119 + 796a23e commit 8a67fa2

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

‎browsers/viewport.mdx‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,52 @@ func main() {
135135
The `refresh_rate` parameter only applies to live view sessions and is ignored for [headless](/browsers/headless) browsers.
136136
</Info>
137137

138+
## Window size vs. page viewport
139+
140+
The `viewport` parameter sets the dimensions of the browser **window**, not the visible page area. On headful browsers, Chromium's UI (tab strip and toolbar) occupies part of the window height, so the page renders in a slightly shorter area than the configured height. For example, with a 1280x800 viewport, `window.innerHeight` will be less than 800 and content near the bottom of the page may not be visible in screenshots or live view.
141+
142+
If your automation expects an exact page viewport, either:
143+
144+
- **Use kiosk mode** to remove the browser UI, so the window dimensions match the page viewport exactly:
145+
146+
<CodeGroup>
147+
148+
```typescript Typescript/Javascript
149+
const kernelBrowser = await kernel.browsers.create({
150+
kiosk_mode: true,
151+
viewport: { width: 1920, height: 1080 }
152+
});
153+
```
154+
155+
```python Python
156+
kernel_browser = kernel.browsers.create(
157+
kiosk_mode=True,
158+
viewport={"width": 1920, "height": 1080}
159+
)
160+
```
161+
162+
</CodeGroup>
163+
164+
- **Set the page viewport through your automation framework.** This will update the rendered page size, but will not be reflected in the live view or computer controls:
165+
166+
<CodeGroup>
167+
168+
```typescript Typescript/Javascript
169+
// Playwright
170+
await page.setViewportSize({ width: 1280, height: 800 });
171+
```
172+
173+
```python Python
174+
# Playwright
175+
await page.set_viewport_size({"width": 1280, "height": 800})
176+
```
177+
178+
</CodeGroup>
179+
180+
- **Account for the browser UI when choosing dimensions** by adding its height to the `height` you pass to Kernel, so the remaining page area matches your target size.
181+
182+
On [headless](/browsers/headless) browsers there is no browser UI, so the page viewport matches the configured dimensions exactly.
183+
138184
## Supported viewport configurations
139185

140186
Kernel supports specific viewport configurations tuned for optimal performance and Computer Use compatibility. When you provide width and height without specifying refresh_rate, it will be automatically determined if the dimensions match one of the supported resolutions exactly. The following resolutions are supported:
@@ -414,4 +460,4 @@ if err != nil {
414460
- The viewport configuration is set when the browser is created and applies to the initial browser window
415461
- Higher resolutions (like 2560x1440) may impact the performance and responsiveness of live view sessions
416462
- The viewport size affects how websites render, especially those with responsive designs
417-
- Screenshots taken from the browser will match the configured viewport dimensions
463+
- Screenshots taken through your automation framework capture the page viewport, which on headful browsers is shorter than the configured dimensions due to the browser UI (see [Window size vs. page viewport](#window-size-vs-page-viewport))

0 commit comments

Comments
 (0)