Interface IBrowser
The Browser domain defines methods and events for browser managing.
public interface IBrowser
Properties
DownloadProgress
Fired when download makes progress. Last call has |done| == true.
[Experimental("BIDICDP001")]
IEventSource<DownloadProgressEventArgs> DownloadProgress { get; }
Property Value
- IEventSource<DownloadProgressEventArgs>
Remarks
Event args (DownloadProgressEventArgs):
- Guid - Global unique identifier of the download.
- TotalBytes - Total expected bytes to download.
- ReceivedBytes - Total bytes received.
- State - Download status.
- FilePath - If download is "completed", provides the path of the downloaded file. Depending on the platform, it is not guaranteed to be set, nor the file is guaranteed to exist.
DownloadWillBegin
Fired when page is about to start a download.
[Experimental("BIDICDP001")]
IEventSource<DownloadWillBeginEventArgs> DownloadWillBegin { get; }
Property Value
- IEventSource<DownloadWillBeginEventArgs>
Remarks
Event args (DownloadWillBeginEventArgs):
- FrameId - Id of the frame that caused the download to begin.
- Guid - Global unique identifier of the download.
- Url - URL of the resource being downloaded.
- SuggestedFilename - Suggested file name of the resource (the actual name of the file saved on disk may differ).
Methods
AddMockCameraAsync(string, string?, CancellationToken)
Adds or updates a mock camera in the shared video capture device list for test automation. The mock camera is not scoped to a particular page or frame and is removed when the DevTools session that created it disconnects.
[Experimental("BIDICDP001")]
Task<AddMockCameraResult> AddMockCameraAsync(string deviceId, string? session = null, CancellationToken cancellationToken = default)
Parameters
deviceIdstringRequired non-empty identifier for the mock camera. This is mapped to an internal virtual-device identifier and is not the MediaDeviceInfo.deviceId exposed to the page.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AddMockCameraResult>
A task representing the asynchronous operation, containing a AddMockCameraResult.
AddPrivacySandboxEnrollmentOverrideAsync(string, string?, CancellationToken)
Allows a site to use privacy sandbox features that require enrollment without the site actually being enrolled. Only supported on page targets.
Task<AddPrivacySandboxEnrollmentOverrideResult> AddPrivacySandboxEnrollmentOverrideAsync(string url, string? session = null, CancellationToken cancellationToken = default)
Parameters
urlstringsessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AddPrivacySandboxEnrollmentOverrideResult>
A task representing the asynchronous operation, containing a AddPrivacySandboxEnrollmentOverrideResult.
CancelDownloadAsync(string, BrowserContextID?, string?, CancellationToken)
Cancel a download if in progress
[Experimental("BIDICDP001")]
Task<CancelDownloadResult> CancelDownloadAsync(string guid, BrowserContextID? browserContextId = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
guidstringGlobal unique identifier of the download.
browserContextIdBrowserContextIDBrowserContext to perform the action in. When omitted, default browser context is used.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<CancelDownloadResult>
A task representing the asynchronous operation, containing a CancelDownloadResult.
CloseAsync(string?, CancellationToken)
Close browser gracefully.
Task<CloseResult> CloseAsync(string? session = null, CancellationToken cancellationToken = default)
Parameters
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<CloseResult>
A task representing the asynchronous operation, containing a CloseResult.
CrashAsync(string?, CancellationToken)
Crashes browser on the main thread.
[Experimental("BIDICDP001")]
Task<CrashResult> CrashAsync(string? session = null, CancellationToken cancellationToken = default)
Parameters
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<CrashResult>
A task representing the asynchronous operation, containing a CrashResult.
CrashGpuProcessAsync(string?, CancellationToken)
Crashes GPU process.
[Experimental("BIDICDP001")]
Task<CrashGpuProcessResult> CrashGpuProcessAsync(string? session = null, CancellationToken cancellationToken = default)
Parameters
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<CrashGpuProcessResult>
A task representing the asynchronous operation, containing a CrashGpuProcessResult.
ExecuteBrowserCommandAsync(BrowserCommandId, string?, CancellationToken)
Invoke custom browser commands used by telemetry.
[Experimental("BIDICDP001")]
Task<ExecuteBrowserCommandResult> ExecuteBrowserCommandAsync(BrowserCommandId commandId, string? session = null, CancellationToken cancellationToken = default)
Parameters
commandIdBrowserCommandIdsessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<ExecuteBrowserCommandResult>
A task representing the asynchronous operation, containing a ExecuteBrowserCommandResult.
GetBrowserCommandLineAsync(string?, CancellationToken)
Returns the command line switches for the browser process if, and only if --enable-automation is on the commandline.
[Experimental("BIDICDP001")]
Task<GetBrowserCommandLineResult> GetBrowserCommandLineAsync(string? session = null, CancellationToken cancellationToken = default)
Parameters
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<GetBrowserCommandLineResult>
A task representing the asynchronous operation, containing a GetBrowserCommandLineResult.
GetGlobalPrivacyControlAsync(string?, CancellationToken)
Gets the current globally-applied privacy control status See https://www.w3.org/TR/gpc/#get-global-privacy-control
[Experimental("BIDICDP001")]
Task<GetGlobalPrivacyControlResult> GetGlobalPrivacyControlAsync(string? session = null, CancellationToken cancellationToken = default)
Parameters
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<GetGlobalPrivacyControlResult>
A task representing the asynchronous operation, containing a GetGlobalPrivacyControlResult.
GetHistogramAsync(string, bool?, string?, CancellationToken)
Get a Chrome histogram by name.
[Experimental("BIDICDP001")]
Task<GetHistogramResult> GetHistogramAsync(string name, bool? delta = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
namestringRequested histogram name.
deltabool?If true, retrieve delta since last delta call.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<GetHistogramResult>
A task representing the asynchronous operation, containing a GetHistogramResult.
GetHistogramsAsync(string?, bool?, string?, CancellationToken)
Get Chrome histograms.
[Experimental("BIDICDP001")]
Task<GetHistogramsResult> GetHistogramsAsync(string? query = null, bool? delta = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
querystringRequested substring in name. Only histograms which have query as a substring in their name are extracted. An empty or absent query returns all histograms.
deltabool?If true, retrieve delta since last delta call.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<GetHistogramsResult>
A task representing the asynchronous operation, containing a GetHistogramsResult.
GetVersionAsync(string?, CancellationToken)
Returns version information.
Task<GetVersionResult> GetVersionAsync(string? session = null, CancellationToken cancellationToken = default)
Parameters
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<GetVersionResult>
A task representing the asynchronous operation, containing a GetVersionResult.
GetWindowBoundsAsync(WindowID, string?, CancellationToken)
Get position and size of the browser window.
[Experimental("BIDICDP001")]
Task<GetWindowBoundsResult> GetWindowBoundsAsync(WindowID windowId, string? session = null, CancellationToken cancellationToken = default)
Parameters
windowIdWindowIDBrowser window id.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<GetWindowBoundsResult>
A task representing the asynchronous operation, containing a GetWindowBoundsResult.
GetWindowForTargetAsync(TargetID?, string?, CancellationToken)
Get the browser window that contains the devtools target.
[Experimental("BIDICDP001")]
Task<GetWindowForTargetResult> GetWindowForTargetAsync(TargetID? targetId = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
targetIdTargetIDDevtools agent host id. If called as a part of the session, associated targetId is used.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<GetWindowForTargetResult>
A task representing the asynchronous operation, containing a GetWindowForTargetResult.
GrantPermissionsAsync(ImmutableArray<PermissionType>, string?, BrowserContextID?, string?, CancellationToken)
Grant specific permissions to the given origin and reject all others. Deprecated. Use setPermission instead.
[Experimental("BIDICDP001")]
[Obsolete]
Task<GrantPermissionsResult> GrantPermissionsAsync(ImmutableArray<PermissionType> permissions, string? origin = null, BrowserContextID? browserContextId = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
permissionsImmutableArray<PermissionType>originstringOrigin the permission applies to, all origins if not specified.
browserContextIdBrowserContextIDBrowserContext to override permissions. When omitted, default browser context is used.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<GrantPermissionsResult>
A task representing the asynchronous operation, containing a GrantPermissionsResult.
ResetPermissionsAsync(BrowserContextID?, string?, CancellationToken)
Reset all permission management for all origins.
Task<ResetPermissionsResult> ResetPermissionsAsync(BrowserContextID? browserContextId = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
browserContextIdBrowserContextIDBrowserContext to reset permissions. When omitted, default browser context is used.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<ResetPermissionsResult>
A task representing the asynchronous operation, containing a ResetPermissionsResult.
SetContentsSizeAsync(WindowID, long?, long?, string?, CancellationToken)
Set size of the browser contents resizing browser window as necessary.
[Experimental("BIDICDP001")]
Task<SetContentsSizeResult> SetContentsSizeAsync(WindowID windowId, long? width = null, long? height = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
windowIdWindowIDBrowser window id.
widthlong?The window contents width in DIP. Assumes current width if omitted. Must be specified if 'height' is omitted.
heightlong?The window contents height in DIP. Assumes current height if omitted. Must be specified if 'width' is omitted.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<SetContentsSizeResult>
A task representing the asynchronous operation, containing a SetContentsSizeResult.
SetDockTileAsync(string?, string?, string?, CancellationToken)
Set dock tile details, platform-specific.
[Experimental("BIDICDP001")]
Task<SetDockTileResult> SetDockTileAsync(string? badgeLabel = null, string? image = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
badgeLabelstringimagestringPng encoded image. (Encoded as a base64 string when passed over JSON)
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<SetDockTileResult>
A task representing the asynchronous operation, containing a SetDockTileResult.
SetDownloadBehaviorAsync(string, BrowserContextID?, string?, bool?, string?, CancellationToken)
Set the behavior when downloading a file.
[Experimental("BIDICDP001")]
Task<SetDownloadBehaviorResult> SetDownloadBehaviorAsync(string behavior, BrowserContextID? browserContextId = null, string? downloadPath = null, bool? eventsEnabled = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
behaviorstringWhether to allow all or deny all download requests, or use default Chrome behavior if available (otherwise deny). |allowAndName| allows download and names files according to their download guids.
browserContextIdBrowserContextIDBrowserContext to set download behavior. When omitted, default browser context is used.
downloadPathstringThe default path to save downloaded files to. This is required if behavior is set to 'allow' or 'allowAndName'.
eventsEnabledbool?Whether to emit download events (defaults to false).
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<SetDownloadBehaviorResult>
A task representing the asynchronous operation, containing a SetDownloadBehaviorResult.
SetGlobalPrivacyControlAsync(bool, string?, CancellationToken)
Sets and then gets the current globally-applied privacy control status See https://www.w3.org/TR/gpc/#set-global-privacy-control
[Experimental("BIDICDP001")]
Task<SetGlobalPrivacyControlResult> SetGlobalPrivacyControlAsync(bool gpc, string? session = null, CancellationToken cancellationToken = default)
Parameters
gpcboolsessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<SetGlobalPrivacyControlResult>
A task representing the asynchronous operation, containing a SetGlobalPrivacyControlResult.
SetPermissionAsync(PermissionDescriptor, PermissionSetting, string?, string?, BrowserContextID?, string?, CancellationToken)
Set permission settings for given embedding and embedded origins.
[Experimental("BIDICDP001")]
Task<SetPermissionResult> SetPermissionAsync(PermissionDescriptor permission, PermissionSetting setting, string? origin = null, string? embeddedOrigin = null, BrowserContextID? browserContextId = null, string? session = null, CancellationToken cancellationToken = default)
Parameters
permissionPermissionDescriptorDescriptor of permission to override.
settingPermissionSettingSetting of the permission.
originstringEmbedding origin the permission applies to, all origins if not specified.
embeddedOriginstringEmbedded origin the permission applies to. It is ignored unless the embedding origin is present and valid. If the embedding origin is provided but the embedded origin isn't, the embedding origin is used as the embedded origin.
browserContextIdBrowserContextIDContext to override. When omitted, default browser context is used.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<SetPermissionResult>
A task representing the asynchronous operation, containing a SetPermissionResult.
SetWindowBoundsAsync(WindowID, Bounds, string?, CancellationToken)
Set position and/or size of the browser window.
[Experimental("BIDICDP001")]
Task<SetWindowBoundsResult> SetWindowBoundsAsync(WindowID windowId, Bounds bounds, string? session = null, CancellationToken cancellationToken = default)
Parameters
windowIdWindowIDBrowser window id.
boundsBoundsNew window bounds. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged.
sessionstringOptional CDP session override.
cancellationTokenCancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<SetWindowBoundsResult>
A task representing the asynchronous operation, containing a SetWindowBoundsResult.