internal async Task RerunAsync(IFrameExecutionContext context) { int runCount = Interlocked.Increment(ref _runCount); IJSHandle success = null; Exception exception = null; try { success = await _task(context).ConfigureAwait(false); } catch (Exception ex) { exception = ex; } if (_terminated || runCount != _runCount) { if (success != null) { await success.DisposeAsync().ConfigureAwait(false); } return; } if (exception == null && await context.EvaluateAsync <bool>("s => !s", success) .ContinueWith(task => task.IsFaulted || task.Result, TaskScheduler.Default) .ConfigureAwait(false)) { if (success != null) { await success.DisposeAsync().ConfigureAwait(false); } return; } if (exception?.Message.Contains("Execution context was destroyed") == true) { _ = RerunAsync(context); return; } if (exception?.Message.Contains("Cannot find context with specified id") == true) { return; } if (exception != null) { _taskCompletion.TrySetException(exception); } else { _taskCompletion.TrySetResult(success); } DoCleanup(); }
public string HandleToString(IJSHandle handle, bool includeType) { var payload = ((JSHandle)handle).RemoteObject; if (!string.IsNullOrEmpty(payload.ObjectId)) { return("JSHandle@" + (string.IsNullOrEmpty(payload.Subtype) ? payload.Type : payload.Subtype)); } return((includeType ? "JSHandle:" : string.Empty) + GetStringFromRemoteObject((RemoteObject)payload)); }
public string HandleToString(IJSHandle handle, bool includeType) { var remote = ((JSHandle)handle).RemoteObject; if (!string.IsNullOrEmpty(remote.ObjectId)) { string type = string.IsNullOrEmpty(remote.Subtype) ? remote.Type : remote.Subtype; return("JSHandle@" + type); } return((includeType ? "JSHandle:" : string.Empty) + GetStringFromRemoteObject(remote)); }
public async Task ExposeBindingHandleShouldNotThrowDuringNavigation() { IJSHandle target = null; await Page.ExposeBindingAsync( "logme", (BindingSource source, IJSHandle t) => { target = t; return(17); }); await TaskUtils.WhenAll( Page.WaitForNavigationAsync(LifecycleEvent.Load), Page.EvaluateAsync(@"async url => { window['logme']({ foo: 42 }); window.location.href = url; }", TestConstants.ServerUrl + "/one-style.html")); }
public async Task ExposeBindingHandleShouldWork() { IJSHandle target = null; await Page.ExposeBindingAsync( "logme", (BindingSource source, IJSHandle t) => { target = t; return(17); }); int result = await Page.EvaluateAsync <int>(@"async function() { return window['logme']({ foo: 42 }); }"); Assert.Equal(42, await target.EvaluateAsync <int>("x => x.foo")); Assert.Equal(17, result); }
public async Task ExposeBindingHandleShouldNotThrowDuringNavigation() { IJSHandle target = null; await Page.ExposeBindingAsync( "logme", (_, t) => { target = t; return(17); }); await TaskUtils.WhenAll( Page.WaitForNavigationAsync(new() { WaitUntil = WaitUntilState.Load }), Page.EvaluateAsync(@"async url => { window['logme']({ foo: 42 }); window.location.href = url; }", Server.Prefix + "/one-style.html")); }
public async Task <T> HandleJSONValueAsync <T>(IJSHandle jsHandle) { var payload = (RemoteObject)((JSHandle)jsHandle).RemoteObject; if (string.IsNullOrEmpty(payload.ObjectId)) { return(DeserializeValue <T>(payload)); } var simpleValue = await _session.SendAsync(new RuntimeCallFunctionRequest { ExecutionContextId = ExecutionContextId, ReturnByValue = true, FunctionDeclaration = "e => e", Args = new[] { ToCallArgument(payload) }, }).ConfigureAwait(false); return(DeserializeValue <T>(simpleValue.Result)); }
public async Task <T> HandleJSONValueAsync <T>(IJSHandle handle) { var remoteObject = ((JSHandle)handle).RemoteObject; if (!string.IsNullOrEmpty(remoteObject.ObjectId)) { var response = await _client.SendAsync(new RuntimeCallFunctionOnRequest { FunctionDeclaration = "function() { return this; }", ObjectId = remoteObject.ObjectId, ReturnByValue = true, AwaitPromise = true, }).ConfigureAwait(false); return((T)GetValueFromRemoteObject <T>(response.Result)); } return((T)GetValueFromRemoteObject <T>(remoteObject)); }