@@ -89,31 +89,20 @@ public void ExecuteJavaScript(string code, Action<JavaScriptResult> callback = d
8989 {
9090 control . BrowserCore . EvaluateScriptAsync ( code ) . ContinueWith ( t =>
9191 {
92- callback ? . Invoke ( new JavaScriptResult
93- {
94- Message = t . Result . Message ,
95- Result = t . Result . Result ,
96- Success = t . Result . Success
97- } ) ;
92+ callback ? . Invoke ( new JavaScriptResult { Message = t . Result . Message , Result = t . Result . Result , Success = t . Result . Success } ) ;
9893 } ) ;
9994 }
10095 else
10196 {
102- Task . Run ( ( ) => callback ? . Invoke ( new JavaScriptResult
103- {
104- Message = "JavaScript can't be executed in main frame!" ,
105- Success = false
106- } ) ) ;
97+ Task . Run ( ( ) => callback ? . Invoke ( new JavaScriptResult { Message = "Could not execute JavaScript in main frame!" , Success = false } ) ) ;
10798 }
10899 }
109100 catch ( Exception e )
110101 {
111- logger . Error ( $ "Failed to execute JavaScript '{ ( code . Length > 50 ? code . Take ( 50 ) : code ) } '!", e ) ;
112- Task . Run ( ( ) => callback ? . Invoke ( new JavaScriptResult
113- {
114- Message = $ "Failed to execute JavaScript '{ ( code . Length > 50 ? code . Take ( 50 ) : code ) } '! Reason: { e . Message } ",
115- Success = false
116- } ) ) ;
102+ var message = "Failed to execute JavaScript in main frame!" ;
103+
104+ logger . Error ( message , e ) ;
105+ Task . Run ( ( ) => callback ? . Invoke ( new JavaScriptResult { Message = $ "{ message } Reason: { e . Message } ", Success = false } ) ) ;
117106 }
118107 }
119108
@@ -193,9 +182,21 @@ public void Zoom(double level)
193182 control . BrowserCore . SetZoomLevel ( level ) ;
194183 }
195184
196- private void Clipboard_Changed ( long id )
185+ private void Clipboard_Changed ( string id )
197186 {
198- ExecuteJavaScript ( $ "SafeExamBrowser.clipboard.update({ id } , '{ clipboard . Content } ');") ;
187+ try
188+ {
189+ var script = $ "SafeExamBrowser.clipboard.update('{ id } ', '{ clipboard . Content } ');";
190+
191+ foreach ( var frame in control . BrowserCore ? . GetAllFrames ( ) ?? Enumerable . Empty < IFrame > ( ) )
192+ {
193+ frame . EvaluateScriptAsync ( script ) ;
194+ }
195+ }
196+ catch ( Exception e )
197+ {
198+ logger . Error ( $ "Failed to update JavaScript clipboard!", e ) ;
199+ }
199200 }
200201
201202 private void Control_IsBrowserInitializedChanged ( object sender , EventArgs e )
@@ -208,7 +209,7 @@ private void Control_IsBrowserInitializedChanged(object sender, EventArgs e)
208209
209210 private void WebBrowser_JavascriptMessageReceived ( object sender , JavascriptMessageReceivedEventArgs e )
210211 {
211- clipboard . Process ( e ) ;
212+ clipboard . Update ( e ) ;
212213 }
213214 }
214215}
0 commit comments