33using System . Diagnostics . Contracts ;
44using PuppeteerSharp . Input ;
55using Newtonsoft . Json . Linq ;
6+ using System . Diagnostics ;
67
78namespace PuppeteerSharp
89{
@@ -12,14 +13,14 @@ public class FrameManager
1213 private Mouse _mouse ;
1314 private Touchscreen _touchscreen ;
1415 private Page _page ;
15- private Dictionary < string , ExecutionContext > _contextIdToContext ;
16+ private Dictionary < int , ExecutionContext > _contextIdToContext ;
1617
1718 public FrameManager ( Session client , FrameTree frameTree , Page page )
1819 {
1920 _client = client ;
2021 _page = page ;
2122 Frames = new Dictionary < string , Frame > ( ) ;
22- _contextIdToContext = new Dictionary < string , ExecutionContext > ( ) ;
23+ _contextIdToContext = new Dictionary < int , ExecutionContext > ( ) ;
2324
2425 _client . MessageReceived += _client_MessageReceived ;
2526 HandleFrameTree ( frameTree ) ;
@@ -60,7 +61,7 @@ void _client_MessageReceived(object sender, PuppeteerSharp.MessageEventArgs e)
6061 break ;
6162
6263 case "Runtime.executionContextDestroyed" :
63- OnExecutionContextDestroyed ( e . MessageData . executionContextId . ToString ( ) ) ;
64+ OnExecutionContextDestroyed ( ( int ) e . MessageData . executionContextId ) ;
6465 break ;
6566 case "Runtime.executionContextsCleared" :
6667 OnExecutionContextsCleared ( ) ;
@@ -92,7 +93,7 @@ private void OnExecutionContextsCleared()
9293 _contextIdToContext . Clear ( ) ;
9394 }
9495
95- private void OnExecutionContextDestroyed ( string executionContextId )
96+ private void OnExecutionContextDestroyed ( int executionContextId )
9697 {
9798 _contextIdToContext . TryGetValue ( executionContextId , out var context ) ;
9899
@@ -109,8 +110,11 @@ private void OnExecutionContextCreated(ContextPayload contextPayload)
109110 var context = new ExecutionContext ( _client , contextPayload , ( dynamic remoteObject ) =>
110111 {
111112 _contextIdToContext . TryGetValue ( contextPayload . Id , out var storedContext ) ;
112-
113- Contract . Assert ( storedContext == null , $ "INTERNAL ERROR: missing context with id = { contextPayload . Id } ") ;
113+
114+ if ( storedContext == null )
115+ {
116+ Console . WriteLine ( $ "INTERNAL ERROR: missing context with id = { contextPayload . Id } ") ;
117+ }
114118 if ( remoteObject . Subtype == "node" )
115119 {
116120 return new ElementHandle ( storedContext , _client , remoteObject , _page ) ;
0 commit comments