Unhandled exception. Unhandled exception. Unhandled exception. Unhandled exception.…
- User
Unhandled exception. Unhandled exception. Unhandled exception. Unhandled exception. Unhandled exception. Unhandled exception. Unhandled exception. PuppeteerSharp.TargetClosedException: Protocol error(Page.addScriptToEvaluateOnNewDocument): Target closed. (Target.detachedFromTarget) at PuppeteerSharp.CDPSession.SendAsync(String method, Object args, Boolean waitForCallback) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 96 at PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions.StackTrace.OnPageCreated(IPage page) at PuppeteerExtraSharp.PuppeteerExtra.<>c__DisplayClass9_1.<b__2>d.MoveNext() --- End of stack trace from previous location --- at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() PuppeteerSharp.TargetClosedException: Protocol error(Network.setUserAgentOverride): Target closed. (Target.detachedFromTarget) at PuppeteerSharp.CDPSession.SendAsync(String method, Object args, Boolean waitForCallback) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 96 at PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions.UserAgent.OnPageCreated(IPage page) at PuppeteerExtraSharp.PuppeteerExtra.<>c__DisplayClass9_1.<b__2>d.MoveNext() --- End of stack trace from previous location --- at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() PuppeteerSharp.TargetClosedException: Protocol error(Page.addScriptToEvaluateOnNewDocument): Target closed. (Target.detachedFromTarget) at PuppeteerSharp.CDPSession.SendAsync(String method, Object args, Boolean waitForCallback) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 96 at PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions.Vendor.OnPageCreated(IPage page) at PuppeteerExtraSharp.PuppeteerExtra.<>c__DisplayClass9_1.<b__2>d.MoveNext() --- End of stack trace from previous location --- at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() PuppeteerSharp.TargetClosedException: Protocol error(Page.addScriptToEvaluateOnNewDocument): Target closed. (Target.detachedFromTarget) at PuppeteerSharp.CDPSession.SendAsync(String method, Object args, Boolean waitForCallback) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 96 at PuppeteerExtraSharp.PuppeteerExtra.<>c__DisplayClass9_1.<b__2>d.MoveNext() --- End of stack trace from previous location --- at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() PuppeteerSharp.TargetClosedException: Protocol error(Page.addScriptToEvaluateOnNewDocument): Target closed. (Target.detachedFromTarget) at PuppeteerSharp.CDPSession.SendAsync(String method, Object args, Boolean waitForCallback) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 96 at PuppeteerExtraSharp.PuppeteerExtra.<>c__DisplayClass9_1.<b__2>d.MoveNext() --- End of stack trace from previous location --- at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()PuppeteerSharp.TargetClosedException: Protocol error(Page.addScriptToEvaluateOnNewDocument): Target closed. (Target.detachedFromTarget) at PuppeteerSharp.CDPSession.SendAsync(String method, Object args, Boolean waitForCallback) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 96 at PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions.WebGl.OnPageCreated(IPage page) at PuppeteerExtraSharp.PuppeteerExtra.<>c__DisplayClass9_1.<b__2>d.MoveNext() --- End of stack trace from previous location --- at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() PuppeteerSharp.TargetClosedException: Protocol error(Page.addScriptToEvaluateOnNewDocument): Target closed. (Target.detachedFromTarget) at PuppeteerSharp.CDPSession.SendAsync(String method, Object args, Boolean waitForCallback) in /home/runner/work/puppeteer-sharp/puppeteer-sharp/lib/PuppeteerSharp/CDPSession.cs:line 96 at PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions.PluginEvasion.OnPageCreated(IPage page) at PuppeteerExtraSharp.PuppeteerExtra.<>c__DisplayClass9_1.<b__2>d.MoveNext() --- End of stack trace from previous location --- at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
- Assistant
The code encountered an unhandled exception of type
PuppeteerSharp.TargetClosedException. This exception occurs when there is a protocol error related to page targets being closed or detached. The stack trace shows that this error occurred while trying to send a command to the CDPSession. The specific methods that threw the exception arePage.addScriptToEvaluateOnNewDocument,Network.setUserAgentOverride, and others. These methods are part of PuppeteerSharp and PuppeteerExtraSharp libraries, which are used to automate browser actions and manipulate web page behavior.To resolve this issue, you should investigate why the page targets are being closed or detached unexpectedly. This could be due to various reasons such as network issues, timing issues, or browser behavior. You can also try updating the libraries to the latest versions, as it may contain bug fixes or improvements related to this issue. Additionally, you can try capturing more detailed logs or enabling debugging options to get more information about the error.
If you need further assistance, please provide more context or code snippets to analyze the issue more accurately.
- User
- Assistant
У вас происходит открытие нескольких браузеров, потому что метод
FirstRequestв классеMyRequestявляется асинхронным и возвращаетTask. Однако, в методеMainего вызов не является асинхронным. Это означает, что вызовmyRequest.FirstRequestне ждет завершения асинхронной операции и сразу переходит к следующему запросу.Для исправления этой проблемы вам нужно изменить метод
Mainтак, чтобы он стал асинхронным и дожидался завершения вызоваmyRequest.FirstRequestс помощьюawait:public static async Task Main(string[] args) { MyRequest myRequest = new MyRequest(); await myRequest.FirstRequest(ame, word, proxy); }Теперь
Mainстановится асинхронным и будет ждать завершения асинхронной операции вFirstRequest, прежде чем перейти к следующему шагу. Это гарантирует, что будет выполнен только один запрос.