DeviceDescriptor Class
A device to emulate, as the device descriptors of Playwright (playwright.devices): the size of its viewport and of its screen, its device pixel ratio, whether it is a mobile device with a touch screen, and its user agent string. The library has no list of devices: copy the values of a descriptor of Playwright, or describe your own device.
public sealed class DeviceDescriptor : IEquatable<DeviceDescriptor>Example
// The values of the "iPhone 13" device of Playwright
var iPhone13 = new DeviceDescriptor
{
Width = 390,
Height = 664,
ScreenWidth = 390,
ScreenHeight = 844,
DevicePixelRatio = 3,
IsMobile = true,
HasTouch = true,
UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1",
};
using var context = new BrowsingContext(new BrowsingContextOptions
{
Viewport = iPhone13.CreateViewport(),
UserAgent = iPhone13.UserAgent,
});
var document = context.Navigate("https://example.com/", _ => "<!DOCTYPE html><p>Hello</p>");
Assert.True(document.DefaultView!.MatchMedia("(pointer: coarse) and (max-device-width: 500px)").Matches);
Assert.Equal(iPhone13.UserAgent, document.DefaultView.Navigator.UserAgent);- Implements
Constructors
| Name | Description |
|---|---|
| DeviceDescriptor() |
DeviceDescriptor()
DeviceDescriptor.cs- Obsolete: Constructors of types with required members are not supported in this version of your compiler.
[Obsolete("Constructors of types with required members are not supported in this version of your compiler.", true)]
public DeviceDescriptor()No documentation is available.
Properties
| Name | Description |
|---|---|
| DevicePixelRatio | Gets or sets the number of device pixels per CSS pixel (deviceScaleFactor in Playwright). The default is 1. |
| HasTouch | Gets or sets whether the device has a touch screen (hasTouch in Playwright, see ViewportOptions.HasTouch). |
| Height | Gets or sets the height of the viewport, in CSS pixels (viewport.height in Playwright). |
| IsMobile | Gets or sets whether the device is a mobile device (isMobile in Playwright, see ViewportOptions.IsMobile). |
| ScreenHeight | Gets or sets the height of the screen, in CSS pixels (screen.height in Playwright), or null for the height of the viewport. |
| ScreenWidth | Gets or sets the width of the screen, in CSS pixels (screen.width in Playwright), or null for the width of the viewport. |
| UserAgent | Gets or sets the user agent string of the device (userAgent in Playwright, see BrowsingContextOptions.UserAgent), or null. |
| Width | Gets or sets the width of the viewport, in CSS pixels (viewport.width in Playwright). |
DevicePixelRatio
DeviceDescriptor.csHasTouch
DeviceDescriptor.csGets or sets whether the device has a touch screen (hasTouch in Playwright, see ViewportOptions.HasTouch).
public bool HasTouch { get; init; }Property value
Height
DeviceDescriptor.csIsMobile
DeviceDescriptor.csGets or sets whether the device is a mobile device (isMobile in Playwright, see ViewportOptions.IsMobile).
public bool IsMobile { get; init; }Property value
ScreenHeight
DeviceDescriptor.csScreenWidth
DeviceDescriptor.csUserAgent
DeviceDescriptor.csGets or sets the user agent string of the device (userAgent in Playwright, see BrowsingContextOptions.UserAgent), or null.
public string? UserAgent { get; init; }Property value
Width
DeviceDescriptor.csMethods
| Name | Description |
|---|---|
| CreateViewport(ViewportOptions?) | Returns the viewport of the device: the options of viewport (the preferences of the user, the media type...) with the size, the screen, the device pixel ratio and the kind of device of the descriptor. |
| Equals(DeviceDescriptor?) | |
| Equals(object?) | |
| GetHashCode() | |
| ToString() |
CreateViewport(ViewportOptions?)
DeviceDescriptor.csReturns the viewport of the device: the options of viewport (the preferences of the user, the media type...) with the size, the screen, the device pixel ratio and the kind of device of the descriptor.
public ViewportOptions CreateViewport(ViewportOptions? viewport = null)Parameters
viewportViewportOptions?- The other options of the viewport, or null for
ViewportOptions.Default.
Returns
ViewportOptions The options of the viewport, to set in BrowsingContextOptions.Viewport.
Equals overloads
Equals(DeviceDescriptor?)
public bool Equals(DeviceDescriptor? other)No documentation is available.
Equals(object?)
GetHashCode()
ToString()
Operators
| Name | Description |
|---|---|
| operator ==(DeviceDescriptor?, DeviceDescriptor?) | |
| operator !=(DeviceDescriptor?, DeviceDescriptor?) |
operator ==(DeviceDescriptor?, DeviceDescriptor?)
public static bool operator ==(DeviceDescriptor? left, DeviceDescriptor? right)No documentation is available.
operator !=(DeviceDescriptor?, DeviceDescriptor?)
public static bool operator !=(DeviceDescriptor? left, DeviceDescriptor? right)No documentation is available.