grafana/k6 · error

setting window bounds

Error message

setting window bounds: %w

What it means

Wrap of the CDP Browser.setWindowBounds command: after applying device-metrics emulation, updateViewport recalculates the OS-dependent viewport inset (only when running headed, i.e., hasUIWindow) and resizes the actual browser window to match. This error fires when resizing the window fails — the window ID is stale (window closed), the browser crashed, or the session was canceled during teardown.

Solutions

  1. Ensure the browser window still exists when the viewport is updated
  2. Prefer headless mode if window resizing is not essential to the test
  3. Set the viewport at context creation instead of resizing an existing window mid-test
  4. Retry on a new page if the browser session has been torn down
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/frame_session.go:1272 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-09-20). Data as JSON: /api/errors/838608cf0152f625. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/frame_session.go:1329

		WithScreenWidth(screen.Width).
		WithScreenHeight(screen.Height)
	if err := action.Do(cdp.WithExecutor(ctx, fs.session)); err != nil {
		return fmt.Errorf("emulating viewport: %w", err)
	}

	if fs.hasUIWindow {
		// add an inset to viewport depending on the operating system.
		// this won't add an inset if we're running in headless mode.
		viewport = viewport.recalculateInset(
			fs.page.browserCtx.browser.browserOpts.Headless,
			runtime.GOOS,
		)
		action2 := browser.SetWindowBounds(fs.windowID, &browser.Bounds{
			Width:  viewport.Width,
			Height: viewport.Height,
		})
		if err := action2.Do(cdp.WithExecutor(ctx, fs.session)); err != nil {
			return fmt.Errorf("setting window bounds: %w", err)
		}
	}

	return nil
}

func (fs *FrameSession) executionContextForID(
	executionContextID cdpruntime.ExecutionContextID,
) (*ExecutionContext, error) {
	fs.contextIDToContextMu.Lock()
	defer fs.contextIDToContextMu.Unlock()

	if exc, ok := fs.contextIDToContext[executionContextID]; ok {
		return exc, nil
	}

	return nil, fmt.Errorf("no execution context found for id: %v", executionContextID)
}

View on GitHub (pinned to 3fcf5388d7)