Пример #1
0
        private async Task OnTargetCreatedAsync(TargetTargetCreatedFirefoxEvent payload)
        {
            string targetId         = payload.TargetId;
            string url              = payload.Url;
            string browserContextId = payload.BrowserContextId;
            string openerId         = payload.OpenerId;
            var    type             = payload.Type;

            var context = browserContextId != null ? Contexts[browserContextId] : DefaultContext;
            var target  = new FirefoxTarget(_connection, this, context, targetId, type, url, openerId);

            TargetsMap[targetId] = target;
            var opener = target.Opener;

            if (opener?.PageTask != null)
            {
                var openerPage = await opener.PageTask.ConfigureAwait(false);

                if (openerPage.HasPopupEventListeners)
                {
                    var popupPage = await target.GetPageAsync().ConfigureAwait(false);

                    openerPage.OnPopup(popupPage);
                }
            }

            TargetCreated?.Invoke(this, new TargetChangedArgs {
                Target = target
            });
        }
Пример #2
0
        private async Task CreateTargetAsync(TargetCreatedResponse e)
        {
            var targetInfo       = e.TargetInfo;
            var browserContextId = targetInfo.BrowserContextId;

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

            var target = new Target(
                e.TargetInfo,
                info => Connection.CreateSessionAsync(info),
                context);

            if (TargetsMap.ContainsKey(e.TargetInfo.TargetId))
            {
                _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);
                context.OnTargetCreated(this, args);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
        private async Task CreateTargetAsync(TargetCreatedResponse e)
        {
            var    targetInfo       = e.TargetInfo;
            string browserContextId = targetInfo.BrowserContextId;

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

            var target = new Target(
                e.TargetInfo,
                () => Connection.CreateSessionAsync(targetInfo),
                context);

            TargetsMap[e.TargetInfo.TargetId] = target;

            if (await target.InitializedTask.ConfigureAwait(false))
            {
                var args = new TargetChangedArgs {
                    Target = target
                };
                TargetCreated?.Invoke(this, args);
                context.OnTargetCreated(this, args);
            }
        }
Пример #5
0
        private async Task CreateTarget(TargetCreatedResponse e)
        {
            var target = new Target(this, e.TargetInfo);

            _targets[e.TargetInfo.TargetId] = target;

            if (await target.InitializedTask)
            {
                TargetCreated?.Invoke(this, new TargetChangedArgs()
                {
                    Target = target
                });
            }
        }
Пример #6
0
        private async Task CreateTarget(MessageEventArgs args)
        {
            var targetInfo = new TargetInfo(args.MessageData.targetInfo);
            var target     = new Target(this, targetInfo);

            _targets[targetInfo.TargetId] = target;

            if (await target.InitializedTask)
            {
                TargetCreated?.Invoke(this, new TargetChangedArgs()
                {
                    Target = target
                });
            }
        }
Пример #7
0
        private async Task CreateTargetAsync(TargetCreatedResponse e)
        {
            var target = new Target(
                e.TargetInfo,
                () => Connection.CreateSessionAsync(e.TargetInfo.TargetId),
                this);

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

            TargetsMap[e.TargetInfo.TargetId] = target;

            if (await target.InitializedTask.ConfigureAwait(false))
            {
                TargetCreated?.Invoke(this, new TargetChangedArgs
                {
                    Target = target
                });
            }
        }
Пример #8
0
 internal void OnTargetCreated(Browser browser, TargetChangedArgs args) => TargetCreated?.Invoke(browser, args);