// Copyright © 2020 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
namespace CefSharp.DevTools.Target
{
using System.Linq;
///
/// Supports additional targets discovery and allows to attach to them.
///
public partial class Target : DevToolsDomainBase
{
private CefSharp.DevTools.IDevToolsClient _client;
public Target(CefSharp.DevTools.IDevToolsClient client)
{
_client = (client);
}
partial void ValidateActivateTarget(string targetId);
///
/// Activates (focuses) the target.
///
/// targetId
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task ActivateTargetAsync(string targetId)
{
ValidateActivateTarget(targetId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("targetId", targetId);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.activateTarget", dict);
return methodResult;
}
partial void ValidateAttachToTarget(string targetId, bool? flatten = null);
///
/// Attaches to the target with given id.
///
/// targetId
/// Enables "flat" access to the session via specifying sessionId attribute in the commands.We plan to make this the default, deprecate non-flattened mode,and eventually retire it. See crbug.com/991325.
/// returns System.Threading.Tasks.Task<AttachToTargetResponse>
public async System.Threading.Tasks.Task AttachToTargetAsync(string targetId, bool? flatten = null)
{
ValidateAttachToTarget(targetId, flatten);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("targetId", targetId);
if (flatten.HasValue)
{
dict.Add("flatten", flatten.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.attachToTarget", dict);
return methodResult.DeserializeJson();
}
///
/// Attaches to the browser target, only uses flat sessionId mode.
///
/// returns System.Threading.Tasks.Task<AttachToBrowserTargetResponse>
public async System.Threading.Tasks.Task AttachToBrowserTargetAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.attachToBrowserTarget", dict);
return methodResult.DeserializeJson();
}
partial void ValidateCloseTarget(string targetId);
///
/// Closes the target. If the target is a page that gets closed too.
///
/// targetId
/// returns System.Threading.Tasks.Task<CloseTargetResponse>
public async System.Threading.Tasks.Task CloseTargetAsync(string targetId)
{
ValidateCloseTarget(targetId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("targetId", targetId);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.closeTarget", dict);
return methodResult.DeserializeJson();
}
partial void ValidateExposeDevToolsProtocol(string targetId, string bindingName = null);
///
/// Inject object to the target's main frame that provides a communication
/// channel with browser target.
///
/// Injected object will be available as `window[bindingName]`.
///
/// The object has the follwing API:
/// - `binding.send(json)` - a method to send messages over the remote debugging protocol
/// - `binding.onmessage = json => handleMessage(json)` - a callback that will be called for the protocol notifications and command responses.
///
/// targetId
/// Binding name, 'cdp' if not specified.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task ExposeDevToolsProtocolAsync(string targetId, string bindingName = null)
{
ValidateExposeDevToolsProtocol(targetId, bindingName);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("targetId", targetId);
if (!(string.IsNullOrEmpty(bindingName)))
{
dict.Add("bindingName", bindingName);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.exposeDevToolsProtocol", dict);
return methodResult;
}
partial void ValidateCreateBrowserContext(bool? disposeOnDetach = null, string proxyServer = null, string proxyBypassList = null);
///
/// Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than
/// one.
///
/// If specified, disposes this context when debugging session disconnects.
/// Proxy server, similar to the one passed to --proxy-server
/// Proxy bypass list, similar to the one passed to --proxy-bypass-list
/// returns System.Threading.Tasks.Task<CreateBrowserContextResponse>
public async System.Threading.Tasks.Task CreateBrowserContextAsync(bool? disposeOnDetach = null, string proxyServer = null, string proxyBypassList = null)
{
ValidateCreateBrowserContext(disposeOnDetach, proxyServer, proxyBypassList);
var dict = new System.Collections.Generic.Dictionary();
if (disposeOnDetach.HasValue)
{
dict.Add("disposeOnDetach", disposeOnDetach.Value);
}
if (!(string.IsNullOrEmpty(proxyServer)))
{
dict.Add("proxyServer", proxyServer);
}
if (!(string.IsNullOrEmpty(proxyBypassList)))
{
dict.Add("proxyBypassList", proxyBypassList);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.createBrowserContext", dict);
return methodResult.DeserializeJson();
}
///
/// Returns all browser contexts created with `Target.createBrowserContext` method.
///
/// returns System.Threading.Tasks.Task<GetBrowserContextsResponse>
public async System.Threading.Tasks.Task GetBrowserContextsAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.getBrowserContexts", dict);
return methodResult.DeserializeJson();
}
partial void ValidateCreateTarget(string url, int? width = null, int? height = null, string browserContextId = null, bool? enableBeginFrameControl = null, bool? newWindow = null, bool? background = null);
///
/// Creates a new page.
///
/// The initial URL the page will be navigated to.
/// Frame width in DIP (headless chrome only).
/// Frame height in DIP (headless chrome only).
/// The browser context to create the page in.
/// Whether BeginFrames for this target will be controlled via DevTools (headless chrome only,not supported on MacOS yet, false by default).
/// Whether to create a new Window or Tab (chrome-only, false by default).
/// Whether to create the target in background or foreground (chrome-only,false by default).
/// returns System.Threading.Tasks.Task<CreateTargetResponse>
public async System.Threading.Tasks.Task CreateTargetAsync(string url, int? width = null, int? height = null, string browserContextId = null, bool? enableBeginFrameControl = null, bool? newWindow = null, bool? background = null)
{
ValidateCreateTarget(url, width, height, browserContextId, enableBeginFrameControl, newWindow, background);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("url", url);
if (width.HasValue)
{
dict.Add("width", width.Value);
}
if (height.HasValue)
{
dict.Add("height", height.Value);
}
if (!(string.IsNullOrEmpty(browserContextId)))
{
dict.Add("browserContextId", browserContextId);
}
if (enableBeginFrameControl.HasValue)
{
dict.Add("enableBeginFrameControl", enableBeginFrameControl.Value);
}
if (newWindow.HasValue)
{
dict.Add("newWindow", newWindow.Value);
}
if (background.HasValue)
{
dict.Add("background", background.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.createTarget", dict);
return methodResult.DeserializeJson();
}
partial void ValidateDetachFromTarget(string sessionId = null, string targetId = null);
///
/// Detaches session with given id.
///
/// Session to detach.
/// Deprecated.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task DetachFromTargetAsync(string sessionId = null, string targetId = null)
{
ValidateDetachFromTarget(sessionId, targetId);
var dict = new System.Collections.Generic.Dictionary();
if (!(string.IsNullOrEmpty(sessionId)))
{
dict.Add("sessionId", sessionId);
}
if (!(string.IsNullOrEmpty(targetId)))
{
dict.Add("targetId", targetId);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.detachFromTarget", dict);
return methodResult;
}
partial void ValidateDisposeBrowserContext(string browserContextId);
///
/// Deletes a BrowserContext. All the belonging pages will be closed without calling their
/// beforeunload hooks.
///
/// browserContextId
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task DisposeBrowserContextAsync(string browserContextId)
{
ValidateDisposeBrowserContext(browserContextId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("browserContextId", browserContextId);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.disposeBrowserContext", dict);
return methodResult;
}
partial void ValidateGetTargetInfo(string targetId = null);
///
/// Returns information about a target.
///
/// targetId
/// returns System.Threading.Tasks.Task<GetTargetInfoResponse>
public async System.Threading.Tasks.Task GetTargetInfoAsync(string targetId = null)
{
ValidateGetTargetInfo(targetId);
var dict = new System.Collections.Generic.Dictionary();
if (!(string.IsNullOrEmpty(targetId)))
{
dict.Add("targetId", targetId);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.getTargetInfo", dict);
return methodResult.DeserializeJson();
}
///
/// Retrieves a list of available targets.
///
/// returns System.Threading.Tasks.Task<GetTargetsResponse>
public async System.Threading.Tasks.Task GetTargetsAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.getTargets", dict);
return methodResult.DeserializeJson();
}
partial void ValidateSetAutoAttach(bool autoAttach, bool waitForDebuggerOnStart, bool? flatten = null);
///
/// Controls whether to automatically attach to new targets which are considered to be related to
/// this one. When turned on, attaches to all existing related targets as well. When turned off,
/// automatically detaches from all currently attached targets.
///
/// Whether to auto-attach to related targets.
/// Whether to pause new targets when attaching to them. Use `Runtime.runIfWaitingForDebugger`to run paused targets.
/// Enables "flat" access to the session via specifying sessionId attribute in the commands.We plan to make this the default, deprecate non-flattened mode,and eventually retire it. See crbug.com/991325.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetAutoAttachAsync(bool autoAttach, bool waitForDebuggerOnStart, bool? flatten = null)
{
ValidateSetAutoAttach(autoAttach, waitForDebuggerOnStart, flatten);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("autoAttach", autoAttach);
dict.Add("waitForDebuggerOnStart", waitForDebuggerOnStart);
if (flatten.HasValue)
{
dict.Add("flatten", flatten.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.setAutoAttach", dict);
return methodResult;
}
partial void ValidateSetDiscoverTargets(bool discover);
///
/// Controls whether to discover available targets and notify via
/// `targetCreated/targetInfoChanged/targetDestroyed` events.
///
/// Whether to discover available targets.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetDiscoverTargetsAsync(bool discover)
{
ValidateSetDiscoverTargets(discover);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("discover", discover);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.setDiscoverTargets", dict);
return methodResult;
}
partial void ValidateSetRemoteLocations(System.Collections.Generic.IList locations);
///
/// Enables target discovery for the specified locations, when `setDiscoverTargets` was set to
/// `true`.
///
/// List of remote locations.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetRemoteLocationsAsync(System.Collections.Generic.IList locations)
{
ValidateSetRemoteLocations(locations);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("locations", locations.Select(x => x.ToDictionary()));
var methodResult = await _client.ExecuteDevToolsMethodAsync("Target.setRemoteLocations", dict);
return methodResult;
}
}
}