Skip to content

Post request: PuppeteerSharp.PuppeteerException: 'Request is already handled!' #36

@w4po

Description

@w4po

PuppeteerExtraSharp version: 1.3.2
PuppeteerSharp version: 6.2.0
C# .NET Framework: 4.7.0
OS: Windows 11

Plugins: StealthPlugin, BlockResourcesPlugin

I am trying to send a post request with SetRequestInterceptionAsync,
But I got the following: 'Request is already handled!'.
Because of the following plugin: BlockResourcesPlugin.

Code:

//'info' is an object containing my data (url, headers,etc...)
//Manage Post
if (!string.IsNullOrEmpty(info.Post))
{
	await _page.SetRequestInterceptionAsync(true).ConfigureAwait(false);
	_page.Request += OnRequestHandler;
	async void OnRequestHandler(object s, RequestEventArgs e)
	{
		_page.Request -= OnRequestHandler;
		
		var payload = new Payload()
		{
			Url = info.Url,
			Method = HttpMethod.Post,
			PostData = info.Post,
			Headers = info.AdditionalHeaders
		};
		await e.Request.ContinueAsync(payload).ConfigureAwait(false);

		await _page.SetRequestInterceptionAsync(false).ConfigureAwait(false);
	}
}
await _page.GoToAsync(info.Url, new NavigationOptions { Referer = info.Referer }).ConfigureAwait(false);

The problem was raised because of the following Plugin: 'BlockResourcesPlugin', I've removed it and the code works fine now.

var blockResourcesPlugin = new BlockResourcesPlugin();
blockResourcesPlugin.AddRule(builder => builder.BlockedResources(ResourceType.StyleSheet));
extra.Use(blockResourcesPlugin);

_browser = await extra.LaunchAsync(launchOptions).ConfigureAwait(false);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions