/// <summary> /// Initializes a new instance of the <see cref="Dialog"/> class. /// </summary> /// <param name="client">Client.</param> /// <param name="type">Type.</param> /// <param name="message">Message.</param> /// <param name="defaultValue">Default value.</param> public Dialog(CDPSession client, DialogType type, string message, string defaultValue) { _client = client; DialogType = type; Message = message; DefaultValue = defaultValue; }
internal Worker( CDPSession client, string url, Func <ConsoleType, JSHandle[], StackTrace, Task> consoleAPICalled, Action <EvaluateExceptionResponseDetails> exceptionThrown) { _logger = client.Connection.LoggerFactory.CreateLogger <Worker>(); _client = client; Url = url; _consoleAPICalled = consoleAPICalled; _exceptionThrown = exceptionThrown; _client.MessageReceived += OnMessageReceived; _executionContextCallback = new TaskCompletionSource <ExecutionContext>(TaskCreationOptions.RunContinuationsAsynchronously); _ = _client.SendAsync("Runtime.enable").ContinueWith(task => { if (task.IsFaulted) { _logger.LogError(task.Exception.Message); } }); _ = _client.SendAsync("Log.enable").ContinueWith(task => { if (task.IsFaulted) { _logger.LogError(task.Exception.Message); } }); }
internal static async Task <FrameManager> CreateFrameManagerAsync( CDPSession client, Page page, bool ignoreHTTPSErrors, TimeoutSettings timeoutSettings) { var frameManager = new FrameManager(client, page, ignoreHTTPSErrors, timeoutSettings); var getFrameTreeTask = client.SendAsync <PageGetFrameTreeResponse>("Page.getFrameTree"); await Task.WhenAll( client.SendAsync("Page.enable"), getFrameTreeTask).ConfigureAwait(false); await frameManager.HandleFrameTreeAsync(new FrameTree(getFrameTreeTask.Result.FrameTree)).ConfigureAwait(false); await Task.WhenAll( client.SendAsync("Page.setLifecycleEventsEnabled", new PageSetLifecycleEventsEnabledRequest { Enabled = true }), client.SendAsync("Runtime.enable"), frameManager.NetworkManager.InitializeAsync()).ConfigureAwait(false); await frameManager.EnsureIsolatedWorldAsync().ConfigureAwait(false); return(frameManager); }
internal Response( CDPSession client, Request request, ResponsePayload responseMessage) { _client = client; Request = request; Status = responseMessage.Status; StatusText = responseMessage.StatusText; Url = request.Url; _fromDiskCache = responseMessage.FromDiskCache; FromServiceWorker = responseMessage.FromServiceWorker; Headers = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase); if (responseMessage.Headers != null) { foreach (var keyValue in responseMessage.Headers) { Headers[keyValue.Key] = keyValue.Value; } } SecurityDetails = responseMessage.SecurityDetails; RemoteAddress = new RemoteAddress { IP = responseMessage.RemoteIPAddress, Port = responseMessage.RemotePort }; BodyLoadedTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.None); }
internal JSHandle(ExecutionContext context, CDPSession client, object remoteObject) { ExecutionContext = context; Client = client; Logger = Client.Connection.LoggerFactory.CreateLogger(this.GetType()); RemoteObject = remoteObject; }
internal static async Task <FrameManager> CreateFrameManagerAsync(CDPSession client, Page page, NetworkManager networkManager, FrameTree frameTree) { var frameManager = new FrameManager(client, page, networkManager); await frameManager.HandleFrameTreeAsync(frameTree).ConfigureAwait(false); return(frameManager); }
internal Request( CDPSession client, string requestId, string interceptionId, bool isNavigationRequest, bool allowInterception, string url, ResourceType resourceType, Payload payload, Frame frame, List <Request> redirectChain) { _client = client; _allowInterception = allowInterception; _interceptionHandled = false; _logger = _client.Connection.LoggerFactory.CreateLogger <Request>(); RequestId = requestId; InterceptionId = interceptionId; IsNavigationRequest = isNavigationRequest; Url = url; ResourceType = resourceType; Method = payload.Method; PostData = payload.PostData; Frame = frame; RedirectChainList = redirectChain; Headers = new Dictionary <string, object>(); foreach (var keyValue in payload.Headers) { Headers[keyValue.Key] = keyValue.Value; } FromMemoryCache = false; }
internal NetworkManager(CDPSession client) { FrameManager = null; _client = client; _client.MessageReceived += Client_MessageReceived; _logger = _client.Connection.LoggerFactory.CreateLogger <NetworkManager>(); }
internal Request( CDPSession client, Frame frame, string interceptionId, bool allowInterception, RequestWillBeSentPayload e, List <Request> redirectChain) { _client = client; _allowInterception = allowInterception; _interceptionHandled = false; _logger = _client.Connection.LoggerFactory.CreateLogger <Request>(); RequestId = e.RequestId; InterceptionId = interceptionId; IsNavigationRequest = e.RequestId == e.LoaderId && e.Type == ResourceType.Document; Url = e.Request.Url; ResourceType = e.Type; Method = e.Request.Method; PostData = e.Request.PostData; Frame = frame; RedirectChainList = redirectChain; Headers = new Dictionary <string, string>(); foreach (var keyValue in e.Request.Headers) { Headers[keyValue.Key] = keyValue.Value; } FromMemoryCache = false; }
internal ExecutionContext(CDPSession client, ContextPayload contextPayload, Func <dynamic, JSHandle> objectHandleFactory) { _client = client; _contextId = contextPayload.Id; FrameId = contextPayload.AuxData.FrameId; IsDefault = contextPayload.AuxData.IsDefault; ObjectHandleFactory = objectHandleFactory; }
internal async Task <CDPSession> CreateSessionAsync(string targetId) { string sessionId = (await SendAsync("Target.attachToTarget", new { targetId }).ConfigureAwait(false)).sessionId; var session = new CDPSession(this, targetId, sessionId); _sessions.Add(sessionId, session); return(session); }
internal NetworkManager(CDPSession client, bool ignoreHTTPSErrors, FrameManager frameManager) { FrameManager = frameManager; _client = client; _ignoreHTTPSErrors = ignoreHTTPSErrors; _client.MessageReceived += Client_MessageReceived; _logger = _client.Connection.LoggerFactory.CreateLogger <NetworkManager>(); }
internal ExecutionContext( CDPSession client, ContextPayload contextPayload, Frame frame) { _client = client; _contextId = contextPayload.Id; Frame = frame; }
internal ExecutionContext( CDPSession client, ContextPayload contextPayload, DOMWorld world) { _client = client; _contextId = contextPayload.Id; World = world; }
internal static IConnection FromSession(CDPSession session) { var connection = session.Connection; while (connection is CDPSession) { connection = connection.Connection; } return(connection); }
internal async Task <CDPSession> CreateSessionAsync(TargetInfo targetInfo) { var sessionId = (await SendAsync("Target.attachToTarget", new { targetId = targetInfo.TargetId }).ConfigureAwait(false))[MessageKeys.SessionId].AsString(); var session = new CDPSession(this, targetInfo.Type, sessionId); _sessions.TryAdd(sessionId, session); return(session); }
internal async Task <CDPSession> CreateSessionAsync(TargetInfo targetInfo) { var sessionId = (await SendAsync <TargetAttachToTargetResponse>("Target.attachToTarget", new TargetAttachToTargetRequest { TargetId = targetInfo.TargetId }).ConfigureAwait(false)).SessionId; var session = new CDPSession(this, targetInfo.Type, sessionId); _sessions.TryAdd(sessionId, session); return(session); }
internal FrameManager(CDPSession client, FrameTree frameTree, Page page) { _client = client; Page = page; Frames = new Dictionary <string, Frame>(); _contextIdToContext = new Dictionary <int, ExecutionContext>(); _logger = _client.Connection.LoggerFactory.CreateLogger <FrameManager>(); _client.MessageReceived += _client_MessageReceived; HandleFrameTree(frameTree); }
internal ElementHandle( ExecutionContext context, CDPSession client, RemoteObject remoteObject, Page page, FrameManager frameManager) : base(context, client, remoteObject) { Page = page; _frameManager = frameManager; _logger = client.LoggerFactory.CreateLogger <ElementHandle>(); }
internal ExecutionContext( CDPSession client, ContextPayload contextPayload, Func <ExecutionContext, dynamic, JSHandle> objectHandleFactory, Frame frame) { _client = client; _contextId = contextPayload.Id; ObjectHandleFactory = objectHandleFactory; Frame = frame; }
internal ElementHandle( ExecutionContext context, CDPSession client, object remoteObject, Page page, FrameManager frameManager) : base(context, client, remoteObject) { Page = page; _frameManager = frameManager; }
private FrameManager(CDPSession client, Page page, bool ignoreHTTPSErrors, TimeoutSettings timeoutSettings) { Client = client; Page = page; _frames = new ConcurrentDictionary <string, Frame>(); _contextIdToContext = new Dictionary <int, ExecutionContext>(); NetworkManager = new NetworkManager(client, ignoreHTTPSErrors, this); TimeoutSettings = timeoutSettings; _asyncFrames = new AsyncDictionaryHelper <string, Frame>(_frames, "Frame {0} not found"); Client.MessageReceived += Client_MessageReceived; }
private FrameManager(CDPSession client, Page page, NetworkManager networkManager) { Client = client; Page = page; _frames = new ConcurrentDictionary <string, Frame>(); _contextIdToContext = new Dictionary <int, ExecutionContext>(); _logger = Client.Connection.LoggerFactory.CreateLogger <FrameManager>(); NetworkManager = networkManager; _pendingFrameRequests = new MultiMap <string, TaskCompletionSource <Frame> >(); Client.MessageReceived += Client_MessageReceived; }
private FrameManager(CDPSession client, Page page, NetworkManager networkManager) { Client = client; Page = page; _frames = new ConcurrentDictionary <string, Frame>(); _contextIdToContext = new Dictionary <int, ExecutionContext>(); _logger = Client.Connection.LoggerFactory.CreateLogger <FrameManager>(); NetworkManager = networkManager; _asyncFrames = new AsyncDictionaryHelper <string, Frame>(_frames, "Frame {0} not found"); Client.MessageReceived += Client_MessageReceived; }
private void ProcessIncomingMessage(ConnectionResponse obj) { var method = obj.Method; var param = obj.Params?.ToObject <ConnectionResponseParams>(); if (method == "Target.attachedToTarget") { var sessionId = param.SessionId; var session = new CDPSession(this, param.TargetInfo.Type, sessionId); _asyncSessions.AddItem(sessionId, session); SessionAttached?.Invoke(this, new SessionAttachedEventArgs { Session = session }); if (obj.SessionId != null && _sessions.TryGetValue(obj.SessionId, out var parentSession)) { parentSession.OnSessionAttached(session); } } else if (method == "Target.detachedFromTarget") { var sessionId = param.SessionId; if (_sessions.TryRemove(sessionId, out var session) && !session.IsClosed) { session.Close("Target.detachedFromTarget"); } } if (!string.IsNullOrEmpty(obj.SessionId)) { var session = GetSession(obj.SessionId); session?.OnMessage(obj); } else if (obj.Id.HasValue) { // If we get the object we are waiting for we return if // if not we add this to the list, sooner or later some one will come for it if (_callbacks.TryRemove(obj.Id.Value, out var callback)) { MessageQueue.Enqueue(callback, obj); } } else { MessageReceived?.Invoke(this, new MessageEventArgs { MessageID = method, MessageData = obj.Params }); } }
internal Response(CDPSession client, Request request, HttpStatusCode status, Dictionary <string, object> headers, SecurityDetails securityDetails) { _client = client; Request = request; Status = status; Ok = (int)status >= 200 && (int)status <= 299; Url = request.Url; Headers = new Dictionary <string, object>(); foreach (KeyValuePair <string, object> keyValue in headers) { Headers[keyValue.Key] = keyValue.Value; } SecurityDetails = securityDetails; }
internal Frame(CDPSession client, Frame parentFrame, string frameId) { _client = client; ParentFrame = parentFrame; Id = frameId; if (parentFrame != null) { ParentFrame.ChildFrames.Add(this); } SetDefaultContext(null); WaitTasks = new List <WaitTask>(); LifecycleEvents = new List <string>(); }
private async Task NavigateAsync(CDPSession client, string url, string referrer, string frameId) { var response = await client.SendAsync <PageNavigateResponse>("Page.navigate", new { url, referrer = referrer ?? string.Empty, frameId }).ConfigureAwait(false); _ensureNewDocumentNavigation = !string.IsNullOrEmpty(response.LoaderId); if (!string.IsNullOrEmpty(response.ErrorText)) { throw new NavigationException(response.ErrorText, url); } }
internal Frame(FrameManager frameManager, CDPSession client, Frame parentFrame, string frameId) { FrameManager = frameManager; _client = client; ParentFrame = parentFrame; Id = frameId; if (parentFrame != null) { ParentFrame.ChildFrames.Add(this); } WaitTasks = new List <WaitTask>(); LifecycleEvents = new List <string>(); _mainWorld = new DOMWorld(FrameManager, this); }
internal Frame(FrameManager frameManager, CDPSession client, Frame parentFrame, string frameId) { FrameManager = frameManager; _client = client; ParentFrame = parentFrame; Id = frameId; LifecycleEvents = new List <string>(); MainWorld = new DOMWorld(FrameManager, this, FrameManager.TimeoutSettings); SecondaryWorld = new DOMWorld(FrameManager, this, FrameManager.TimeoutSettings); if (parentFrame != null) { ParentFrame.AddChildFrame(this); } }