Skip to content

Commit e213f37

Browse files
committed
Core - EvaluateScriptAsPromiseAsync not working when JavascriptBindingApiGlobalObjectName specified
Resolves #3281
1 parent e873f8f commit e213f37

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

CefSharp.Test/OffScreen/OffScreenBrowserBasicFacts.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,29 @@ public async Task CanEvaluateScriptAsyncWithEncodedStringArguments()
200200
}
201201
}
202202

203+
[Theory]
204+
[InlineData("lowerCustom")]
205+
[InlineData("UpperCustom")]
206+
public async Task CanEvaluateScriptAsPromiseAsyncJavascriptBindingApiGlobalObjectName(string rootObjName)
207+
{
208+
using (var browser = new ChromiumWebBrowser("http://www.google.com", automaticallyCreateBrowser:false))
209+
{
210+
browser.JavascriptObjectRepository.Settings.JavascriptBindingApiGlobalObjectName = rootObjName;
211+
browser.CreateBrowser();
212+
213+
await browser.LoadPageAsync();
214+
215+
var mainFrame = browser.GetMainFrame();
216+
Assert.True(mainFrame.IsValid);
217+
218+
var javascriptResponse = await browser.EvaluateScriptAsPromiseAsync("return new Promise(function(resolve, reject) { resolve(42); });");
219+
220+
Assert.True(javascriptResponse.Success);
221+
222+
Assert.Equal("42", javascriptResponse.Result.ToString());
223+
}
224+
}
225+
203226
[Theory]
204227
[InlineData("return 42;", true, "42")]
205228
[InlineData("return new Promise(function(resolve, reject) { resolve(42); });", true, "42")]

CefSharp/WebBrowserExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ public static Task<JavascriptResponse> EvaluateScriptAsPromiseAsync(this IWebBro
10141014
/// When the promise either trigger then/catch this returned Task will be completed.
10151015
/// </summary>
10161016
/// <exception cref="ArgumentOutOfRangeException">Thrown when one or more arguments are outside the required range.</exception>
1017-
/// <param name="chromiumWebBrowser">The ChromiumWebBrowser instance this method extends.</param>
1017+
/// <param name="frame">The <seealso cref="IFrame"/> instance this method extends.</param>
10181018
/// <param name="script">The Javascript code that should be executed.</param>
10191019
/// <param name="timeout">(Optional) The timeout after which the Javascript code execution should be aborted.</param>
10201020
/// <returns>
@@ -1039,11 +1039,11 @@ private static string GetPromiseHandlerScript(string script, string javascriptBi
10391039

10401040
if (char.IsLower(internalJsFunctionName[0]))
10411041
{
1042-
internalJsFunctionName += "sendEvalScriptResponse";
1042+
internalJsFunctionName += ".sendEvalScriptResponse";
10431043
}
10441044
else
10451045
{
1046-
internalJsFunctionName += "SendEvalScriptResponse";
1046+
internalJsFunctionName += ".SendEvalScriptResponse";
10471047
}
10481048
}
10491049
var promiseHandlerScript = "let innerImmediatelyInvokedFuncExpression = (function() { " + script + " })(); Promise.resolve(innerImmediatelyInvokedFuncExpression).then((val) => " + internalJsFunctionName + "(cefSharpInternalCallbackId, true, val)).catch ((reason) => " + internalJsFunctionName + "(cefSharpInternalCallbackId, false, String(reason))); return 'CefSharpDefEvalScriptRes';";

0 commit comments

Comments
 (0)