Ejemplo n.º 1
0
        private async Task OnExecutionContextCreatedAsync(ContextPayload contextPayload)
        {
            var frameId = contextPayload.AuxData?.FrameId;
            var frame   = !string.IsNullOrEmpty(frameId) ? await GetFrameAsync(frameId).ConfigureAwait(false) : null;

            DOMWorld world = null;

            if (frame != null)
            {
                if (contextPayload.AuxData?.IsDefault == true)
                {
                    world = frame.MainWorld;
                }
                else if (contextPayload.Name == UtilityWorldName && !frame.SecondaryWorld.HasContext)
                {
                    // In case of multiple sessions to the same target, there's a race between
                    // connections so we might end up creating multiple isolated worlds.
                    // We can use either.
                    world = frame.SecondaryWorld;
                }
            }

            var context = new ExecutionContext(Client, contextPayload, world);

            if (world != null)
            {
                world.SetContext(context);
            }
            _contextIdToContext[contextPayload.Id] = context;
        }
Ejemplo n.º 2
0
        private async Task OnExecutionContextCreatedAsync(ContextPayload contextPayload)
        {
            var frameId = contextPayload.AuxData?.FrameId;
            var frame   = !string.IsNullOrEmpty(frameId) ? await GetFrameAsync(frameId).ConfigureAwait(false) : null;

            DOMWorld world = null;

            if (frame != null)
            {
                if (contextPayload.AuxData?.IsDefault == true)
                {
                    world = frame.MainWorld;
                }
                else if (contextPayload.Name == UtilityWorldName)
                {
                    world = frame.SecondaryWorld;
                }
            }
            if (contextPayload.AuxData?.Type == DOMWorldType.Isolated)
            {
                _isolatedWorlds.Add(contextPayload.Name);
            }
            var context = new ExecutionContext(Client, contextPayload, world);

            if (world != null)
            {
                world.SetContext(context);
            }
            _contextIdToContext[contextPayload.Id] = context;
        }
Ejemplo n.º 3
0
 internal ExecutionContext(
     CDPSession client,
     ContextPayload contextPayload,
     DOMWorld world)
 {
     _client    = client;
     _contextId = contextPayload.Id;
     World      = world;
 }
Ejemplo n.º 4
0
        internal Frame(FrameManager frameManager, CDPSession client, Frame parentFrame, string frameId)
        {
            FrameManager = frameManager;
            _client      = client;
            ParentFrame  = parentFrame;
            Id           = frameId;

            LifecycleEvents = new List <string>();

            MainWorld      = new DOMWorld(FrameManager, this, FrameManager.TimeoutSettings);
            SecondaryWorld = new DOMWorld(FrameManager, this, FrameManager.TimeoutSettings);

            if (parentFrame != null)
            {
                ParentFrame.AddChildFrame(this);
            }
        }
Ejemplo n.º 5
0
        internal Frame(FrameManager frameManager, CDPSession client, Frame parentFrame, string frameId)
        {
            FrameManager = frameManager;
            _client      = client;
            ParentFrame  = parentFrame;
            Id           = frameId;

            if (parentFrame != null)
            {
                ParentFrame.ChildFrames.Add(this);
            }

            WaitTasks       = new List <WaitTask>();
            LifecycleEvents = new List <string>();

            _mainWorld = new DOMWorld(FrameManager, this);
        }
Ejemplo n.º 6
0
        internal WaitTask(
            DOMWorld world,
            string predicateBody,
            bool isExpression,
            string title,
            WaitForFunctionPollingOption polling,
            int?pollingInterval,
            int timeout,
            object[] args = null)
        {
            if (string.IsNullOrEmpty(predicateBody))
            {
                throw new ArgumentNullException(nameof(predicateBody));
            }
            if (pollingInterval <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pollingInterval), "Cannot poll with non-positive interval");
            }

            _world           = world;
            _predicateBody   = isExpression ? $"return ({predicateBody})" : $"return ({predicateBody})(...args)";
            _polling         = polling;
            _pollingInterval = pollingInterval;
            _timeout         = timeout;
            _args            = args ?? Array.Empty <object>();
            _title           = title;

            _cts = new CancellationTokenSource();

            _taskCompletion = new TaskCompletionSource <JSHandle>(TaskCreationOptions.RunContinuationsAsynchronously);

            _world.WaitTasks.Add(this);

            if (timeout > 0)
            {
                _timeoutTimer = System.Threading.Tasks.Task.Delay(timeout, _cts.Token)
                                .ContinueWith(
                    _ => Terminate(new WaitTaskTimeoutException(timeout, title)),
                    TaskScheduler.Default);
            }

            _ = Rerun();
        }