tomaskrupka / Gripper

A web-scraping toolbox for .NET.
https://tomaskrupka.github.io/Gripper
MIT License
0 stars 0 forks source link

More execution contexts related to one frame #1

Open tomaskrupka opened 2 years ago

tomaskrupka commented 2 years ago

CdtrChromeClient.MainContext crashes on NullReferenceException.

 Failed to GetBackendNodeId: System.AggregateException: One or more errors occurred. (Runtime.evaluate: Cannot find context with specified id)
 ---> BaristaLabs.ChromeDevTools.Runtime.CommandResponseException: Runtime.evaluate: Cannot find context with specified id
 at BaristaLabs.ChromeDevTools.Runtime.ChromeSession.SendCommand(String commandName, JToken params, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
 at BaristaLabs.ChromeDevTools.Runtime.ChromeSession.SendCommand[TCommand,TCommandResponse](TCommand command, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
 at BaristaLabs.ChromeDevTools.Runtime.Runtime.RuntimeAdapter.Evaluate(EvaluateCommand command, CancellationToken cancellationToken, Nullable`1 millisecondsTimeout, Boolean throwExceptionIfResponseNotReceived)
 --- End of inner exception stack trace ---
 at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
 at System.Threading.Tasks.Task`1.get_Result()
 at Gripper.WebClient.Browser.BaristaLabsCdtr.CdtrContext.GetBackendNodeId(Nullable`1 contextId, ChromeSession chromeSession, ILogger logger) in C:\Users\TK\source\repos\Gripper\Gripper.WebClient\Browser\BaristaLabsCdtr\CdtrContext.cs:line 37
tomaskrupka commented 2 years ago

This may happen when more than one execution contexts are related to the same iFrame. This happens when

tomaskrupka commented 2 years ago

Current implementation blindly takes the context with the greatest context id as the proper one for a given frame. This is OK in case of missed ExecutionContextDestroyed events, and most of the time for picking the DOM context as well as it's the last one to be created.

Make sure to redo this to actually identify the DOM context and pick it before merging/closing this issue.