private void ProcessIncomingMessage(ConnectionResponse obj) { if (!obj.Params.HasValue) { GetSession(obj.SessionId ?? string.Empty)?.OnMessage(obj); return; } var param = ChromiumProtocolTypes.ParseEvent(obj.Method, obj.Params.Value.GetRawText()); if (obj.Id == BrowserCloseMessageId) { return; } if (param is TargetAttachedToTargetChromiumEvent targetAttachedToTarget) { string sessionId = targetAttachedToTarget.SessionId; ChromiumSession session = new ChromiumSession(this, targetAttachedToTarget.TargetInfo.GetTargetType(), sessionId); _asyncSessions.AddItem(sessionId, session); } else if (param is TargetDetachedFromTargetChromiumEvent targetDetachedFromTarget) { string sessionId = targetDetachedFromTarget.SessionId; if (_sessions.TryRemove(sessionId, out var session) && !session.IsClosed) { session.OnClosed(targetDetachedFromTarget.InternalName); } } GetSession(obj.SessionId ?? string.Empty).OnMessageReceived(param); }
public CSSCoverage(ChromiumSession client) { _client = client; _enabled = false; _stylesheetURLs = new Dictionary <string, string>(); _stylesheetSources = new Dictionary <string, string>(); _resetOnNavigation = false; }
public ChromiumConnection(IConnectionTransport transport) { _transport = transport; _transport.MessageReceived += Transport_MessageReceived; _transport.Closed += Transport_Closed; RootSession = new ChromiumSession(this, TargetType.Browser, string.Empty); _sessions.TryAdd(string.Empty, RootSession); _asyncSessions = new AsyncDictionaryHelper <string, ChromiumSession>(_sessions, "Session {0} not found"); }
internal ChromiumBrowserContext( ChromiumSession client, ChromiumBrowser chromiumBrowser, string contextId, BrowserContextOptions options) { _client = client; _browser = chromiumBrowser; _contextId = contextId; Options = options; }
public ChromiumPage(ChromiumSession client, ChromiumBrowser browser, IBrowserContext browserContext) { Client = client; _browser = browser; _browserContext = browserContext; _networkManager = new ChromiumNetworkManager(Client, this); RawKeyboard = new ChromiumRawKeyboard(client); RawMouse = new ChromiumRawMouse(client); Page = new Page(this, browserContext); client.MessageReceived += Client_MessageReceived; }
private ChromiumAXNode(ChromiumSession client, AXNode payload) { _client = client; Payload = payload; _name = payload.Name != null?payload.Name.Value.ToString() : string.Empty; _role = payload.Role != null?payload.Role.Value.ToString() : "Unknown"; _richlyEditable = GetPropertyElement(payload, "editable")?.ToString() == "richtext"; _editable |= _richlyEditable; _hidden = GetPropertyElement(payload, "hidden")?.ToObject <bool>() ?? false; Focusable = GetPropertyElement(payload, "focusable")?.ToObject <bool>() ?? false; }
private ChromiumBrowser(ChromiumConnection connection, string[] browserContextIds) { _connection = connection; _client = connection.RootSession; DefaultContext = new BrowserContext(new ChromiumBrowserContext(connection.RootSession, this)); _contexts = browserContextIds.ToDictionary( contextId => contextId, contextId => (IBrowserContext) new BrowserContext(new ChromiumBrowserContext(connection.RootSession, this, contextId, null))); _connection.Disconnected += Connection_OnDisconnected; _client.MessageReceived += Client_MessageReceived; }
private ChromiumBrowser(IBrowserApp app, ChromiumConnection connection, string[] browserContextIds) { _app = app; _connection = connection; _session = connection.RootSession; DefaultContext = new BrowserContext(new ChromiumBrowserContext(connection.RootSession, this)); _contexts = browserContextIds.ToDictionary( contextId => contextId, contextId => (IBrowserContext) new BrowserContext(new ChromiumBrowserContext(connection.RootSession, this, contextId, null))); _session.MessageReceived += Session_MessageReceived; _connection.Disconnected += (sender, e) => Disconnected?.Invoke(this, EventArgs.Empty); }
internal static async Task ReleaseObjectAsync(ChromiumSession client, IRemoteObject remoteObject) { if (string.IsNullOrEmpty(remoteObject.ObjectId)) { return; } try { await client.SendAsync(new RuntimeReleaseObjectRequest { ObjectId = remoteObject.ObjectId, }).ConfigureAwait(false); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }
/// <inheritdoc cref="IBrowser.StartTracingAsync(IPage, TracingOptions)"/> public Task StartTracingAsync(IPage page, TracingOptions options = null) { if (_tracingRecording) { throw new InvalidOperationException("Cannot start recording trace while already recording trace."); } _tracingClient = page != null ? ((ChromiumPage)((Page)page).Delegate).Client : _client; var defaultCategories = new List <string> { "-*", "devtools.timeline", "v8.execute", "disabled-by-default-devtools.timeline", "disabled-by-default-devtools.timeline.frame", "toplevel", "blink.console", "blink.user_timing", "latencyInfo", "disabled-by-default-devtools.timeline.stack", "disabled-by-default-v8.cpu_profiler", }; var categories = options?.Categories ?? defaultCategories; if (options?.Screenshots == true) { categories.Add("disabled-by-default-devtools.screenshot"); } _tracingPath = options?.Path; _tracingRecording = true; return(_tracingClient.SendAsync(new TracingStartRequest { TransferMode = "ReturnAsStream", Categories = string.Join(", ", categories), })); }
internal static async Task <string> ReadProtocolStreamStringAsync(ChromiumSession client, string handle, string path) { var result = new StringBuilder(); var fs = !string.IsNullOrEmpty(path) ? AsyncFileHelper.CreateStream(path, FileMode.Create) : null; try { bool eof = false; while (!eof) { var response = await client.SendAsync(new IOReadRequest { Handle = handle, }).ConfigureAwait(false); eof = response.Eof.Value; 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(new IOCloseRequest { Handle = handle, }).ConfigureAwait(false); return(result.ToString()); } finally { fs?.Dispose(); } }
public ChromiumInterceptableRequest( ChromiumSession client, Frame frame, string interceptionId, string documentId, bool requestInterceptionEnabled, NetworkRequestWillBeSentChromiumEvent e, List <Request> redirectChain) { _client = client; RequestId = e.RequestId; InterceptionId = interceptionId; Request = new Request( requestInterceptionEnabled ? this : null, frame, redirectChain, documentId, e.Request.Url, (e.Type ?? Protocol.Network.ResourceType.Other).ToPlaywrightResourceType(), new HttpMethod(e.Request.Method), e.Request.PostData, e.Request.Headers); }
internal static async Task <byte[]> ReadProtocolStreamByteAsync(ChromiumSession client, string handle, string path) { IEnumerable <byte> result = null; bool eof = false; var fs = !string.IsNullOrEmpty(path) ? AsyncFileHelper.CreateStream(path, FileMode.Create) : null; try { while (!eof) { var response = await client.SendAsync(new IOReadRequest { Handle = handle, }).ConfigureAwait(false); eof = response.Eof.Value; 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(new IOCloseRequest { Handle = handle, }).ConfigureAwait(false); return(result.ToArray()); } finally { fs?.Dispose(); } }
public static ChromiumAXNode CreateTree(ChromiumSession client, AXNode[] payloads) { var nodeById = new Dictionary <string, ChromiumAXNode>(); foreach (var payload in payloads) { nodeById[payload.NodeId] = new ChromiumAXNode(client, payload); } foreach (var node in nodeById.Values) { if (node.Payload.ChildIds == null) { continue; } foreach (string childId in node.Payload.ChildIds) { node.Children.Add(nodeById[childId]); } } return(nodeById.Values.FirstOrDefault()); }
internal ChromiumBrowserContext(ChromiumSession client, ChromiumBrowser chromiumBrowser) : this(client, chromiumBrowser, null, null) { }
internal Coverage(ChromiumSession client) { _jsCoverage = new JSCoverage(client); _cssCoverage = new CSSCoverage(client); }
internal void InstrumentNetworkEvents(ChromiumSession session) => session.MessageReceived += Client_MessageReceived;
public ChromiumExecutionContext(ChromiumSession client, ExecutionContextDescription contextPayload) { _client = client; ContextId = contextPayload.Id.Value; }
public ChromiumNetworkManager(ChromiumSession client, Page page) { _client = client; _page = page; _client.MessageReceived += Client_MessageReceived; }
public ChromiumNetworkManager(ChromiumSession client, ChromiumPage chromiumPage) { _client = client; _chromiumPage = chromiumPage; }
internal static ChromiumConnection FromSession(ChromiumSession client) => client.Connection;
public ChromiumPdf(ChromiumSession client) { _client = client; }