Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
w4po opened this issue Mar 10, 2022 · 0 comments

Comments

@w4po
Copy link

w4po commented Mar 10, 2022

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant