Esempio n. 1
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,
                () => Connection.CreateSessionAsync(targetInfo),
                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);
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        internal void ChangeTarget(Target target)
        {
            var args = new TargetChangedArgs {
                Target = target
            };

            TargetChanged?.Invoke(this, args);
            target.BrowserContext.OnTargetChanged(this, args);
        }
Esempio n. 4
0
        private async Task DestroyTargetAsync(TargetDestroyedResponse e)
        {
            if (!TargetsMap.ContainsKey(e.TargetId))
            {
                throw new InvalidTargetException("Target should exists before DestroyTarget");
            }

            var target = TargetsMap[e.TargetId];

            TargetsMap.Remove(e.TargetId);

            target.CloseTaskWrapper.TrySetResult(true);

            if (await target.InitializedTask.ConfigureAwait(false))
            {
                var args = new TargetChangedArgs {
                    Target = target
                };
                TargetDestroyed?.Invoke(this, args);
                target.BrowserContext.OnTargetDestroyed(this, args);
            }
        }
Esempio n. 5
0
 internal void OnTargetChanged(Browser browser, TargetChangedArgs args) => TargetChanged?.Invoke(browser, args);