/// <summary> /// Aborts request. To use this, request interception should be enabled with <see cref="Page.SetRequestInterceptionAsync(bool)"/>. /// Exception is immediately thrown if the request interception is not enabled. /// </summary> /// <param name="errorCode">Optional error code. Defaults to <see cref="RequestAbortErrorCode.Failed"/></param> /// <returns>Task</returns> public async Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed) { // Request interception is not supported for data: urls. if (Url.StartsWith("data:", StringComparison.InvariantCultureIgnoreCase)) { return; } if (!_allowInterception) { throw new PuppeteerException("Request Interception is not enabled!"); } if (_interceptionHandled) { throw new PuppeteerException("Request is already handled!"); } var errorReason = errorCode.ToString(); _interceptionHandled = true; try { await _client.SendAsync("Network.continueInterceptedRequest", new NetworkContinueInterceptedRequestRequest { InterceptionId = InterceptionId, ErrorReason = errorReason }).ConfigureAwait(false); } catch (PuppeteerException ex) { // In certain cases, protocol will return error if the request was already canceled // or the page was closed. We should tolerate these errors _logger.LogError(ex.ToString()); } }
/// <summary> /// Aborts request. To use this, request interception should be enabled with <see cref="Page.SetRequestInterceptionAsync(bool)"/>. /// Exception is immediately thrown if the request interception is not enabled. /// </summary> /// <param name="errorCode">Optional error code. Defaults to <see cref="RequestAbortErrorCode.Failed"/></param> /// <returns>Task</returns> public async Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed) { if (!_allowInterception) { throw new PuppeteerException("Request Interception is not enabled!"); } if (_interceptionHandled) { throw new PuppeteerException("Request is already handled!"); } var errorReason = errorCode.ToString(); _interceptionHandled = true; try { await _client.SendAsync("Network.continueInterceptedRequest", new Dictionary <string, object> { { MessageKeys.InterceptionId, InterceptionId }, { MessageKeys.ErrorReason, errorReason } }).ConfigureAwait(false); } catch (PuppeteerException ex) { // In certain cases, protocol will return error if the request was already canceled // or the page was closed. We should tolerate these errors _logger.LogError(ex.ToString()); } }
/// <summary> /// Aborts request. To use this, request interception should be enabled with <see cref="Page.SetRequestInterceptionAsync(bool)"/>. /// Exception is immediately thrown if the request interception is not enabled. /// </summary> /// <param name="errorCode">Optional error code. Defaults to <see cref="RequestAbortErrorCode.Failed"/></param> /// <returns>Task</returns> public async Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed) { // Request interception is not supported for data: urls. if (Url.StartsWith("data:", StringComparison.InvariantCultureIgnoreCase)) { return; } if (!_allowInterception) { throw new PuppeteerException("Request Interception is not enabled!"); } if (_interceptionHandled) { throw new PuppeteerException("Request is already handled!"); } var errorReason = errorCode.ToString(); _interceptionHandled = true; try { await _client.SendAsync("Fetch.failRequest", new FetchFailRequest { RequestId = InterceptionId, ErrorReason = errorReason }).ConfigureAwait(false); } catch (PuppeteerException) { } }
/// <summary> /// Aborts request. To use this, request interception should be enabled with <see cref="Page.SetRequestInterceptionAsync(bool)"/>. /// Exception is immediately thrown if the request interception is not enabled. /// </summary> /// <param name="errorCode">Optional error code. Defaults to <see cref="RequestAbortErrorCode.Failed"/></param> /// <returns>Task</returns> public async Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed) { if (!_allowInterception) { throw new PuppeteerException("Request interception is not enabled!"); } if (_interceptionHandled) { throw new PuppeteerException("Request is already handled!"); } var errorReason = errorCode.ToString(); _interceptionHandled = true; try { await _client.SendAsync("Network.continueInterceptedRequest", new Dictionary <string, object> { { "interceptionId", InterceptionId }, { "errorReason", errorReason } }); } catch (Exception) { // In certain cases, protocol will return error if the request was already canceled // or the page was closed. We should tolerate these errors //TODO: Choose log mechanism } }
public Task AbortAsync(RequestAbortErrorCode errorCode) => Connection.SendMessageToServerAsync( Guid, "abort", new Dictionary <string, object> { ["errorCode"] = errorCode, });
public async Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed) { try { await _client.SendAsync(new FetchFailRequestRequest { RequestId = InterceptionId, ErrorReason = errorCode.ToErrorReasonProtocol(), }).ConfigureAwait(false); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }
/// <inheritdoc cref="IRequest.AbortAsync(RequestAbortErrorCode)"/> public Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed) { if (_delegate == null) { throw new PlaywrightSharpException("Request Interception is not enabled!"); } if (_interceptionHandled) { throw new PlaywrightSharpException("Request is already handled!"); } _interceptionHandled = true; return(_delegate.AbortAsync(errorCode)); }
/// <inheritdoc /> public Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed) => throw new NotImplementedException();
/// <summary> /// Aborts the route's request. /// </summary> /// <param name="errorCode">Optional error code.</param> /// <returns>A <see cref="Task"/> that completes when the message was sent.</returns> public Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed) => _channel.AbortAsync(errorCode);