public NavigatorWatcher(
            CDPSession client,
            FrameManager frameManager,
            Frame mainFrame,
            NetworkManager networkManager,
            int timeout,
            NavigationOptions options)
        {
            var waitUntil = _defaultWaitUntil;

            if (options?.WaitUntil != null)
            {
                waitUntil = options.WaitUntil;
            }

            _expectedLifecycle = waitUntil.Select(w =>
            {
                var protocolEvent = _puppeteerToProtocolLifecycle.GetValueOrDefault(w);
                Contract.Assert(protocolEvent != null, $"Unknown value for options.waitUntil: {w}");
                return(protocolEvent);
            });

            _frameManager              = frameManager;
            _networkManager            = networkManager;
            _frame                     = mainFrame;
            _initialLoaderId           = mainFrame.LoaderId;
            _hasSameDocumentNavigation = false;

            frameManager.LifecycleEvent += CheckLifecycleComplete;
            frameManager.FrameNavigatedWithinDocument += NavigatedWithinDocument;
            frameManager.FrameDetached += OnFrameDetached;
            networkManager.Request     += OnRequest;
            _connection         = Connection.FromSession(client);
            _connection.Closed += OnConnectionClosed;

            _sameDocumentNavigationTaskWrapper = new TaskCompletionSource <bool>();
            _newDocumentNavigationTaskWrapper  = new TaskCompletionSource <bool>();
            _terminationTaskWrapper            = new TaskCompletionSource <bool>();
            _timeoutTask = TaskHelper.CreateTimeoutTask(timeout);
        }
        public NavigationWatcher(FrameManager frameManager, Frame mainFrame, int timeout, dynamic options)
        {
            var waitUntil = new[] { "load" };

            if (options != null && options.waitUntil is Array)
            {
                waitUntil = options.waitUntil;
            }
            else if (options != null && options.waitUntil is string)
            {
                waitUntil = new string[] { options.waitUntil.ToString() };
            }

            _expectedLifecycle = waitUntil.Select(w =>
            {
                var protocolEvent = _puppeteerToProtocolLifecycle.GetValueOrDefault(w);
                Contract.Assert(protocolEvent != null, $"Unknown value for options.waitUntil: {w}");
                return(protocolEvent);
            });

            _frameManager    = frameManager;
            _frame           = mainFrame;
            _options         = options;
            _initialLoaderId = mainFrame.LoaderId;
            _timeout         = timeout;

            frameManager.LifecycleEvent += FrameManager_LifecycleEvent;
            frameManager.FrameDetached  += FrameManager_LifecycleEvent;
            LifeCycleCompleteTaskWrapper = new TaskCompletionSource <bool>();

            NavigationTask = Task.WhenAny(new[]
            {
                CreateTimeoutTask(),
                LifeCycleCompleteTask,
            }).ContinueWith((task) =>
            {
                CleanUp();
            });
        }
        public LifecycleWatcher(
            FrameManager frameManager,
            Frame frame,
            int timeout,
            NavigationOptions options)
        {
            var waitUntil = _defaultWaitUntil;

            if (options?.WaitUntil != null)
            {
                waitUntil = options.WaitUntil;
            }

            _expectedLifecycle = waitUntil.Select(w =>
            {
                var protocolEvent = _puppeteerToProtocolLifecycle.GetValueOrDefault(w);
                Contract.Assert(protocolEvent != null, $"Unknown value for options.waitUntil: {w}");
                return(protocolEvent);
            });

            _frameManager              = frameManager;
            _frame                     = frame;
            _options                   = options;
            _initialLoaderId           = frame.LoaderId;
            _timeout                   = timeout;
            _hasSameDocumentNavigation = false;

            _sameDocumentNavigationTaskWrapper = new TaskCompletionSource <bool>();
            _newDocumentNavigationTaskWrapper  = new TaskCompletionSource <bool>();
            _lifecycleTaskWrapper   = new TaskCompletionSource <bool>();
            _terminationTaskWrapper = new TaskCompletionSource <bool>();

            frameManager.LifecycleEvent += CheckLifecycleComplete;
            frameManager.FrameNavigatedWithinDocument += NavigatedWithinDocument;
            frameManager.FrameDetached          += OnFrameDetached;
            frameManager.NetworkManager.Request += OnRequest;
            frameManager.Client.Disconnected    += OnClientDisconnected;
        }
        public NavigatorWatcher(FrameManager frameManager, Frame mainFrame, int timeout, NavigationOptions options)
        {
            var waitUntil = new[] { WaitUntilNavigation.Load };

            if (options?.WaitUntil != null)
            {
                waitUntil = options.WaitUntil;
            }

            _expectedLifecycle = waitUntil.Select(w =>
            {
                var protocolEvent = _puppeteerToProtocolLifecycle.GetValueOrDefault(w);
                Contract.Assert(protocolEvent != null, $"Unknown value for options.waitUntil: {w}");
                return(protocolEvent);
            });

            _frameManager              = frameManager;
            _frame                     = mainFrame;
            _options                   = options;
            _initialLoaderId           = mainFrame.LoaderId;
            _timeout                   = timeout;
            _hasSameDocumentNavigation = false;

            frameManager.LifecycleEvent += CheckLifecycleComplete;
            frameManager.FrameNavigatedWithinDocument += NavigatedWithinDocument;
            frameManager.FrameDetached  += CheckLifecycleComplete;
            LifeCycleCompleteTaskWrapper = new TaskCompletionSource <bool>();

            NavigationTask = Task.WhenAny(new[]
            {
                TaskHelper.CreateTimeoutTask(_timeout),
                LifeCycleCompleteTask
            }).ContinueWith((task) =>
            {
                CleanUp();
                return(task.GetAwaiter().GetResult());
            });
        }
Esempio n. 5
0
 public NetworkManager(Session client, FrameManager frameManager)
 {
     _frameManager            = frameManager;
     _client                  = client;
     _client.MessageReceived += Client_MessageReceived;
 }