Table of Contents

Class SetViewportCommandParameters

Namespace
WebDriverBiDi.BrowsingContext
Assembly
WebDriverBiDi.dll

Provides parameters for the browsingContext.setViewport command.

public class SetViewportCommandParameters : CommandParameters<SetViewportCommandResult>
Inheritance
SetViewportCommandParameters
Inherited Members

Constructors

SetViewportCommandParameters()

Initializes a new instance of the SetViewportCommandParameters class.

public SetViewportCommandParameters()

Properties

BrowsingContextId

Gets or sets the ID of the browsing context for which to set the viewport.

[JsonPropertyName("context")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? BrowsingContextId { get; set; }

Property Value

string

Remarks

This and UserContexts are mutually exclusive: a command that names both a browsing context and user contexts is rejected by the remote end with an invalid argument error.

DevicePixelRatio

Gets or sets the device pixel ratio of the viewport.

[JsonPropertyName("devicePixelRatio")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(SentinelNullJsonConverter<double, NegativeDoubleSentinelChecker, FixedDoubleJsonConverter>))]
[SpecRange(0, Infinity, MinimumExclusive = true, HasSentinel = true, SentinelValue = -1)]
public double? DevicePixelRatio { get; set; }

Property Value

double?

Remarks

Valid values for this property are greater than 0.0. This property does not validate its value; a value outside this range is sent as-is, and a conforming remote end rejects it when the command is executed. Assigning ResetToDefaultDevicePixelRatio instead signals the remote end to reset the device pixel ratio to its default.

Any negative value resets, but only ResetToDefaultDevicePixelRatio is declared as the reset sentinel of the SpecRangeAttribute, so tooling reports another negative value as out of range. That is deliberate, and matches how every other resettable numeric property in the library is declared: the named sentinel is the supported way to ask for a reset.

MethodName

Gets the method name of the command.

[JsonIgnore]
public override string MethodName { get; }

Property Value

string

ResetToDefaultDevicePixelRatio

Gets a sentinel value for the DevicePixelRatio property that signals the remote end to reset the device pixel ratio to its default value. Assign this to the DevicePixelRatio property; do not use it as a command-level reset.

public static double ResetToDefaultDevicePixelRatio { get; }

Property Value

double

Remarks

This is a property-level sentinel, not a command-level reset. It must be assigned to the DevicePixelRatio property of a SetViewportCommandParameters instance:

await driver.BrowsingContext.SetViewportAsync(
    new SetViewportCommandParameters
    {
        DevicePixelRatio = SetViewportCommandParameters.ResetToDefaultDevicePixelRatio
    });

When serialized, the sentinel (any negative value) causes the devicePixelRatio field to be written as JSON null, instructing the remote end to restore the default pixel ratio. Assigning a C# null to DevicePixelRatio omits the field entirely, leaving the current pixel ratio unchanged.

ResetToDefaultViewport

Gets a sentinel value for the Viewport property that signals the remote end to reset the viewport to its default dimensions. Assign this to the Viewport property; do not use it as a command-level reset.

public static Viewport ResetToDefaultViewport { get; }

Property Value

Viewport

Remarks

This is a property-level sentinel, not a command-level reset. It must be assigned to the Viewport property of a SetViewportCommandParameters instance:

await driver.BrowsingContext.SetViewportAsync(
    new SetViewportCommandParameters
    {
        Viewport = SetViewportCommandParameters.ResetToDefaultViewport
    });

When serialized, the sentinel causes the viewport field to be written as JSON null, instructing the remote end to restore the default viewport. Assigning a C# null to Viewport omits the field entirely, leaving the current viewport unchanged.

UserContexts

Gets the user context IDs for which to set the viewport.

[JsonIgnore]
public List<string> UserContexts { get; }

Property Value

List<string>

Remarks

The protocol requires this property, when present, to contain at least one entry. An empty list therefore means "not specified": the property is omitted from the JSON payload entirely, and an empty array is never sent. Add entries to the list to scope the command.

This and BrowsingContextId are mutually exclusive: a command that names both is rejected by the remote end with an invalid argument error.

Viewport

Gets or sets the viewport dimensions to set. A null value omits the field, leaving the current viewport unchanged; assign ResetToDefaultViewport to restore the default dimensions.

[JsonPropertyName("viewport")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(SentinelNullJsonConverter<Viewport, ViewportSentinelChecker>))]
public Viewport? Viewport { get; set; }

Property Value

Viewport