Exemplo n.º 1
0
        private async Task CreateTargetAsync(TargetTargetCreatedChromiumEvent e)
        {
            var    targetInfo       = e.TargetInfo;
            string browserContextId = targetInfo.BrowserContextId;

            if (!(browserContextId != null && _contexts.TryGetValue(browserContextId, out var context)))
            {
                context = DefaultContext;
            }

            var target = new ChromiumTarget(
                e.TargetInfo,
                this,
                () => _connection.CreateSessionAsync(targetInfo),
                context);

            if (TargetsMap.ContainsKey(e.TargetInfo.TargetId))
            {
                // TODO add logger
                // _logger.LogError("Target should not exist before targetCreated");
            }

            TargetsMap[e.TargetInfo.TargetId] = target;

            if (await target.InitializedTask.ConfigureAwait(false))
            {
                var args = new TargetChangedArgs {
                    Target = target
                };
                TargetCreated?.Invoke(this, args);
            }
        }
        /// <inheritdoc cref="IBrowser.GetPageTarget(IPage)"/>
        public ITarget GetPageTarget(IPage page)
        {
            if (page == null)
            {
                return(null);
            }

            return(ChromiumTarget.FromPage(page as Page));
        }
 internal Task ClosePageAsync(Page page)
 => _client.SendAsync(new TargetCloseTargetRequest {
     TargetId = ChromiumTarget.FromPage(page).TargetId
 });