ViewportOptions Class

The virtual viewport of the top-level browsing context and the preferences of the user: nothing is rendered, but the media queries (@media, the media of the style sheets) and the viewport-relative lengths (vw, vh...) of the computed styles are evaluated against them. The viewport of a nested browsing context is the size given by the width and height attributes of its iframe (300x150 by default).

public sealed class ViewportOptions : IEquatable<ViewportOptions>
Implements

Constructors

NameDescription
ViewportOptions()

ViewportOptions()

ViewportOptions.cs
public ViewportOptions()

No documentation is available.

Properties

NameDescription
CaretBlinkIntervalGets or sets the time during which the caret is displayed, then hidden, when it blinks (caret-animation: auto). The default is TimeSpan.Zero: the caret does not blink, so that the screenshots do not depend on the time they are taken at (the browsers blink every 500 ms or so). The blinking is driven by the timers of the event loop (its BrowsingContextOptions.TimeProvider): it starts when the caret is displayed, starts again when the caret moves, and stops when the document is no longer painted.
CaretVisibleGets or sets whether the text insertion caret is painted (https://drafts.csswg.org/css-ui-4/#insertion-caret): the caret of the focused text control, or of the collapsed selection in the focused editable content, when the top-level browsing context has the system focus (BrowsingContext.HasSystemFocus). The default is true.
DefaultGets the default viewport: 800x600 CSS pixels, a device pixel ratio of 1, a screen and no preferences.
DevicePixelRatioGets or sets the number of device pixels per CSS pixel (the resolution media feature). The default is 1.
ForcedColorsGets or sets whether a forced colors mode is active (https://drafts.csswg.org/css-color-adjust-1/#forced, the forced-colors media feature): the colors of the pages are replaced with the system colors of ViewportOptions.ForcedColorsTheme, unless an element opts out with forced-color-adjust.
ForcedColorsThemeGets or sets the color palette of the forced colors mode (the values of the system colors when ViewportOptions.ForcedColors is set). The default is null: ForcedColorsTheme.Dark when ViewportOptions.PreferredColorScheme is dark, ForcedColorsTheme.Light otherwise. A palette whose canvas is clearly dark or light also sets the preferred color scheme of the pages (the prefers-color-scheme media feature).
HasTouchGets or sets whether the device has a touch screen as its primary pointing device, as the hasTouch option of Playwright: the pointer and any-pointer media features are coarse, hover and any-hover are none, and navigator.maxTouchPoints is 1. The default is false (a mouse: fine and hover).
HeightGets or sets the height of the viewport, in CSS pixels. The default is 600.
IsMobileGets or sets whether the viewport is the one of a mobile device, as the isMobile option of Playwright: the viewport meta element of the top-level document sets the size of its layout viewport and its scale (see ViewportOptions.Width), the scrollbars are overlay scrollbars (ViewportOptions.ScrollbarThickness is ignored), and the client hints default to a mobile device (ClientHintsOptions.Mobile). The default is false.
MediaTypeGets or sets the media type: screen (the default) or print.
PreferredColorSchemeGets or sets the preferred color scheme (the prefers-color-scheme media feature, and the used color scheme of light-dark() and the system colors). The prefers-color-scheme media feature of a page whose color-scheme meta element supports a single color scheme matches that color scheme instead.
PreferredContrastGets or sets the contrast preferred by the user (the prefers-contrast media feature). In forced colors mode, the preference is the contrast of the forced colors palette instead. The default is PreferredContrast.NoPreference.
PrefersReducedMotionGets or sets whether the user prefers reduced motion (the prefers-reduced-motion media feature).
PrefersReducedTransparencyGets or sets whether the user prefers reduced transparency (the prefers-reduced-transparency media feature).
ScreenHeightGets or sets the height of the screen, in CSS pixels (the device-height media feature and screen.height). The default is null: the height of the viewport.
ScreenWidthGets or sets the width of the screen, in CSS pixels (the device-width media feature and screen.width). The default is null: the width of the viewport.
ScrollbarThicknessGets or sets the thickness of the classic scrollbars, in CSS pixels (https://drafts.csswg.org/css-overflow-3/#classic-scrollbars): the scrollbars of the scroll containers and of the viewport take this space from their content box when they are displayed (clientWidth excludes them). The default is 15, the scrollbars of Chrome on Windows and Linux (which the web-platform-tests assume). 0 gives overlay scrollbars, which take no space (as on macOS and the mobile devices).
ScrollbarsVisibleGets or sets whether the classic scrollbars are painted and react to the pointer (a press on the track scrolls by a page, a drag of the thumb scrolls). The default is true. When it is false, the scrollbars still take their space (ViewportOptions.ScrollbarThickness), which is left empty: the background of the scroll container, or of the canvas for the viewport, shows in their gutters. The overlay scrollbars (a ViewportOptions.ScrollbarThickness of 0) are never painted.
SmoothUserScrollingGets or sets whether the scrolls of the user are animated, as in the browsers: the scrolls of the keys and of the presses on the track of a scrollbar are smooth scrolls (https://drafts.csswg.org/cssom-view/#concept-smooth-scroll) advanced by the rendering updates of the event loop (on its BrowsingContextOptions.TimeProvider), which a later key retargets, a gesture of the wheel lasts until no wheel event follows for 100 ms, and the snapping at the end of a gesture is animated. The default is false: the scrolls of the user are instant and each wheel event is a complete gesture, so that a screenshot taken right after an input does not depend on the time it is taken at.
WidthGets or sets the width of the viewport, in CSS pixels. The default is 800.

CaretBlinkInterval

ViewportOptions.cs

Gets or sets the time during which the caret is displayed, then hidden, when it blinks (caret-animation: auto). The default is TimeSpan.Zero: the caret does not blink, so that the screenshots do not depend on the time they are taken at (the browsers blink every 500 ms or so). The blinking is driven by the timers of the event loop (its BrowsingContextOptions.TimeProvider): it starts when the caret is displayed, starts again when the caret moves, and stops when the document is no longer painted.

public TimeSpan CaretBlinkInterval { get; init; }

Property value

TimeSpan

CaretVisible

ViewportOptions.cs

Gets or sets whether the text insertion caret is painted (https://drafts.csswg.org/css-ui-4/#insertion-caret): the caret of the focused text control, or of the collapsed selection in the focused editable content, when the top-level browsing context has the system focus (BrowsingContext.HasSystemFocus). The default is true.

public bool CaretVisible { get; init; }

Property value

bool

Gets the default viewport: 800x600 CSS pixels, a device pixel ratio of 1, a screen and no preferences.

public static ViewportOptions Default { get; }

Property value

ViewportOptions

DevicePixelRatio

ViewportOptions.cs

Gets or sets the number of device pixels per CSS pixel (the resolution media feature). The default is 1.

public double DevicePixelRatio { get; init; }

Property value

double

ForcedColors

ViewportOptions.cs

Gets or sets whether a forced colors mode is active (https://drafts.csswg.org/css-color-adjust-1/#forced, the forced-colors media feature): the colors of the pages are replaced with the system colors of ViewportOptions.ForcedColorsTheme, unless an element opts out with forced-color-adjust.

public bool ForcedColors { get; init; }

Property value

bool

ForcedColorsTheme

ViewportOptions.cs

Gets or sets the color palette of the forced colors mode (the values of the system colors when ViewportOptions.ForcedColors is set). The default is null: ForcedColorsTheme.Dark when ViewportOptions.PreferredColorScheme is dark, ForcedColorsTheme.Light otherwise. A palette whose canvas is clearly dark or light also sets the preferred color scheme of the pages (the prefers-color-scheme media feature).

public ForcedColorsTheme? ForcedColorsTheme { get; init; }

Property value

ForcedColorsTheme?

Gets or sets whether the device has a touch screen as its primary pointing device, as the hasTouch option of Playwright: the pointer and any-pointer media features are coarse, hover and any-hover are none, and navigator.maxTouchPoints is 1. The default is false (a mouse: fine and hover).

public bool HasTouch { get; init; }

Property value

bool

Gets or sets the height of the viewport, in CSS pixels. The default is 600.

public double Height { get; init; }

Property value

double

Gets or sets whether the viewport is the one of a mobile device, as the isMobile option of Playwright: the viewport meta element of the top-level document sets the size of its layout viewport and its scale (see ViewportOptions.Width), the scrollbars are overlay scrollbars (ViewportOptions.ScrollbarThickness is ignored), and the client hints default to a mobile device (ClientHintsOptions.Mobile). The default is false.

public bool IsMobile { get; init; }

Property value

bool

Gets or sets the media type: screen (the default) or print.

public string MediaType { get; init; }

Property value

string

PreferredColorScheme

ViewportOptions.cs

Gets or sets the preferred color scheme (the prefers-color-scheme media feature, and the used color scheme of light-dark() and the system colors). The prefers-color-scheme media feature of a page whose color-scheme meta element supports a single color scheme matches that color scheme instead.

public PreferredColorScheme PreferredColorScheme { get; init; }

Property value

PreferredColorScheme

PreferredContrast

ViewportOptions.cs

Gets or sets the contrast preferred by the user (the prefers-contrast media feature). In forced colors mode, the preference is the contrast of the forced colors palette instead. The default is PreferredContrast.NoPreference.

public PreferredContrast PreferredContrast { get; init; }

Property value

PreferredContrast

PrefersReducedMotion

ViewportOptions.cs

Gets or sets whether the user prefers reduced motion (the prefers-reduced-motion media feature).

public bool PrefersReducedMotion { get; init; }

Property value

bool

PrefersReducedTransparency

ViewportOptions.cs

Gets or sets whether the user prefers reduced transparency (the prefers-reduced-transparency media feature).

public bool PrefersReducedTransparency { get; init; }

Property value

bool

ScreenHeight

ViewportOptions.cs

Gets or sets the height of the screen, in CSS pixels (the device-height media feature and screen.height). The default is null: the height of the viewport.

public double? ScreenHeight { get; init; }

Property value

double?

Gets or sets the width of the screen, in CSS pixels (the device-width media feature and screen.width). The default is null: the width of the viewport.

public double? ScreenWidth { get; init; }

Property value

double?

ScrollbarThickness

ViewportOptions.cs

Gets or sets the thickness of the classic scrollbars, in CSS pixels (https://drafts.csswg.org/css-overflow-3/#classic-scrollbars): the scrollbars of the scroll containers and of the viewport take this space from their content box when they are displayed (clientWidth excludes them). The default is 15, the scrollbars of Chrome on Windows and Linux (which the web-platform-tests assume). 0 gives overlay scrollbars, which take no space (as on macOS and the mobile devices).

public double ScrollbarThickness { get; init; }

Property value

double

ScrollbarsVisible

ViewportOptions.cs

Gets or sets whether the classic scrollbars are painted and react to the pointer (a press on the track scrolls by a page, a drag of the thumb scrolls). The default is true. When it is false, the scrollbars still take their space (ViewportOptions.ScrollbarThickness), which is left empty: the background of the scroll container, or of the canvas for the viewport, shows in their gutters. The overlay scrollbars (a ViewportOptions.ScrollbarThickness of 0) are never painted.

public bool ScrollbarsVisible { get; init; }

Property value

bool

SmoothUserScrolling

ViewportOptions.cs

Gets or sets whether the scrolls of the user are animated, as in the browsers: the scrolls of the keys and of the presses on the track of a scrollbar are smooth scrolls (https://drafts.csswg.org/cssom-view/#concept-smooth-scroll) advanced by the rendering updates of the event loop (on its BrowsingContextOptions.TimeProvider), which a later key retargets, a gesture of the wheel lasts until no wheel event follows for 100 ms, and the snapping at the end of a gesture is animated. The default is false: the scrolls of the user are instant and each wheel event is a complete gesture, so that a screenshot taken right after an input does not depend on the time it is taken at.

public bool SmoothUserScrolling { get; init; }

Property value

bool

Gets or sets the width of the viewport, in CSS pixels. The default is 800.

public double Width { get; init; }

Property value

double

Methods

NameDescription
Equals(ViewportOptions?)
Equals(object?)
GetHashCode()
ToString()

Equals overloads

Equals(ViewportOptions?)

public bool Equals(ViewportOptions? other)
Parameters
other ViewportOptions?
Returns

bool

No documentation is available.

Equals(object?)

public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetHashCode()

public override int GetHashCode()

Returns

int

No documentation is available.

ToString()

public override string ToString()

Returns

string

No documentation is available.

Operators

NameDescription
operator ==(ViewportOptions?, ViewportOptions?)
operator !=(ViewportOptions?, ViewportOptions?)

operator ==(ViewportOptions?, ViewportOptions?)

public static bool operator ==(ViewportOptions? left, ViewportOptions? right)

Parameters

left ViewportOptions?
right ViewportOptions?

Returns

bool

No documentation is available.

operator !=(ViewportOptions?, ViewportOptions?)

public static bool operator !=(ViewportOptions? left, ViewportOptions? right)

Parameters

left ViewportOptions?
right ViewportOptions?

Returns

bool

No documentation is available.