Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Browser"/> class.
        /// </summary>
        /// <param name="connection">The connection</param>
        /// <param name="contextIds">The context ids></param>
        /// <param name="ignoreHTTPSErrors">The option to ignoreHTTPSErrors</param>
        /// <param name="defaultViewport">Default viewport</param>
        /// <param name="chromiumProcess">The Chromium process</param>
        public Browser(
            Connection connection,
            string[] contextIds,
            bool ignoreHTTPSErrors,
            ViewPortOptions defaultViewport,
            ChromiumProcess chromiumProcess)
        {
            SetConnectionAsync(connection, false).Wait();
            IgnoreHTTPSErrors   = ignoreHTTPSErrors;
            DefaultViewport     = defaultViewport;
            TargetsMap          = new ConcurrentDictionary <string, Target>();
            ScreenshotTaskQueue = new TaskQueue();
            DefaultContext      = new BrowserContext(Connection, this, null);
            _contexts           = contextIds.ToDictionary(keySelector: contextId => contextId,
                                                          elementSelector: contextId => new BrowserContext(Connection, this, contextId));

            _chromiumProcess = chromiumProcess;
        }
Exemple #2
0
        internal Target(
            TargetInfo targetInfo,
            Func <Task <CDPSession> > sessionFactory,
            BrowserContext browserContext)
        {
            TargetInfo      = targetInfo;
            _sessionFactory = sessionFactory;
            BrowserContext  = browserContext;
            PageTask        = null;

            _ = _initializedTaskWrapper.Task.ContinueWith(
                async initializedTask =>
            {
                var success = initializedTask.Result;
                if (!success)
                {
                    return;
                }

                var openerPageTask = Opener?.PageTask;
                if (openerPageTask == null || Type != TargetType.Page)
                {
                    return;
                }
                var openerPage = await openerPageTask.ConfigureAwait(false);
                if (!openerPage.HasPopupEventListeners)
                {
                    return;
                }
                var popupPage = await PageAsync().ConfigureAwait(false);
                openerPage.OnPopup(popupPage);
            },
                TaskScheduler.Default);

            CloseTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);
            IsInitialized    = TargetInfo.Type != TargetType.Page || !string.IsNullOrEmpty(TargetInfo.Url);

            if (IsInitialized)
            {
                _initializedTaskWrapper.TrySetResult(true);
            }
        }
