Puppeteer-sharp-extra
Puppeteer-sharp-extra copied to clipboard
SolveCaptchaAsync is throwing an error
var browser = await new PuppeteerExtra().Use(recaptchaPlugin).LaunchAsync(new LaunchOptions()
{
Headless = false
});
var page = await browser.NewPageAsync();
await page.GoToAsync("https://patrickhlauke.github.io/recaptcha/");
await recaptchaPlugin.SolveCaptchaAsync(page).ConfigureAwait(false);
Error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=PuppeteerExtraSharp
StackTrace:
at PuppeteerExtraSharp.Plugins.Recaptcha.Provider.AntiCaptcha.AntiCaptchaApi.<>c.<PendingForResult>b__5_0(RestResponse`1 response)
at PuppeteerExtraSharp.Plugins.Recaptcha.RestClient.PollingBuilder`1.<ActivatePollingAsync>d__7.MoveNext()
at PuppeteerExtraSharp.Plugins.Recaptcha.Provider.AntiCaptcha.AntiCaptchaApi.<PendingForResult>d__5.MoveNext()
at PuppeteerExtraSharp.Plugins.Recaptcha.Provider.AntiCaptcha.AntiCaptcha.<GetSolution>d__3.MoveNext()
at PuppeteerExtraSharp.Plugins.Recaptcha.Recaptcha.<GetSolutionAsync>d__5.MoveNext()
at PuppeteerExtraSharp.Plugins.Recaptcha.Recaptcha.<Solve>d__3.MoveNext()
at PuppeteerExtraSharp.Plugins.Recaptcha.RecaptchaPlugin.<SolveCaptchaAsync>d__2.MoveNext()
at Program.<Main>d__0.MoveNext() in C:\Users\_\Documents\Visual Studio 2022\Projects\_\_\Program.cs:line 32
This exception was originally thrown at this call stack:
[External Code]
Program.Main(string[]) in Program.cs
The issue is in the TaskResultModel. "cost" is declared as a string but according to Anti Captcha's docs, it's a double. Commenting out all of the unused properties (cost, ip, createTime, endTime, solveCount) fixes the issue.
public class TaskResultModel {
public int errorId { get; set; }
public string status { get; set; }
public Solution solution { get; set; }
//public double cost { get; set; }
//public string ip { get; set; }
//public int createTime { get; set; }
//public int endTime { get; set; }
//public string solveCount { get; set; }
}
i believe TaskResultModel should now look like this:
`public class TaskResultModel { public int errorId { get; set; } public string status { get; set; } public Solution solution { get; set; } public string cost { get; set; } public string ip { get; set; } public int createTime { get; set; } public int endTime { get; set; } public int solveCount { get; set; } }
public class Solution { public string gRecaptchaResponse { get; set; } public Cookies cookies { get; set; } }
public class Cookies { public string empty { get; set; } }`