public JSCoverage(CDPSession client) { _client = client; _enabled = false; _scriptURLs = new Dictionary <string, string>(); _scriptSources = new Dictionary <string, string>(); _resetOnNavigation = false; }
public JSCoverage(CDPSession client) { _client = client; _enabled = false; _scriptURLs = new Dictionary <string, string>(); _scriptSources = new Dictionary <string, string>(); _logger = _client.Connection.LoggerFactory.CreateLogger <JSCoverage>(); _resetOnNavigation = false; }
internal static async Task ReleaseObject(CDPSession client, dynamic remoteObject, ILogger logger) { if (remoteObject.objectId == null) { return; } try { await client.SendAsync("Runtime.releaseObject", new { remoteObject.objectId }); } catch (Exception ex) { // Exceptions might happen in case of a page been navigated or closed. // Swallow these since they are harmless and we don't leak anything in this case. logger.LogWarning(ex.ToString()); } }
protected static Task <JToken> WaitEvent(CDPSession emitter, string eventName) { var completion = new TaskCompletionSource <JToken>(); void handler(object sender, MessageEventArgs e) { if (e.MessageID != eventName) { return; } emitter.MessageReceived -= handler; completion.SetResult(e.MessageData); } emitter.MessageReceived += handler; return(completion.Task); }
internal static async Task ReleaseObjectAsync(CDPSession client, RemoteObject remoteObject) { if (remoteObject.ObjectId == null) { return; } try { await client.SendAsync("Runtime.releaseObject", new RuntimeReleaseObjectRequest { ObjectId = remoteObject.ObjectId }).ConfigureAwait(false); } catch { } }
internal async Task InitAsync() { var targetId = _page.Target.TargetId; _session = await _page.Target.CreateCDPSessionAsync(); var args = new JObject { { "expression", new JValue("self.paramsForReuse") }, { "returnByValue", new JValue(true) } }; var getParamsForReuseTask = _session.SendAsync("Runtime.evaluate", args); var targetObject = $"{{ targetId: '{targetId}' }}"; var getWindowForTargetTask = _app.Session.SendAsync("Browser.getWindowForTarget", JObject.Parse(targetObject)); var color = new JObject { { "color", new JObject { { "r", new JValue(_options.BgColor.R) }, { "g", new JValue(_options.BgColor.G) }, { "b", new JValue(_options.BgColor.B) }, { "a", new JValue(_options.BgColor.A) }, } } }; await _session.SendAsync("Emulation.setDefaultBackgroundColorOverride", color); var response = await getParamsForReuseTask; _paramsForReuse = response.Value<object>(); var window = await getWindowForTargetTask; await InitBoundsAsync(window); await ConfigureIpcMethodsOnceAsync(); }
public async Task <Dictionary <string, decimal> > AccessPageAndGetMetricsByTrl(string url) { var page = await Browser.NewPageAsync(); CDPSession cpd = await page.Target.CreateCDPSessionAsync(); await cpd.SendAsync("Performance.enable"); var metrics1 = await MetricsAsync(cpd); Response response; try { response = await page.GoToAsync(url); if (response == null) { throw new Exception("Null Response for " + url); } var metrics2 = await MetricsAsync(cpd); System.Threading.Thread.Sleep(10000); var metrics3 = await MetricsAsync(cpd); foreach (var metric1 in metrics1) { var m2 = metrics2[metric1.Key]; var m3 = metrics3[metric1.Key]; Console.WriteLine($"{metric1.Key,30} | {metric1.Value,15} | {m2,15} | {m3,15}"); } return(metrics2); } catch (Exception e) { throw e; } finally { await page.CloseAsync(); } }
internal static async Task ReleaseObject(CDPSession client, JToken remoteObject, ILogger logger) { var objectId = remoteObject[MessageKeys.ObjectId]?.AsString(); if (objectId == null) { return; } try { await client.SendAsync("Runtime.releaseObject", new { objectId }).ConfigureAwait(false); } catch (Exception ex) { // Exceptions might happen in case of a page been navigated or closed. // Swallow these since they are harmless and we don't leak anything in this case. logger.LogWarning(ex.ToString()); } }
internal static async Task <string> ReadProtocolStreamStringAsync(CDPSession client, string handle, string path) { var result = new StringBuilder(); var fs = !string.IsNullOrEmpty(path) ? AsyncFileHelper.CreateStream(path, FileMode.Create) : null; try { var eof = false; while (!eof) { var response = await client.SendAsync <IOReadResponse>("IO.read", new IOReadRequest { Handle = handle }).ConfigureAwait(false); eof = response.Eof; result.Append(response.Data); if (fs != null) { var data = Encoding.UTF8.GetBytes(response.Data); await fs.WriteAsync(data, 0, data.Length).ConfigureAwait(false); } } await client.SendAsync("IO.close", new IOCloseRequest { Handle = handle }).ConfigureAwait(false); return(result.ToString()); } finally { fs?.Dispose(); } }
internal static async Task <byte[]> ReadProtocolStreamByteAsync(CDPSession client, string handle, string path) { IEnumerable <byte> result = null; var eof = false; var fs = !string.IsNullOrEmpty(path) ? AsyncFileHelper.CreateStream(path, FileMode.Create) : null; try { while (!eof) { var response = await client.SendAsync <IOReadResponse>("IO.read", new IOReadRequest { Handle = handle }).ConfigureAwait(false); eof = response.Eof; var data = Convert.FromBase64String(response.Data); result = result == null ? data : result.Concat(data); if (fs != null) { await fs.WriteAsync(data, 0, data.Length).ConfigureAwait(false); } } await client.SendAsync("IO.close", new IOCloseRequest { Handle = handle }).ConfigureAwait(false); return(result.ToArray()); } finally { fs?.Dispose(); } }
/// <summary> /// Initializes a new instance of the <see cref="PuppeteerSharp.PageAccessibility.Accessibility"/> class. /// </summary> /// <param name="client">Client.</param> public Accessibility(CDPSession client) => _client = client;
internal Coverage(CDPSession client) { _jsCoverage = new JSCoverage(client); _cssCoverage = new CSSCoverage(client); }
/// <summary> /// Initializes a new instance of the <see cref="Mouse"/> class. /// </summary> /// <param name="client">The client</param> /// <param name="keyboard">The keyboard</param> public Mouse(CDPSession client, Keyboard keyboard) { _client = client; _keyboard = keyboard; }
internal Keyboard(CDPSession client) { _client = client; }
/// <summary> /// Initializes a new instance of the <see cref="Touchscreen"/> class. /// </summary> /// <param name="client">The client</param> /// <param name="keyboard">The keyboard</param> public Touchscreen(CDPSession client, Keyboard keyboard) { _client = client; _keyboard = keyboard; }
public HttpRequest(CDPSession session, JToken @params, Queue <RequestHandlerAsync> handlers) { _session = session; _params = @params; _handlers = handlers; }
private async Task <Dictionary <string, decimal> > MetricsAsync(CDPSession cdp) { var response = await cdp.SendAsync <PerformanceGetMetricsResponse>("Performance.getMetrics"); return(BuildMetricsObject(response.Metrics)); }