Skip to content

Commit d60d1b7

Browse files
committed
SetCanExecuteJavascriptOnMainFrame was only being set when there was a RenderProcessMessageHandler assigned, change so it's always set
Improve the formatting of the exception thrown
1 parent eecf3ad commit d60d1b7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

CefSharp.Core/Internals/ClientAdapter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,8 @@ namespace CefSharp
10831083

10841084
if (name == kOnContextCreatedRequest)
10851085
{
1086+
_browserControl->SetCanExecuteJavascriptOnMainFrame(true);
1087+
10861088
auto handler = _browserControl->RenderProcessMessageHandler;
10871089

10881090
if (handler != nullptr)
@@ -1091,14 +1093,14 @@ namespace CefSharp
10911093
CefFrameWrapper frameWrapper(browser->GetFrame(GetInt64(argList, 0)));
10921094

10931095
handler->OnContextCreated(_browserControl, browserWrapper, %frameWrapper);
1094-
1095-
_browserControl->SetCanExecuteJavascriptOnMainFrame(true);
10961096
}
10971097

10981098
handled = true;
10991099
}
11001100
else if (name == kOnContextReleasedRequest)
11011101
{
1102+
_browserControl->SetCanExecuteJavascriptOnMainFrame(false);
1103+
11021104
auto handler = _browserControl->RenderProcessMessageHandler;
11031105

11041106
if (handler != nullptr)
@@ -1107,8 +1109,6 @@ namespace CefSharp
11071109
CefFrameWrapper frameWrapper(browser->GetFrame(GetInt64(argList, 0)));
11081110

11091111
handler->OnContextReleased(_browserControl, browserWrapper, %frameWrapper);
1110-
1111-
_browserControl->SetCanExecuteJavascriptOnMainFrame(false);
11121112
}
11131113

11141114
handled = true;

CefSharp/WebBrowserExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ public static void ExecuteScriptAsync(this IWebBrowser browser, string script)
209209
{
210210
if (browser.CanExecuteJavascriptInMainFrame == false)
211211
{
212-
throw new Exception(@"Unable to execute javascript at this time, scripts can only be executed within a V8Context.
213-
Use the IWebBrowser.CanExecuteJavascriptInMainFrame property to guard against this exception.
214-
See https://github.com/cefsharp/CefSharp/wiki/General-Usage#when-can-i-start-executing-javascript
215-
for more details on when you can execute javascript.");
212+
throw new Exception("Unable to execute javascript at this time, scripts can only be executed within a V8Context." +
213+
"Use the IWebBrowser.CanExecuteJavascriptInMainFrame property to guard against this exception." +
214+
"See https://github.com/cefsharp/CefSharp/wiki/General-Usage#when-can-i-start-executing-javascript " +
215+
"for more details on when you can execute javascript.");
216216
}
217217

218218
using (var frame = browser.GetMainFrame())
@@ -736,10 +736,10 @@ public static Task<JavascriptResponse> EvaluateScriptAsync(this IWebBrowser brow
736736

737737
if(browser.CanExecuteJavascriptInMainFrame == false)
738738
{
739-
throw new Exception(@"Unable to execute javascript at this time, scripts can only be executed within a V8Context.
740-
Use the IWebBrowser.CanExecuteJavascriptInMainFrame property to guard against this exception.
741-
See https://github.com/cefsharp/CefSharp/wiki/General-Usage#when-can-i-start-executing-javascript
742-
for more details on when you can execute javascript.");
739+
throw new Exception("Unable to execute javascript at this time, scripts can only be executed within a V8Context." +
740+
"Use the IWebBrowser.CanExecuteJavascriptInMainFrame property to guard against this exception." +
741+
"See https://github.com/cefsharp/CefSharp/wiki/General-Usage#when-can-i-start-executing-javascript " +
742+
"for more details on when you can execute javascript.");
743743
}
744744

745745
using (var frame = browser.GetMainFrame())

0 commit comments

Comments
 (0)