Exemple #3
0
        internal Target(
            TargetInfo targetInfo,
            Func <Task <CDPSession> > sessionFactory,
            BrowserContext browserContext)
        {
            _targetInfo     = targetInfo;
            _targetId       = targetInfo.TargetId;
            _sessionFactory = sessionFactory;
            BrowserContext  = browserContext;
            _pageTask       = null;

            InitilizedTaskWrapper = new TaskCompletionSource <bool>();
            CloseTaskWrapper      = new TaskCompletionSource <bool>();
            IsInitialized         = _targetInfo.Type != TargetType.Page || _targetInfo.Url != string.Empty;

            if (IsInitialized)
            {
                InitilizedTaskWrapper.SetResult(true);
            }
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Browser"/> class.
        /// </summary>
        /// <param name="connection">The connection</param>
        /// <param name="contextIds">The context ids></param>
        /// <param name="ignoreHTTPSErrors">The option to ignoreHTTPSErrors</param>
        /// <param name="defaultViewport">Default viewport</param>
        /// <param name="launcher">The launcher</param>
        public Browser(
            Connection connection,
            string[] contextIds,
            bool ignoreHTTPSErrors,
            ViewPortOptions defaultViewport,
            LauncherBase launcher)
        {
            Connection          = connection;
            IgnoreHTTPSErrors   = ignoreHTTPSErrors;
            DefaultViewport     = defaultViewport;
            TargetsMap          = new ConcurrentDictionary <string, Target>();
            ScreenshotTaskQueue = new TaskQueue();
            DefaultContext      = new BrowserContext(Connection, this, null);
            _contexts           = contextIds.ToDictionary(
                contextId => contextId,
                contextId => new BrowserContext(Connection, this, contextId));

            Connection.Disconnected    += Connection_Disconnected;
            Connection.MessageReceived += Connect_MessageReceived;

            Launcher = launcher;
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Browser"/> class.
        /// </summary>
        /// <param name="connection">The connection</param>
        /// <param name="contextIds">The context ids></param>
        /// <param name="ignoreHTTPSErrors">The option to ignoreHTTPSErrors</param>
        /// <param name="setDefaultViewport">The option to setDefaultViewport</param>
        /// <param name="chromiumProcess">The Chromium process</param>
        public Browser(
            Connection connection,
            string[] contextIds,
            bool ignoreHTTPSErrors,
            bool setDefaultViewport,
            ChromiumProcess chromiumProcess)
        {
            Connection          = connection;
            IgnoreHTTPSErrors   = ignoreHTTPSErrors;
            SetDefaultViewport  = setDefaultViewport;
            TargetsMap          = new Dictionary <string, Target>();
            ScreenshotTaskQueue = new TaskQueue();
            _defaultContext     = new BrowserContext(this, null);
            _contexts           = contextIds.ToDictionary(keySelector: contextId => contextId,
                                                          elementSelector: contextId => new BrowserContext(this, contextId));

            Connection.Closed          += (object sender, EventArgs e) => Disconnected?.Invoke(this, new EventArgs());
            Connection.MessageReceived += Connect_MessageReceived;

            _chromiumProcess = chromiumProcess;
            _logger          = Connection.LoggerFactory.CreateLogger <Browser>();
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Browser"/> class.
        /// </summary>
        /// <param name="connection">The connection</param>
        /// <param name="contextIds">The context ids></param>
        /// <param name="ignoreHTTPSErrors">The option to ignoreHTTPSErrors</param>
        /// <param name="defaultViewport">Default viewport</param>
        /// <param name="chromiumProcess">The Chromium process</param>
        public Browser(
            Connection connection,
            string[] contextIds,
            bool ignoreHTTPSErrors,
            ViewPortOptions defaultViewport,
            ChromiumProcess chromiumProcess)
        {
            Connection          = connection;
            IgnoreHTTPSErrors   = ignoreHTTPSErrors;
            DefaultViewport     = defaultViewport;
            TargetsMap          = new ConcurrentDictionary <string, Target>();
            ScreenshotTaskQueue = new TaskQueue();
            DefaultContext      = new BrowserContext(Connection, this, null);
            _contexts           = contextIds.ToDictionary(
                contextId => contextId,
                contextId => new BrowserContext(Connection, this, contextId));

            Connection.Disconnected    += Connection_Disconnected;
            Connection.MessageReceived += Connect_MessageReceived;

            ChromiumProcess = chromiumProcess;
            _logger         = Connection.LoggerFactory.CreateLogger <Browser>();
        }
        internal Browser(
            Connection connection,
            string[] contextIds,
            bool ignoreHTTPSErrors,
            ViewPortOptions defaultViewport,
            LauncherBase launcher,
            Func <TargetInfo, bool> targetFilter)
        {
            Connection          = connection;
            IgnoreHTTPSErrors   = ignoreHTTPSErrors;
            DefaultViewport     = defaultViewport;
            TargetsMap          = new ConcurrentDictionary <string, Target>();
            ScreenshotTaskQueue = new TaskQueue();
            DefaultContext      = new BrowserContext(Connection, this, null);
            _contexts           = new ConcurrentDictionary <string, BrowserContext>(contextIds.ToDictionary(
                                                                                        contextId => contextId,
                                                                                        contextId => new BrowserContext(Connection, this, contextId)));
            Connection.Disconnected    += Connection_Disconnected;
            Connection.MessageReceived += Connect_MessageReceived;

            Launcher = launcher;
            _logger  = Connection.LoggerFactory.CreateLogger <Browser>();
            _targetFilterCallback = targetFilter ?? ((TargetInfo _) => true);
        }