Beispiel #1
0
        public async Task <T> EvaluateAsync <T>(ExecutionContext context, bool returnByValue, string pageFunction, object[] args)
        {
            if (!pageFunction.IsJavascriptFunction())
            {
                var result = await _session.SendAsync(new RuntimeEvaluateRequest
                {
                    Expression         = pageFunction.Trim(),
                    ReturnByValue      = returnByValue,
                    ExecutionContextId = ExecutionContextId,
                }).ConfigureAwait(false);

                return(ExtractResult <T>(result.ExceptionDetails, result.Result, returnByValue, context));
            }

            RuntimeCallFunctionResponse payload = null;

            try
            {
                string functionText = pageFunction;
                payload = await _session.SendAsync(new RuntimeCallFunctionRequest
                {
                    FunctionDeclaration = functionText,
                    Args               = Array.ConvertAll(args, arg => FormatArgument(arg, context)),
                    ReturnByValue      = returnByValue,
                    ExecutionContextId = ExecutionContextId,
                }).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                payload = RewriteError(ex);
            }

            return(ExtractResult <T>(payload.ExceptionDetails, payload.Result, returnByValue, context));
        }
        private async Task <AccessibilityTree> GetAccessibilityTreeAsync(FirefoxSession session, IElementHandle needle)
        {
            string objectId = (needle as ElementHandle)?.RemoteObject.ObjectId;
            var    result   = await session.SendAsync(new AccessibilityGetFullAXTreeRequest
            {
                ObjectId = objectId,
            }).ConfigureAwait(false);

            var axNode = new FirefoxAXNode(result.Tree);

            return(new AccessibilityTree
            {
                Tree = axNode,
                Needle = needle != null?axNode.FindNeedle() : null,
            });
        }
Beispiel #3
0
        public async Task <ElementHandle> AdoptElementHandleAsync(ElementHandle handle, FrameExecutionContext to)
        {
            var result = await _session.SendAsync(new PageAdoptNodeRequest
            {
                FrameId            = handle.Context.Frame.Id,
                ObjectId           = handle.RemoteObject.ObjectId,
                ExecutionContextId = ((FirefoxExecutionContext)to.Delegate).ExecutionContextId,
            }).ConfigureAwait(false);

            return(to.CreateHandle(result.RemoteObject) as ElementHandle);
        }
 internal Task SetRequestInterception(bool enabled)
 => _session.SendAsync(new NetworkSetRequestInterceptionRequest {
     Enabled = enabled
 });